- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Teamwork
- Cuts Like a Knife
- Charge Me
- Que Sera, Sera
- Hot Dog
- Sentinel Headline
- Mais Que Nada
- Here Comes the Sun
-
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
It's a pity he did not fix the atrocious curly brace style while he was at it. This is java unworthy.
Admin
Does Java not have some form of the TryParseInt function?
Admin
This is the kind of method I re-read multiple times just to try to back into the thought process that produced it.
Edit Admin
"only to find 39 copies of this function, with minor variations." If only there were a way to reuse code in other parts of the project...
Edit Admin
No, Java doesn't have a tryParse built-in. There's just the parseInt used here that throws an exception (that Java forces a catch block for): https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Integer.html#parseInt(java.lang.String)
But it's a common thing to exist in utility libraries that many projects would be including anyway, like Apache Commons Lang: https://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/math/NumberUtils.html#toInt-java.lang.String-
Of course, it might be implemented by just catching the exception of the built-in parseInt, so you're playing the Java exception performance penalty anyway for cases where it isn't a number: https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/math/NumberUtils.java#L1528
Admin
If trying you are, doing you are not.
Edit Admin
TRWTF is that nobody will ever appreciate how the developer fully understood how the Beauty-of-Java™ is that all code is reusable (but only if less than 40 times) and also remembered something something methods can be overridden [so why not extend this to functions too?] AND managed to give "i" something to do besides be a counter in a for loop that got copypasta'd from .
Personally, I'm kind of impressed that we don't just check if Bad Use Of Stringly Data might be an integer - we MAKE it an integer no matte what it might represent. That, my colleagues, is Brillant!!
Addendum 2025-05-22 14:53: @Override "for loop that got copypasta'd from Stack Overflow"
Maybe that should be @Overflow...?
Edit Admin
I think this was done out of pure malice