Maintainability of Boolean logic - Is nesting if statements needed?
- by Vaccano
Which of these is better for maintainability?
if (byteArrayVariable != null)
if (byteArrayVariable .Length != 0)
//Do something with byteArrayVariable
OR
if ((byteArrayVariable != null) && (byteArrayVariable.Length != 0))
//Do something with byteArrayVariable
I prefer reading and writing the second, but I recall reading in code complete that doing things like that is bad for maintainability.
This is because you are relying on the language to not evaluate the second part of the if if the first part is false and not all languages do that. (The second part will throw an exception if evaluated with a null byteArrayVariable.)
I don't know if that is really something to worry about or not, and I would like general feedback on the question.
Thanks.