- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I saw the sarcasm. I left you a clue to that effect (hint: it was the part where I mentioned the sarcasm). It's subtle, but try to stay with me here.
A sprinkling of sarcasm doesn't come with a free pass on total bullshit math. He's trying to (sarcastically, yes) make the point that exceptions are cheap enough to not be worth doing stupid things over, even if this "pattern" helped, which it doesn't. The conclusion happens to be true, but it certainly is not proven by the faulty reasoning.
Admin
the biggest wtf is of course the non-java coding style.
Admin
Dynamic typing in Java. Nice.
It must be using reflection then, which means it's probably an order of magnitude slower than normal method calls, while removing the benefits of static typing (compile-time checking for common errors).
Sounds like you are using the wrong programming language for the job at hand, heh ;)
(I know..it's not like the decision to use Java was yours, probably)
Admin
Simple example: word processor app implementing file|save. The app writes out all data to the file, but the data isn't actually written across the network yet. Then the file server goes down. Then the app calls close(). The OS tries to finish writing the data across the network, and fails. So the close() fails, and throws an exception. You want to handle this exception, tell the user that the save was not successful, and leave the user's data buffer in a dirty state.
Admin
That one really hurts my heart!
i have really no idea how someone ever should come to such a stupid solution!
it does not even have less code lines, the for-loop is completly useless o_0
Admin
This entire thread is really depressing.
captcha: cognac. tasty.
Admin
Let us assume that baos is a ByteArrayOutputStream and dos is a DataOutputStream and dos is a wrapper for baos, what would happen if we didn't call close at all?
ByteArrayOutputStream.close()
And DataOutputStream.close()
As you can see dos flushs and closes baos, which all do nothing.
But imagine that there was a good reason to actually call these methods and they did something important.
In that case we have called. baos.close(); dos.close(); dos.flush(); baos.flush();
Note: baos is closed before dos is flushed. So if there was unsaved data in dos and baos prevented a flush after being closed, this would fail.
In other words, calling these two methods in this order only works because they don't do anything! In which case you could just not call them.
IMHO: the safest option is just dos.close() and log any exception on the lowest logging level, because if it ever threw an exception it might mean one of your assumptions is wrong.
Admin
Yeah whatever. You are all a bunch of faegoats.