- Feature Articles
-
CodeSOD
- Most Recent Articles
- What a More And
- Hall of Mirrors
- Magical Bytes
- Contact Us
- Plugin Acrobatics
- Recursive Search
- Objectified
- Secondary Waits
- 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
Arrr, me likes!
Admin
["This", "is", "the", "arracomment!"]
Admin
I'm a big fan of arralphaletio*.
*Starts off as "phaletio" and ends with ralphing.
Admin
/**
Oy.
Admin
The beginning "Z" value in the array is likely so that A maps to 1 instead of 0. I was honestly taught to do things like this in a business "programming" class that a few of us Comp Sci majors took for a laugh. Apparently 0-based values are MUCH more confusing than 1-based ones.
Admin
The real WTF is that they forgot to code the lower-case arralphalet.
Admin
ARRALPHALET vs ALPHABET
You have failed when you acronym takes more letters than the correct spelling.
Admin
It's just a conversion to base 26 poorly coded.
Admin
I've always felt content knowing that in the UK our buildings start with a Ground Floor (Floor 0) whereas in the states they start off at Floor 1.
Admin
/**
Admin
Wow, Java has no len() or chr() functions? Glad I never wasted my time with it.
CAPTCHA: dignissim <- Okay, now you're just making these up.
Admin
It's not often that you see DEC Alpha mentioned here, let alone DEC 2 Alpha.
Admin
Not a WTF. In an embedded system--takes two bullets to the chest ... bleeds ... dies
Additionally, the name ARRALPHALET doesn't seem to make sense on multiple levels... it's not an array of alphabets (or alphalets, for that matter). Or maybe it is, and it's just missing 25 characters from the second set (explains the second Z).
Admin
I may be putting myself up for ridicule here, but what is the problem with a Util class for widely used methods in strict OOP languages? I understand that you don't want to throw everything in there.
Admin
Admin
I think I know what that does:
It converts a number into an Excel-like column label. If you're familiar with Excel, then you know how its columns are labeled A through Z, then AA through AZ, and so on. Someone wants to represent an Excel file in a 2D Java Array (the "static final" syntax tipped me off).
Now, why anyone needs to represent an Excel file in Java, I'm not sure...
Wait...
"The grass is not always greener"... Java-based Excel formatting... Dear Ghod, this is a snippet from OpenOffice!
Admin
It creates spaghetti code and breaks modularization. You basically surrender all of the advantages of OOP languages (at least in this one little area).
It's one of the classic anti-patterns.
Admin
Admin
Just looked at the algorithm. There is one major bug in that if you pass in a negative number you will fail the checks and take a negative index from the array, presumably in Java that gives you a bounds exception or whatever they call it, but is there not an unsigned int in Java?
It is writing in a sort of base-26, the Z is used for exact multiples of 26 however. The "0" character is used only on the number 0 itself.
So 0 -> 0 1 -> A 2 -> B 26 -> Z 27 -> AA 28 -> AB
etc. which gives you Excel column names so ignoring the fact that there is no column 0 in Excel, what you are generating might actually be useful, although there is no doubt a better way to code it.
Admin
However, this gives the wrong value: 27, because of the extra 'Z' at the beginning. Therefore, since everybody knows that the Latin arralphabet has 26 letters, it's defined as a final static.
Admin
You have failed when you don't know what an acronym is. It's actually impossible for an acronym to take more letters than the words it is an acronym for, since an acronym is comprised solely of the letters in those words.
Admin
Not an acronym. No sir. This is Hungarian notation, of course.
Admin
Apparently with a tribute to old BASIC languages, hence the "LET" at the end.
CAPTCHA 'vereor', more "OR" than a regular "OR"
Admin
FTFY
Not generally; only in hotels that cater for Americans ;-)
Admin
Yeah, utility classes like System.Math / java.lang.Math are pretty useless. In all seriousness, utility classes are a simple way to practice DRY and sometimes cannot be refactored into anything more elegant. Abuse/overuse of utility classes is certainly an antipattern. However, in this case we're talking about a Utilize class, which is a horse of a different color.
Admin
dec2Alpha(15796)
Admin
There's nothing wrong with it if you don't overdo it (i.e. recreate library functions) and name your utility classes correctly. Examples in the Java runtime lib are java.lang.Math and java.lang.Array. You neither "break modularization" nor do these class methods necessarily have to be instance methods, as has been claimed above.
Admin
Is "Arralphalet" a combination of "Array", "Alphabet", and "Epithet"?
I'm assuming this is Apache Commons' %29]StringUtils.join. If so, then the goal seems to be to return a String of characters. So the question is: "why?"
Captcha: suscipere -- this code is very suscipere
Admin
We should set a coding challenge to write a better algorithm for this.
Admin
The funny thing is the dec2Alpha method name, that takes an int...
captcha: tego - after seeing code like this, I have tego
Admin
I'm on-board with the Excel-cell theory. Messed up the link, but I don't know how to fix it.
Admin
Admin
Admin
Admin
Zst!
Oh, what.
Admin
And if ARRALPHALET only meant ARRay of ALPHAbet LETters ?
While we could argue that this is certainly not the best name to give to such array - or about the utility of the given array in the first place - this is a relatively minor WTF compared with the poor implementation of quasi-base26 encoding.
Admin
I see. So we're going to get rid of static methods entirely?
Admin
Admin
Having specific classes that perform common functions is not a bad thing. The examples of Math, Array, Collections... are just fine. They contain related methods of a specific purpose. However if you have a class named ${project_name}Util I guarantee you're doing it wrong. I've seen it. I've even done it (I've since fixed it). It's bad, don't do it. If you think you need it you have a larger problem with your application design.
Admin
I sure hope I never end up at destitute.
Admin
However, a Util class does not produce spaghetti code. The actual code for each function could (good luck, though) be clean, single-entry-single-exit, low coupling etc. Spaghetti code is random (bad word) full of unstructured gotos, invalid assumptions, etc., as found in BASIC code written by novices.
My point is not that it never happens the way you said so much as that it isn't automatic.
Admin
If you want me to take your position seriously, you're going to have to provide arguments, not injunctions.
Admin
Instead of arguing it's a poor design could you show the correct design ?
Admin
From this code snippet I get the impression that the author of dec2alpha was new to Java but had experience writing in C for a system that could have an ASCII or an EBCDIC character set.
Admin
QED
Admin
I'd like to see Sesame Street sing a song about The Arralphalet
Admin
Hopefully yes. There is no reason for them to exist.
A Util class is not object-oriented. Try to define its responsibility. If you write "it's supposed to hold everything that doesn't fit elsewhere" and compare that to other classes' responsibilities, you'll see that you have a beast that should be killed.
And existing Java libraries are no excuse to repeat their mistakes.
I might let you keep one static main() to get things rolling.
Admin
For me, TRWTF is that it's not written in python:
Admin
Well, the code does suck.
Admin
Only minor wtfs here. Here it is fixed: