4 ms·
Since he lumps in Java with C and C++ it's worth pointing out that this specific bug is not possible in Java since unreachable code is a compiler error. I assum
by guelo 13y ago
Since he lumps in Java with C and C++ it's worth pointing out that this specific bug is not possible in Java since unreachable code is a compiler error. I assume the same for C#.
Also, many style guides such as Josh Bloch's highly influential 'Effective Java' recommend against the 2-line if statement without curly braces since it's known to be prone to this type of error. His argument that keywords are better than braces for ending blocks is weak.
- Aaronontheweb 13y agoIn C# if this were nested between two Catch blocks (for handling different types of exceptions, per this example) then it would throw a compiler error. If it were a switch statement, you'd get a warning for code that will never be executed.
- morganherlocker 13y agoI believe it is a warning in C# (have not used it in a while).
- AnimalMuppet 13y agoI don't think that's quite his argument. His argument is that in Eiffel, the keywords are mandatory, whereas in C, the braces are optional (for a one-line body). And, in fact, mandatory braces would have prevented this particular issue.
- mikestew 13y ago> it's worth pointing out that this specific bug is not possible in Java since unreachable code is a compiler error Not on my Java compiler (Android toolkit and Eclipse). I see it as a warning throughout the code base I work on. :-(
- josephschmoe 13y agoUse IntelliJ (Google's favorite Android IDE - they make a mod of it called Android Studio but the good stuff makes it back to IntelliJ)
- srcreigh 13y agoI use ADT as well, and IIRC there are certain kinds of unreachable code that won't compile: public int foo(int i) { return 2; return i; }