...and people are still using java? (Answers)
by Manu (modified: 2009 Sep 23)
Here are the answers for the quiz of last week:
- b=2
- b=2
- b=2 and an exception
- b=4 and no exception
- returns 2
- returns 1 and b=2
The difficult ones where definitely the last 3. Note that for #4 this is rejected by C# which forbids exiting from the finally clause (actually this is a .NET runtime restriction that has moved up to the language specification).
If you are unlucky and have to program in Java (instead of Eiffel as I do), you have to be careful when handling code that makes an extensive use of try .. finally...
with goto style code flow.
The jump instructions are the real problem
I don't think finally is the problem. It's the jump instructions: break, return, etc.
Everyone knows that Dijkstra said that goto was considered harmful, but hardly anyone these days (apart from we Eiffel programmers) seems to remember that these jump instructions are unstructured too.
My most recent head-slapping moment came when I saw this in some code.
do { //.... if (...) break; //---- } while (false);
Your criticism of Java is just nitpicking at trivia
If this (the surprises surrounding break/continue/return inside a finally clause) were the worst defect in Java, then Java would be a pretty friggin' amazing programming language.
In other words, you are focusing in on minutae and losing sight of the bigger picture.
Of course, this is mostly intended for our Eiffel users to have a little bit of fun. We all know the benefit of using Eiffel over the other approaches and that there is not just one reason for using Eiffel but many.