Tag Info

Hot answers tagged

61

What came first, the process, or the data used by that process? I know this is kind of a "chicken or the egg" question, but in the case of software, I believe it is the process. For instance, you can build up your data model incrementally by implementing a single use-case at a time with just in-memory persistence (or anything as easy to implement). When you ...


28

No, it is not normal 1. At least, it's not normal for good programmers. It probably is normal for someone learning to program. Writing software isn't just slapping lines of code together until it works. You need to consciously work on making the code easy to understand. A programmer I respect highly once told me "code is read way more times than it is ...


19

Nothing precludes command-line arguments from being used when starting a daemon, or configuration files from being used in interactive mode. The general approach that works well and a lot of programs use is to have a list of prioritized ways to set program options: Defaults Global configurations (/etc or HKLM in the registry) Local configurations (home ...


14

There are two kinds of this: 1.) confusion 2.) blissful ignorance The first one is bad and may disappear with time and experience. The second is a good one if projects become larger: If you have to remember every implementation detail just to be able to work with your code, there's something wrong with it (see "information hiding"). Every developer is ...


12

A root cause analysis suggests this problem is not one of method, but is the lack of a specification. Without one it doesn't really matter what you write first - you are going to throw it away anyway. Do yourself a favour and do some basic systems analysis - identify some users at various levels, make up a quick & dirty questionnaire then turn off your ...


9

I'd say it's more common than people care to admit. Even Brian Kernighan alluded to it: Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. When we drive to the store, we make a sequence of detailed adjustments to the ...


8

Good question. The use of enum in Java is primarily meant to handle information that is somewhat categorical in nature. The classic example being using enum to handle the four types of suits that a card could have. It provides all the performance advantage of using an integer and it is also clear in your program. So outside of Java, why wouldn't you ...


8

I was going to say Database First since I have a lot of experience with large projects and you really need a solid data model if you have many developers working in parallel. But then I though about it a little more and I realized that what we were really doing on the more successful large projects was "requirements first". A good well specified set of ...


7

Since this seems so fluid/unspecified, I'd do the frontend GUI first - that sounds like what you need to get responses, support, time, and feedback from the stakeholders, right? They don't care about your brilliant normalized tables and foreign keys constraints and cascading deletes. But a cool GUI with lots of shiny colors - well, that's top notch! For ...


7

In general, you should avoid exiting your entire program from random functions. Why? It makes your code hard to read. The function in question becomes difficult because you then need to care about what context it's being called from. The rest of the program becomes difficult because the "normal" exit point isn't correct all the time. It makes that code ...


5

I believe you misunderstood the recommendations for logging. The 12 Factor site states A twelve-factor app never concerns itself with routing or storage of its output stream. It should not attempt to write to or manage logfiles. Instead, each running process writes its event stream, unbuffered, to stdout. During local development, the developer will ...


5

The caller is responsible for putting the Stream in a suitable state to be consumed by the reader. There are two main reasons: Not all streams support repositioning. You should only set the Stream.Position property if that Stream.CanSeek. Otherwise, you'll get an exception. (see the Stream.Position documentation). “Reading from the beginning” is a special ...


5

I think this is something that'll go away with experience. If you're writing complex systems, you need to have the ability to write clean, maintainable code that both you in the future, and someone else in the future, can understand. So, in essence, the thing you're doing now isn't scalable. You'll have lots of moments where you're looking at some code you ...


5

You are both right. You don't want to lose the stack trace, but you may want to catch the lower level exception. Don't wrap the exception if it isn't adding information. I would call your ExceptionManager and TreatException a bit of a code smell - they are trying too hard to centralize exception handling. To re throw without losing the stack trace: ...


4

"Normal" is very subjective, so I say: it is very common, but should be avoided. One of the features of "the good code" (I heard such thing exists) is clarity: it should be as clear as underlying problems allows it to be. If problem is complex, the code would be complex as well, but that's inherent complexity, as opposed to accidental complexity (I first ...


4

My experience is as follows: In most projects I've worked on, we design the database first. Often times data already exist in spreadsheets, legacy databases, paper, etc. That data will hint you about the tables you need to hole it. Often times a process is already being use, yet manually or using several, disparate tools that are not automated, don't ...


4

As usual, there are obvious upsides and downsides to coercing. It will let your program run on in production, when it is weak and alone and has no one to hold its hand; it must manage whatever conditions it is put into all by itself, and warping to the minimum value is the obvious thing to do. If crashing or skipping a task altogether would be very expensive ...


3

... I wonder if once the program is deployed in production, isn't it also valid to simply log a warning and proceed the execution? Short answer: No. Every function you write runs in its only tiny little world that only knows about the argument values passed to it. It can only change or reinterpret the intention of those values if it understands the ...


3

It's a bit more complicated than that. Firstly, understand the tradeoffs. If you are going to pass a copy of the object (essentially "pass by value" semantics) rather than a reference to the original object, you are going to take a performance hit. Whether that hit is justified or not depends on your software's functional requirements. Secondly, it might ...


3

50 applications in 6 weeks sounds enormously ambitious. You need to tell your new CTO that this is only a lightweight review; there's no way you're going to detect bugs or security flaws in this time. I'm mostly familiar with code review for security, and the rule of thumb I use is 10 KLOC per day - and even that is ambitious, and can only be achieved by ...


2

I still think it makes sense to stick to phpDoc to document PHP code. It is the standard recommended by the php PSR project. It is also generalized into the annotations concept, as it is used for instance in Doctrine. Another argument for phpDoc is that Javascript and many other languages have it's analoguos commenting system. After much time spent to try ...


2

I don't think it is normal, but for very complex programs, like the chess program you mention, I think it certainly possible. Many years ago, when I was just out of grad school (so I was still relatively inexperienced writing large programs), I wrote my first real compiler. The parsing was straightforward, but then I needed to target it for four different ...


2

Every book is worth reading... whether it's good OR bad. It will give you a perspective, just like any life experience. Your question is like asking someone if they like oranges. This someone might tell you oranges taste awful. You might believe this someone. You might never taste oranges in your entire life because of that someone. You are left one ...


2

Method chaining implies that multiple method calls are related, with each call building on the previous one. An example is a "fluent" style of programmatically querying the database. $posts = Post::where(array('name' => 'Test')) .order_by(array('date' => 'desc')) .limit(10); (Forgive my lackluster PHP, it's been quite a while since I wrote ...


2

Ok, I would never in a million years do this, but you could do something like this: Force auto inclusion of this: // forcebanned.h #define for "You must include banned.h" Then add this: // mybanned.h #undef for #include banned.h But don't do that. Better is to make the inclusion of banned.h a coding standard, and rely on code reviews to catch it. If ...


2

Your question shows some misconceptions, I guess: if the alternative to passing an object as parameter is to create a new instance directly in the constructor PassTheObjectHere, then you are obviously not using any values/state of the previously created obj within PassTheObjectHere. If that is the case, it is pretty useless to pass obj as a parameter ...


2

In your examples you are not talking about failing early but rather about how to handle expected failure cases. Handling expected failure cases You gave the similar questions module as example. It can be aware, that one of its submodules may not be able to deliver and then just shows the rest of the questions that it got by its submodules. A counterexample ...


1

The nice thing about YAGNI is that it can be quantified. There are three metrics too look at: The time saved by applying YAGNI and not implementing something up-front. The probability that the application will have to be rewritten The time needed for rewriting the application a couple of years in the future. When time saved > time needed for rewriting ...


1

I think it really depends on the context you are working with. In your example, you are sending the TheObject instance to the PassTheObjectHere constructor, this way of working tells me that, inside your PassTheObjectHere instance, you are working with some previous initializated data. So if the ClassWithTheObject is going to share the conversational state ...


1

First off, having a catch block which only rethrows the exception is usually useless. But, the only real world scenario i can think of which makes sense to use throw ex instead of throw is if you're developing some sort of third party library which you by all means dont want anyone in the outter scope who's using your code to see the full stacktrace. Im not ...



Only top voted, non community-wiki answers of a minimum length are eligible