Tag Info

New answers tagged

0

Most of the developers will be able to understand the 2nd form with a glance. In my opinion over simplification as in 1st form is simply unnecessary. You can improve the readability by adding spaces and braces such as: obj.NeedsChange = obj.Performance <= LOW_PERFORMANCE; or obj.NeedsChange = ( obj.Performance <= LOW_PERFORMANCE ); as ...


0

The second. It has less repetition (DRY) and is easier to understand what is going on, that c holds to value of whether or not a and be b are equal. IMHO, even better would be c = a == b Just as I would write 1 + 2 + 3 instead of ((1 + 2) + 3) 5 + 3 * 7 instead of (5 + (3 * 7)) Obviously and trivially unnecessary code is not a virtue. It's cluttered. ...


1

While your programming should tend towards explicit over implicit "as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live", you can assume a few basic things that your psycho successor will be competent in. One of those is the syntax of the language he is using. obj.NeedsChange = obj.Performance <= ...


1

It is easy to see that Variant 2 and Variant 1 are related via a series of obvious and simple refactorings: if (obj.Performance <= LOW_PERFORMANCE) { obj.NeedsChange = true; } else { obj.NeedsChange = false; } Here, we have needless code duplication, we can factor out the assignment: obj.NeedsChange = if (obj.Performance <= LOW_PERFORMANCE) ...


37

I prefer 2, but I might go for a small adjustment to it: obj.NeedsChange = ( obj.Performance <= LOW_PERFORMANCE ); To me the parentheses makes the line easier to parse and makes it clear at a glance that you are assigning the result of a comparison, and not performing a double assignment. I'm not sure why that is (as off-hand I can't think of a ...


10

Anytime code is more complicated than it needs to be triggers a "what is this supposed to be doing?" smell in the reader. For example, the first example makes me wonder, "was there other functionality in the if/else statement at some point that was removed?" Example (2) is simple, clear, and does exactly what is needed. I read it and immediately ...


20

Variant 1 is easily understood, but that is its only advantage. I automatically assume that anyone who writes like this doesn't really understand what booleans are all about, and will be writing similarly infantile code in many other respects. Variant 2 is what I would always write, and expect to read. I think that anyone who is confused by that idiom ...



Top 50 recent answers are included