- 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
Of course the entire thing can be replaced by just two lines:
Admin
IF I recall, there was an issue with the static initialization of arrays... but it has been a while...
Admin
Java's strings have a
split
method, but it takes a regex. What do you bet they tried"[wonky pipe string]".split("|")
and switched to theStringTokenizer
approach after getting errors about an unescaped pipe character? (Not that using the right method for the job helps much when the job is inherently misguided, but still.)(Also, obligatory complaint about clicking through eight captchas.)
Admin
I remember seeing the "MM_" prefix on code generated by Macromedia applications, waaaaaaaaaaay back then, but that's probably not the case here.
Admin
Wasn't mm_ the prefix used by code generation features in Macromedia IDEs or memory is fooling me?
Admin
By the way, Remy's Law of Requirements Gathering is true. The users do want Excel (or Excel-like) implementations.
Admin
@Naomi Yes, but no. OK, the original programmer may well have had a bunch of
PatternSyntaxException
s thrown at him (or even just the compiler complaining about not catching the exception), but that just means that he needed to correctly specify the pattern. ("\\|"
or"[|]"
would do nicely, if memory serves.)But regardless, if we want to avoid flarblisms with the regexness of
String.split(...)
, switching to a tokeniser (don't get me started on a variable calledtokens
that is of typeStringTokeniser
), it would surely be better to do it withStringUtils.split(...)
or (if using Guava)Splitter.split(...)
.Ref: https://www.baeldung.com/java-split-string
Admin
I'm getting flashbacks to an incident when my German teacher suddenly shaved. People were genuinely distracted by that and couldn't concentrate on class for a bit.
Remy suddenly changing the profile pic after such a long time has a similarly unsettling effect.
Speaking of which, my Facebook profile picture is still showing me as a 20yo. Incidentally, also with a ponytail. Incidentally, my face also got a bit rounder since then, though my hair has receded more than with Remy. If I update my profile pic now, anyone who actually looks at it might get a stroke. Good thing, nobody is likely to do that.
Admin
Er, what? Did you miss the part where I called
split
"the right method for the job", implying that abusingStringTokenizer
like this isn't? I'm not defending this code, just speculating as to where it may have come from.Also,
PatternSyntaxException
is unchecked, so the compiler won't complain if you don't catch it.Also, it's 2024; can we please get over the assumption that programmers are men already?
Admin
As someone from New Zealand: +10 points for referencing Rēkohu.
An island I'm only fairly sure has access to the internet
Admin
According to the docs,
StringTokenizer
implementsEnumeration<Object>
sotokens
is not really such a bad name for a variable of that type.Of course, given that it has
String
in the name, it seems a bit crazy that the interface is notEnumeration<String>
and there are other things that point to the class being a WTF by itself . For example, you can count the tokens left, but you can also change the delimiter on the fly.