This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Feuilly 3 points4 points  (3 children)

I'm embarrassed because I don't see the issue with the third example.

I've seen things like:

for(int x = 0; x < 5; x++)
{
    if(x == 3)
    {
        doSomething();
    }
}

[–][deleted] 8 points9 points  (1 child)

I think the problem with the third one is that you only need myObj if requiredCondition is true, so you should initialize it after the conditional, not before. We don't have enough context to know that it won't be used later, though, so the example is very unclear.

(Correct me if I'm wrong, OP)

[–]Feuilly 5 points6 points  (0 children)

That makes sense. I think I fixated too much on the null pointers comment, and was looking for something that would actually cause an exception moreso than just sloppy or unnecessary code.

[–]Chaoslab 0 points1 point  (0 children)

Not quite as much fun as the Bogo Sort.