• Captain Chaos (unregistered)

    Arrr, me likes!

  • Neville Flynn (unregistered)

    ["This", "is", "the", "arracomment!"]

  • frits (cs)

    I'm a big fan of arralphaletio*.

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

  • wtf (unregistered)

    /**

    • The utilize methods. */

    Oy.

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

  • Cbuttius (cs)

    The real WTF is that they forgot to code the lower-case arralphalet.

  • Crash Magnet (unregistered)

    ARRALPHALET vs ALPHABET

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

  • MOD26 (unregistered)

    It's just a conversion to base 26 poorly coded.

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

  • Red (unregistered)

    /**

    • the horror! */
  • 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.

  • Severity One (cs)

    It's not often that you see DEC Alpha mentioned here, let alone DEC 2 Alpha.

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

  • Mr. Spontaneous (cs)

    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.

  • Mike D. (unregistered) in reply to Adam
    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?
  • 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!

  • Remy Porter (cs) in reply to Mr. Spontaneous
    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.

  • Mike D. (unregistered) in reply to Mr. Spontaneous
    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.
  • Cbuttius (cs)

    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.

  • Severity One (cs) in reply to Mike D.
    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.

  • anon (unregistered) in reply to Crash Magnet
    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.

  • Sylver (unregistered) in reply to Crash Magnet
    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.

  • Anonymous (unregistered) in reply to Sylver
    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"

  • Dave (unregistered) in reply to Mike D.
    Mike D.:
    Do they skip the Mth floor, like here?

    FTFY

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

  • frits (cs) in reply to Remy Porter
    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.

  • Oslo (unregistered)

    dec2Alpha(15796)

  • NameNotFoundException (unregistered) in reply to Mr. Spontaneous
    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.

  • The Nerve (unregistered)
    Comment held for moderation.
  • Cbuttius (cs)

    We should set a coding challenge to write a better algorithm for this.

  • 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

  • The Nerve (unregistered) in reply to The Nerve
    Comment held for moderation.
  • dkf (cs) in reply to The Nerve
    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?
  • Ouch! (unregistered) in reply to pallen
    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.
  • Errorman (unregistered) in reply to Mike D.
    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.
  • Joel (unregistered)

    Zst!

    Oh, what.

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

  • wtf (unregistered) in reply to Mike D.
    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?

  • Ilya Ehrenburg (cs) in reply to frits
    frits:
    I'm a big fan of arralphaletio*.

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

    Creative misspelling of Fellatio?
  • smbell (cs) in reply to frits
    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.

  • Zylon (cs)

    I sure hope I never end up at destitute.

  • Steve The Cynic (cs) in reply to Remy Porter
    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.

  • frits (cs) in reply to smbell
    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.

  • MOD26 (unregistered) in reply to smbell

    Instead of arguing it's a poor design could you show the correct design ?

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

  • Crash Magnet (unregistered) in reply to anon
    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

  • bl@h (unregistered)

    I'd like to see Sesame Street sing a song about The Arralphalet

  • veniam (unregistered) in reply to wtf
    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.

  • 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"
    
  • Silfax (cs) in reply to Ilya Ehrenburg
    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.

  • The Nerve (unregistered)
    Comment held for moderation.

Leave a comment on “The Arralphalet”

Log In or post as a guest

Replying to comment #:

« Return to Article