Comment On The Arralphalet

James sent in today's snippet with virtually no introduction; just six, measly words: "the grass is definitely not greener." Normally, that'd be a bit frustrating, since it's always nice to know a little history or background about the code. But like those six word stories, James told the classic tale of the young and burgeoning software developer who’s always looking to expand his professional purview by seeking out new opportunities to learn and sharpen his skills, only to find his efforts frustrated by a “seemed good on paper” job that leads to nowhere – or worse – towards destitute and despair. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: The Arralphalet

2010-08-09 09:02 • by Captain Chaos (unregistered)
Arrr, me likes!

Re: The Arralphalet

2010-08-09 09:06 • by Neville Flynn (unregistered)
["This", "is", "the", "arracomment!"]

Re: The Arralphalet

2010-08-09 09:07 • by frits
I'm a big fan of arralphaletio*.



*Starts off as "phaletio" and ends with ralphing.

Re: The Arralphalet

2010-08-09 09:09 • by wtf (unregistered)
/**
* The utilize methods.
*/

Oy.

Re: The Arralphalet

2010-08-09 09:12 • by JdFalcon04 (unregistered)
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.

Re: The Arralphalet

2010-08-09 09:14 • by Cbuttius
The real WTF is that they forgot to code the lower-case arralphalet.

Re: The Arralphalet

2010-08-09 09:15 • by Crash Magnet (unregistered)
ARRALPHALET vs ALPHABET

You have failed when you acronym takes more letters than the correct spelling.



Re: The Arralphalet

2010-08-09 09:16 • by MOD26 (unregistered)
It's just a conversion to base 26 poorly coded.

Re: The Arralphalet

2010-08-09 09:18 • by Adam (unregistered)
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.

Re: The Arralphalet

2010-08-09 09:19 • by Red (unregistered)
/**
* the horror!
*/

Re: The Arralphalet

2010-08-09 09:19 • by Mike D. (unregistered)
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.

Re: The Arralphalet

2010-08-09 09:19 • by Severity One
It's not often that you see DEC Alpha mentioned here, let alone DEC 2 Alpha.

Re: The Arralphalet

2010-08-09 09:19 • by pallen (unregistered)
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).

Re: The Arralphalet

2010-08-09 09:20 • by Mr. Spontaneous
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.

Re: The Arralphalet

2010-08-09 09:20 • by Mike D. (unregistered)
316907 in reply to 316901
Adam:
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.

Do they skip the 13th floor, like here?

Re: The Arralphalet

2010-08-09 09:23 • by Mad Adder (unregistered)
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!

Re: The Arralphalet

2010-08-09 09:23 • by Remy Porter
316909 in reply to 316906
Mr. Spontaneous:
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.


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.

Re: The Arralphalet

2010-08-09 09:23 • by Mike D. (unregistered)
316910 in reply to 316906
Mr. Spontaneous:
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.

If it doesn't manipulate the object, it doesn't need to be in the object. So a 'Util' class makes no sense unless you're creating 'Util's.

Re: The Arralphalet

2010-08-09 09:26 • by Cbuttius
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.

Re: The Arralphalet

2010-08-09 09:27 • by Severity One
316912 in reply to 316903
Mike D.:
Wow, Java has no len() or chr() functions? Glad I never wasted my time with it.

It does not, indeed, have a len() method (they're called methods if you're being object-oriented) for array; it has a field (more accurately, a 'member') called 'length'.

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.

Re: The Arralphalet

2010-08-09 09:27 • by anon (unregistered)
316913 in reply to 316899
Crash Magnet:
ARRALPHALET vs ALPHABET

You have failed when you acronym takes more letters than the correct spelling.





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.

Re: The Arralphalet

2010-08-09 09:32 • by Sylver (unregistered)
316914 in reply to 316899
Crash Magnet:
ARRALPHALET vs ALPHABET

You have failed when you acronym takes more letters than the correct spelling.


Not an acronym. No sir. This is Hungarian notation, of course.

Re: The Arralphalet

2010-08-09 09:35 • by Anonymous (unregistered)
316915 in reply to 316914
Sylver:
Crash Magnet:
ARRALPHALET vs ALPHABET

You have failed when you acronym takes more letters than the correct spelling.


Not an acronym. No sir. This is Hungarian notation, of course.


Apparently with a tribute to old BASIC languages, hence the "LET" at the end.

CAPTCHA 'vereor', more "OR" than a regular "OR"

Re: The Arralphalet

2010-08-09 09:36 • by Dave (unregistered)
316916 in reply to 316907
Mike D.:
Do they skip the Mth floor, like here?


FTFY

Not generally; only in hotels that cater for Americans ;-)

Re: The Arralphalet

2010-08-09 09:40 • by frits
316917 in reply to 316909
Remy Porter:
Mr. Spontaneous:
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.


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.


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.

Re: The Arralphalet

2010-08-09 09:40 • by Oslo (unregistered)
dec2Alpha(15796)

Re: The Arralphalet

2010-08-09 09:42 • by NameNotFoundException (unregistered)
316919 in reply to 316906
Mr. Spontaneous:
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.


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.

Re: The Arralphalet

2010-08-09 09:49 • by The Nerve (unregistered)
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

Re: The Arralphalet

2010-08-09 09:50 • by Cbuttius
We should set a coding challenge to write a better algorithm for this.

Re: The Arralphalet

2010-08-09 09:50 • by some anon (unregistered)
The funny thing is the dec2Alpha method name, that takes an int...

captcha: tego - after seeing code like this, I have tego

Re: The Arralphalet

2010-08-09 09:53 • by The Nerve (unregistered)
316923 in reply to 316920
The Nerve:
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


I'm on-board with the Excel-cell theory. Messed up the link, but I don't know how to fix it.

Re: The Arralphalet

2010-08-09 09:54 • by dkf
316924 in reply to 316920
The Nerve:
Is "Arralphalet" a combination of "Array", "Alphabet", and "Epithet"?
ARRay of ALPHAbet LETters I'd guess, and probably all in upper case because of some rule about constants having to be upcased. But why oh why did they hate underscores so much?

Re: The Arralphalet

2010-08-09 09:55 • by Ouch! (unregistered)
316925 in reply to 316905
pallen:

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).

I think ARRALPHALET expands to ARRay of ALPHAbet LETters, which kinda makes sense. It's a stupid name, but it doesn't hurt like the rest of the code.

Re: The Arralphalet

2010-08-09 09:58 • by Errorman (unregistered)
316926 in reply to 316907
Mike D.:
Adam:
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.

Do they skip the 13th floor, like here?

Yes, because of course they have to get used to handling FLOOR_NOT_FOUND errors.

Re: The Arralphalet

2010-08-09 09:59 • by Joel (unregistered)
Zst!

Oh, what.

Re: The Arralphalet

2010-08-09 10:02 • by Pierre Tramo (unregistered)
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.

Re: The Arralphalet

2010-08-09 10:04 • by wtf (unregistered)
316930 in reply to 316910
Mike D.:
Mr. Spontaneous:
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.

If it doesn't manipulate the object, it doesn't need to be in the object.


I see. So we're going to get rid of static methods entirely?

Re: The Arralphalet

2010-08-09 10:06 • by Ilya Ehrenburg
316931 in reply to 316895
frits:
I'm a big fan of arralphaletio*.



*Starts off as "phaletio" and ends with ralphing.


Creative misspelling of Fellatio?

Re: The Arralphalet

2010-08-09 10:11 • by smbell
316932 in reply to 316917
frits:
Remy Porter:
Mr. Spontaneous:
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.


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.


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.


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.

Re: The Arralphalet

2010-08-09 10:12 • by Zylon
I sure hope I never end up at destitute.

Re: The Arralphalet

2010-08-09 10:22 • by Steve The Cynic
316934 in reply to 316909
Remy Porter:
It creates spaghetti code and breaks modularization.

It doesn't exactly "break" modularization; it is more like the opposite of modular code, a single thingy that looks like a module until you realise that the contents aren't actually related to each other.

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.

Re: The Arralphalet

2010-08-09 10:22 • by frits
316935 in reply to 316932
smbell:
frits:
Remy Porter:
Mr. Spontaneous:
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.


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.


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.


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.


If you want me to take your position seriously, you're going to have to provide arguments, not injunctions.

Re: The Arralphalet

2010-08-09 10:22 • by MOD26 (unregistered)
316936 in reply to 316932
Instead of arguing it's a poor design could you show the correct design ?

Re: The Arralphalet

2010-08-09 10:31 • by Gruntled Postal Worker (unregistered)
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.

Re: The Arralphalet

2010-08-09 10:50 • by Crash Magnet (unregistered)
316940 in reply to 316913
anon:
Crash Magnet:
ARRALPHALET vs ALPHABET

You have failed when you acronym takes more letters than the correct spelling.





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.


QED

Re: The Arralphalet

2010-08-09 10:58 • by bl@h (unregistered)
I'd like to see Sesame Street sing a song about The Arralphalet

Re: The Arralphalet

2010-08-09 11:01 • by veniam (unregistered)
316942 in reply to 316930
I see. So we're going to get rid of static methods entirely?


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.

Re: The Arralphalet

2010-08-09 11:02 • by Hugh Brown (unregistered)
For me, TRWTF is that it's not written in python:

from string import uppercase
def dec2alpha(num):
result = []
while num:
num, x = divmod(num, 26)
result.append(uppercase[x])
return "".join(reversed(result)) or "A"

Re: The Arralphalet

2010-08-09 11:08 • by Silfax
316944 in reply to 316931
Ilya Ehrenburg:
frits:
I'm a big fan of arralphaletio*.



*Starts off as "phaletio" and ends with ralphing.


Creative misspelling of Fellatio?


Well, the code does suck.

Re: The Arralphalet

2010-08-09 11:11 • by The Nerve (unregistered)
Only minor wtfs here. Here it is fixed:


/**
* Common class for utility method
*/
public final class Util {

/**
* Valid Excel cell characters, indexed at 1 (except
*for "Z").
* I read an article on thedailywtf.com where they
* ridiculed the use of the "Apples" month when someone
* else was trying to solve the same problem, so I'll
* put "Z" in the first position and make it accessible
* with the 0 index.
*/
private static final String[] ALPHABET = new String[] {
"Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
"V", "W", "X", "Y", "Z" };

/**
* length of the alphabet. Manually set to 26, in case
* some bozo doesn't know what he's doing and tries to
* add extra characters to ALPHABET.
*/
private static final int ALPHABET_LEN = 26;

/**
* return the name of the current column in Excel
* @param index, should be greater than 0.
* @return the String for the current given column in Excel
*/
public static String getExcelColumnName(final int index) {
StringBuffer result = new StringBuffer();

int a = index;
int b;
do {
b = a / ALPHABET_LEN;
final int c = a % ALPHABET_LEN;
if (c == 0 && b == 0) {
result.insert(0, "0");
} else if (c == 0 && b != 0) {
b = b - 1;
result.insert((0, ALPHABET[c]);
} else {
result.insert((0, ALPHABET[c]);
}
a = b;
}
while (a > ALPHABET_LEN);

if (a != 0) {
result.insert((0, ARRALPHALET[a]);
}
return result.toString();
}
}
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment