|
No error checking for array bounds.
«_Superman_»
|
|
|
|
|
There might be, just not in that snippet, or maybe that's was a design decision, I can't tell from just that one statement.
|
|
|
|
|
PIEBALDconsult wrote: Looks OK
Yes, if you mean OK as in syntactically correct.
But it's not very readable, this statement seems to say: I don't care too much about my team mates and/or maintainability. And if that is repeated many times throughout the class, sometimes with one - , sometimes with two, then it is only a question of time until a problem related to these statements will occur.
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Thomas Weller wrote: And if that is repeated many times throughout the class, sometimes with one -, sometimes with two, then it is only a question of time until a problem related to these statements will occur.
How could there be one '-'? Would that even parse? (BTW, the inability to parse a single trailing plus minus would seem a reason to favor i++ over ++i when the two operations would otherwise be interchangeable).
If there were only one or two such statements in the code, I would probably be inclined to create temporary variables to hold the outputs of the various subexpressions. If the exact bit of code is repeated extremely often, I might be inclined to define a separate method for it. Otherwise I would expect someone parsing the code to example that classes referenced therein and determine what the different methods or properties mean. The expression seems pretty straightforward; if it only appeared once, expanding it to use temporary variables would make it easier to read, but if it appears many times, expanding it in such fashion would make one instance (the first one examined) easier to read and the rest bloated and annoying.
|
|
|
|
|
Perfect for a Scheme macro, oh wait! You are not using Scheme!
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 2 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Here's one I spotted in a previous life:
We were working in C on protocol stacks. In every C file created by a group of contractors, we found the following statements:
#define True 0
#define False 1
This was endemic throughout the code produced by this particular group of contractors.
Fortunately, the product never came to be. The 2001 Tech Wreck did it in.
Geoff
Professional Geek,
Amateur Stage-Levelling Gauge
|
|
|
|
|
Ew. While I agree that true should be zero (there are many ways of being wrong, but only one way to be correct; it's also orthogonal with strcmp), I still wouldn't do that.
What we had at one place was:
#define true (0==0)
#define false (!true)
|
|
|
|
|
I've started to favour this form:
#define TRUE (!0)
#define FALSE (!TRUE)
But at least I put it in a header rather than within every single source file. In this case, it was in *.c. Can you say "maintenance nightmare"?
And they claimed they were a CMM level 5 company, too.
Professional Geek,
Amateur Stage-Levelling Gauge
modified on Wednesday, February 4, 2009 6:19 PM
|
|
|
|
|
The (0==0) may be more portable, which is what they were after.
I just tried (0==0) and (!0) on two compilers and both agreed that they equal 1, but that may not always be (or have been) the case.
|
|
|
|
|
Many C compilers (and ancient C++ compilers) don't support the bool type. The expression (0==0) has the advantage of having type bool when possible and int otherwise.
|
|
|
|
|
I would love to have macro-definitions in C# or Java just to break all these silly stereotypes.
#define max(a,b) (a>b ? b : a)
#define min(a,b) (a>b ? a : b) or
#define cerr (cin)
#define cout (cerr)
#define cin (cout)
Aaah so confusing so sweet ...
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Came across this just the other day:
bool value = (someObject == NULL)? true : false;
The same thing is dotted around in a few places, some of the the other way around (returning false if the statement is true). I just can't understand why anybody would bother.
My current favourite word is: Delicious!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
SK Genius wrote:
I just can't understand why anybody would bother.
What on earth is wrong with a ternary operation[^]? There are valid reasons for using it. It is a hint to the compiler that the software engineer wants to make an assignment with no conditional branching if possible. The compiler will try to perform an optimization such as ternary operator optimization[^] if it is possible.
I guess he could have written it like this and it would possibly optimized the same:
bool value;
if(NULL == someObject)
value = true;
else
value = false;
But who really cares? They are equally readable to me although I prefer the ternary operation.
Best Wishes,
-David Delaune
|
|
|
|
|
Nothing wrong with ternary operation really. But wouldn't
(NULL == someObject) returns True/False that can be assigned straight to "value"?
|
|
|
|
|
DePatrick wrote: returns True/False that can be assigned straight to "value"?
Yep, that is true.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: that is true
I second that; it is absolutely (true==!false)==true?true:!false
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
But it's not necessary in this case.
|
|
|
|
|
It is probably a misunderstanding of the form:
BOOL value = (someObject == NULL) ? TRUE : FALSE;
where
#define FALSE 0
#define TRUE !(FALSE)
m.bergman
-- For Bruce Schneier, quanta only have one state : afraid.
|
|
|
|
|
I don't see the horror...
|
|
|
|
|
Found in my own code:
if (action == InvalidContentActions.Remove || action == InvalidContentActions.Remove) {
...
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
More like a second chance.
Yesterday I somehow wound up writing if ( x != x )... , I enjoyed the warning I got:
warning CS1718: Comparison made to same variable; did you mean to compare something else?
|
|
|
|
|
You could actually write something like that to show the dangers of unsafe multithreading :p
|
|
|
|
|
I've seriously used code like that to check for NaN.
|
|
|
|
|
I've seriously used code like that to check for NaN.
If A and B are both floating-point NaN's related to the same condition, what are the values of the six relational operators? If they all report false, then one could test if two numbers were both equal or both NaN with "if (!(a != b))"; if NaN's report not equal to each other but neither greater- nor less-than each other, then maybe "if (!(a > b) && !(a < b))". Of course, unless such statements are commented people would likely find them confusing.
|
|
|
|
|
Wouldn't float.IsNaN(x) be a more readable way to achieve that?
|
|
|
|