- 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
And with "happily ever after" we mean "a constant source for front page articles", right?
Admin
"tested in the fires of a late afternoon code review"
Might I suggest that if you are using code reviews as a fiery test then you're doing them wrong? Good code reviews focus on code not people.
Admin
Admin
Yeah, if you have to schedule for code reviews you're doing it wrong. It's much easier to do them during pull requests.
Admin
Dammit :hanzo:
Somebody found the hidden :wtf: already. Who've guessed it would be the code review?
Admin
I can't see the WTF here. Experienced developer got something completely wrong, is shown the right way, and accepts that he was wrong. That's not a WTF, that's, well, it should be normal, but here it is really an excellent outcome.
Admin
Fortunately, Neil wasn’t so set in his ways that he couldn’t correct course when proven wrong
HIRE THAT MAN!
Admin
i would in a heartbeat (well give him the interview at least) if i knew his contact info.
Admin
Well, until he removes all
/[0-9]+/
s from the codebase because he's heard that magic numbers are wrong.Or learns that "coding by exception" is an antipattern and nuke your error handling.
Admin
Ever the optimist, I love a story with a happy ending. Even very intelligent people make stupid mistakes sometimes, and handling them with grace is a good sign.
Admin
I finally got around to researching finalizers, second google hit was this: Creating and Destroying Java Objects: Item 7: Avoid finalizers. I "skimmed" through the article and saw this:
and thought uhho, (thinking Neil was right). BUT, I then went back and re-read the Article a couple of times, realised that it was given of where and when to use explicit termination instead of finalize().
There is a moral in this somewhere.....
Oh, nearly forgot. In the re-reading I noticed this:
Admin
Not to rain on your parade or anything, but in the meat world creating multiple instances of the same person may be illegal in your jurisidction.
Admin
Obviously, Neil is a singleton;
getInstance()
always returns the same instance.Admin
Seems to me one big WTF here is Donovan, Mr. Grizzled Java vet, didn't immediately recognize that Neil had gotten confused between
final
and a finalizer (or a destructor, whatever it's called in Java). That whole "might not run" shoulda been the tip-off.Admin
Well, a finally clause might not run either if you SIGKILL the JVM at the exact point in time.
Programming test:
does finally block executes?
Admin
Sometimes the next edition contains improvements/updates, sometimes it contains :wtf:s, and the really fun ones contain both.
Admin
FTFY.
Admin
It depends on your method. My parents created two instances of the same person, and although I might have sometimes wished it were illegal, it was not. Indeed, using that method, I think it would be legal everywhere, except perhaps in China. [Tharpa speaks dark truth.]
Admin
Pretty sure "yes". [image]
Admin
Clarification required (identical twins are not in fact completely identical - apart from the fact that some of them are chimaeras, in other cases environmental variation causes slightly different gene expression, so they are never completely identical. If I call getInstance() on a class, all the instances are initially identical, whereas the differences in gene expression in uniovular twins have already started at the point at which fission occurs into two embryos.)
Admin
in JDBC, getResultSet() on a Statement always annoyed me because the ResultSet is like a quark; although in theory it exists as a separate object, in reality it is an indivisible part of the Statement just as a quark can't be extracted from its hadron (except, of course, by getting things hot enough to create a quark gluon plasma, and I don't know what the computing equivalent is of that. An AI singularity?) Oh dear, too much travelling, it causes my brain to go soft.
Admin
Not at all, every call returns a different guy named Neil from the Neil pool.
Admin
:wtf::question:
getInstance()
is the Singleton pattern. You're thinking of the Factory pattern; that method would begetNew()
or something.Admin
It's easy to forget they even exist because the best practice for using them is to never use them, at least in Java. You have zero control over when or even if they ever run. When was the last time you actually saw a Java finalizer?
Admin
To be honest, I forgot those were even a thing. Once upon a time in basic C programming we talked about destructors, but very quickly I learned that if you EVER have to do that yourself, ya done wrong. :fa_rebel:
I think I accidentally discovered buffer underflows at that point too, and figured out how to crash a program by releasing
null
...Admin
Admin
Huh? C doesn't have destructors, you always have to do everything yourself. Did you mean C++, where you should seldom be manually destroying objects/releasing resources and instead rely on destructors to be run automatically with RAII?
Admin
Right, sorry I didn't qualify that we spent only a few weeks on C before moving on. ;)
Admin
Yes and that was in my mind when I wrote it. But there are exceptions even in core lib, like Calendar.getInstance() that returns a Calendar instance initialized with the current date and time.
Admin
I call bulls hit. I haven't met any such "veterans" that were willing to admit that they were wrong. They usually hide behind "You don't know all the details", or even "This is what compiled code does anyway", or some crap like that...
And that always ends in a stalemate, since they've learned to convince others to the point where they've become self-appointed experts on the topic.
Admin
Fun fact: parents who have twins/multiples call the children that were alone in the womb "singletons".
Admin
For identical twins, getInstance() is called twice during pregnancy (obviously). The first time when fertilization occurs; and the second time when the egg splits.
As the egg splits, the 2 instances are identical.
Admin
Sounds like forking a spawn to me.
Admin
Since I share a name with one of the characters in the article, I'd like to take this opportunity to share my favourite abuse of finally:
Admin
Surely you can't return from a finally clause?
Admin
You can. But you shouldn't. If you were already returning a value or throwing an exception, those disappear into the ether. From the Java Language Spec:
and
Note that a
return
statement always completes abruptly, and the reason for completing abruptly is the return value; in the case of a thrown exception, the exception object is the reason.The same logic applies to throwing a new exception from a
finally
block — any pending return value or thrown exception is also discarded.Admin
Calendar is such a steaming pile of WTF that misuse of method names probably shouldn't surprise anyone.
Admin
Strictly, all you know is that
getInstance()
is retrieving an instance, not that it is the only instance (or what the actual class of the instance is). This is Singleton implemented by Factory. (Another way would be to just have apublic static final Neil instance
field in the class and to assign to that field during the initialisation of the class, with the constructor marked asprivate
so that nothing else can get at it.)I hate the way standard object construction works in Java, and the way it forces you to deal with so much pattern shit just to work around it.
Admin
What I liked most about this one is that I followed the link for the book and read through the discussion about finalizers, and it had this to say:
So from "finalizers are evil and should never be used; use an explicit termination method inside a
finally
clause instead", he took away "finally
clauses are evil and should never be used".