• Anonymous Cow-Herd (unregistered)

    No FILE_NOT_FOUND? Son, I am disappoint.

    Also, frist-ish.

  • G-man (unregistered)

    public enum Frist {

    _INB4 = 'file_not_found'

    }

  • Scott Lawrence (unregistered)

    _2nd. (= 1)

    Here's betting that some "developer" had a text editor set to elide all underscores.

  • Ocson (unregistered)

    I didn't want to post this comment but you left me know choice.

  • (cs)

    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.

  • (cs)

    Most ugly code can be fixed, but public enum ugly is forever!

  • (cs) in reply to frits
    frits:
    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism.
    This. Good job picking up on the ugliness between the lines - they're using ENUMS FOR POLYMORPHISM. Versions are variations of a type, ergo...
  • JayC (unregistered) in reply to frits
    frits:
    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism.

    I'm not sure how that keeps you from having:

    public class _1 {
    
    }
    

    CAPTCHA: haero.. anybody tere?

  • Ed (unregistered) in reply to frits
    frits:
    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.

    Nah, Enums are great when you use them as what they're meant for, which is a nice way of grouping a bunch of related flags.

    Need to indicate whether a product is blue, red or green? Use an Enum.

    I'll agree that they're pretty easy to abuse though.

  • Chris (unregistered)

    "know choice"

    seriously? That's another WTF right there :P

  • airdrik (unregistered) in reply to frits
    frits:
    python was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.
    FTFY (java does have enums, they're just not these worthless, meaningless, integer wrapper pieces of garbage)
  • mmmmm (unregistered)

    me loves enum

  • Those who live in glass houses... (unregistered) in reply to frits
    frits:
    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.
    I wish all you ivory tower wannabes would get off your high horses. Enums are polymorphic types! Do you even know what polymorphic means? It means "many forms". Enums take many forms. Now STFU.
  • (cs) in reply to frits
    frits:
    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.
    Not bad. I'll give you an 8. Would have been a better troll with references to PHP and VB.
  • (cs)
    _1 = 0

    This reminds me of the way Wikipedia (well, MediaWiki) numbers references and their corresponding hyperlinks. The printed reference numbers are one-based, but the hyperlinks are zero-based. It drives me nuts.

    For example: http://en.wikipedia.org/wiki/Counting#cite_note-0 .

  • Eponymous (unregistered)

    Not only is it a valid identifier, but in C++0x it's used as part of the standard library (specifically, std::placeholders::_1) and in Scala for members of a tuple.

  • (cs) in reply to Eponymous
    Eponymous:
    Not only is it a valid identifier, but in C++0x it's used as part of the standard library (specifically, std::placeholders::_1) and in Scala for members of a tuple.
    I use _ to prefix member variables, since m_ is too wordy for me.
  • (cs) in reply to pjt33
    pjt33:
    frits:
    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.
    Not bad. I'll give you an 8. Would have been a better troll with references to PHP and VB.
    <?php
    function enum(Array $enums) {
        foreach ($enums as $k => $enum)
            define(strtoupper($enum), $k);
    }
    
    enums(array(
        'frist',
        'wtf',
        'file_not_found',
    ));
    
    echo FRIST . PHP_EOL;
    echo WTF . PHP_EOL;
    echo FILE_NOT_FOUND . PHP_EOL;
    ?>

    I admit that at one point in my early career, I used the above paradigm for creating enums. Thankfully, I've matured since then, and I don't do this anymore.

  • Anonymous (unregistered)

    Enums are meant to be typed constants but then, things like this happen :(

  • (cs)

    Seems to me like the owner was being trolled by his own employees.

  • Winston (unregistered)

    Yes, I may well be drunk, but that code is very, very ugly. But by tomorrow, I shall be sober, while this code will still be ugly.

  • (cs)

    "Being the sensible developer that I am, I emailed the team that we refactor the code."

    Is this Alex-speak for "Do the needful"?

  • Richard (unregistered) in reply to frits

    Java has enums :|

  • Your Retarded (unregistered) in reply to Chris

    You're knot even joking either, are you?

  • (cs) in reply to Anonymous
    Ed:
    I'll agree that they're pretty easy to abuse though.
    What isn't?

    Seriously, is there a language feature out there that we haven't seen multiple WTFs about?

    Anonymous:
    Enums are meant to be typed constants but then, things like this happen :(
    Well to be fair, "then C happens" since it doesn't exactly go out of it's way to actually make them typed constants. At all.
  • HeraclesCA (unregistered)

    Valid values for Stop Bits in the DCB for a serial port (from the Windows common header file WinBase.h) :

    #define ONESTOPBIT 0 #define ONE5STOPBITS 1 #define TWOSTOPBITS 2

    The same header file also includes (for some other API):

    #define STOPBITS_10 ((WORD)0x0001) #define STOPBITS_15 ((WORD)0x0002) #define STOPBITS_20 ((WORD)0x0004)

  • aiyo (unregistered) in reply to frits
    frits:
    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.

    http://download.oracle.com/javase/tutorial/java/javaOO/enum.html

    In the Java programming language, you define an enum type by using the enum keyword. For example, you would specify a TDWTF enum type as:

    public enum Day { _1, _2, FILE_NOT_FOUND, _3, NUM_WTFS, INVALID=-1 }

  • (cs) in reply to frits
    frits:
    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.
    Ah, but when they introduced enums in Java 5, they went all the way. See, enums in Java are static instantiations of a class. So you can actually create constructors in your enums. Like this:
    import java.io.FileNotFoundException;
    
    public enum MyBoolean
    {
        TRUE( Boolean.TRUE ),
        FALSE( Boolean.FALSE ),
        FILE_NOT_FOUND( null );
    
        private Boolean value;
    
        private MyBoolean( Boolean value )
        {
            this.value = value;
        }
    
        public Boolean asBoolean() throws FileNotFoundException
        {
            if( value == null )
                throw new FileNotFoundException();
    
            return value;
        }
    }

    You see, you can f*** up enums in Java as well, but much more elegantly than in most other languages.

  • (cs) in reply to airdrik
    airdrik:
    frits:
    python was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.
    FTFY (java does have enums, they're just not these worthless, meaningless, integer wrapper pieces of garbage)
    I believe he said "java was right for leaving out enums". See the verb tense there?
  • The Enumerator (unregistered)

    Anything is open to abuse. #define statements have been the cause of much grief for me in the past.

    operator overloading is the devil's own invention and some say goto statements are considered harmful.

    In the past i proposed a level based system that prevents entry level programmers from accessing features that were open to abuse.

    with time i learned that anything is open to abuse so that basically means banning all new devs.

    actually...it's not such a bad idea...

  • GOOD_MORNING (unregistered) in reply to Winston

    Winston Churchill references FTW.

  • (cs)

    IIRC, leading underscores are allowed in C/C++, but are "reserved for the implementation". That is, if you ever write one yourself it is not valid C/C++.

  • (cs) in reply to EvanED
    EvanED:
    Anonymous:
    Enums are meant to be typed constants but then, things like this happen :(
    Well to be fair, "then C happens" since it doesn't exactly go out of it's way to actually make them typed constants. At all.
    This. In Delphi, by contrast, enums are real typed constants. Attempting to mix an enum and an integer, or two enums of different types (at least without an explicit cast or an Ord()) is a syntax error.
  • JayC (unregistered) in reply to hoodaticus
    hoodaticus:
    airdrik:
    frits:
    python was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.
    FTFY (java does have enums, they're just not these worthless, meaningless, integer wrapper pieces of garbage)
    I believe he said "java was right for leaving out enums". See the verb tense there?

    Just who is this Java person and this Python person, anyway? If Java met Python, could they talk the same language? Could they make babies?

    CAPTCHA: enim

    Captcha's learning how to read... not quite there yet.

  • ac (unregistered) in reply to frits

    Right. Because nothing replaces a mechanism for creating closed/fixed sets like two mechanisms for creating open sets.

  • Jay (unregistered) in reply to frits
    frits:
    Java was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.
    <feed target="troll"> Umm, you are aware that enums were added to Java in, I think it was version 1.5?

    But to the point: What if you want to create a set of related constants, and create a type-safe way to pass a value that is then restricted to being a member of this set?That's what enums are truly good for, and what I presume they were invented for.

    In any case, how would the problem illustrated here have been prevented if there was no such thing as enums? The programmer could just as well have written

    #define _1 0

    </feed>
  • airdrik (unregistered) in reply to JayC
    JayC:
    hoodaticus:
    airdrik:
    frits:
    python was right for leaving out enums. Otherwise you get this kind of trash. If you want to have different types, use polymorphism. If you want constants, use, well, constants.
    FTFY (java does have enums, they're just not these worthless, meaningless, integer wrapper pieces of garbage)
    I believe he said "java was right for leaving out enums". See the verb tense there?

    Just who is this Java person and this Python person, anyway? If Java met Python, could they talk the same language? Could they make babies?

    Yeah, in fact they've already had kids, including Jython and Groovy (which actually has a 3rd parent in Ruby).
  • Hortical (unregistered) in reply to airdrik
    airdrik:
    Yeah, in fact they've already had kids, including Jython and Groovy (which actually has a 3rd parent in Ruby).

    Trisexualism? Fucking queers!

  • (cs) in reply to ac
    ac:
    Right. Because nothing replaces a mechanism for creating closed/fixed sets like two mechanisms for creating open sets.
    OO Polymorphism replaces the need to know about set size or even if a set exists. Of course you'd know this if cared about anything besides your precious maths.
  • (cs) in reply to Mason Wheeler
    Mason Wheeler:
    EvanED:
    Anonymous:
    Enums are meant to be typed constants but then, things like this happen :(
    Well to be fair, "then C happens" since it doesn't exactly go out of it's way to actually make them typed constants. At all.
    This. In Delphi, by contrast, enums are real typed constants. Attempting to mix an enum and an integer, or two enums of different types (at least without an explicit cast or an Ord()) is a syntax error.
    Delphi? You're making this up - there's no such thing as Delphi.
  • (cs) in reply to Severity One
    Severity One:
    You see, you can f*** up enums in Java as well, but much more elegantly than in most other languages.
    Sad but true.
  • (cs) in reply to The Enumerator
    The Enumerator:
    In the past i proposed a level based system that prevents entry level programmers from accessing features that were open to abuse.
    Actually, this system exists. It's called Haskell. It works by restricting anything open to abuse to running inside a monad. Entry level programmers couldn't possibly understand monads, so just make everyone code in Haskell. Problem solved. You're welcome.
  • Umakant (unregistered) in reply to Anonymous Cow-Herd

    It was often situation that when one user switch caffe aparat on, Samir's computer resets itself. UPS? What is this??? As you can expect, such 'stable' voltage distroyed Samir's hard disc...

  • (cs) in reply to Raedwald
    Raedwald:
    IIRC, leading underscores are allowed in C/C++, but are "reserved for the implementation". That is, if you ever write one yourself it is not valid C/C++.
    Time to put on my language lawyer hat. I'm not 100% sure that this is the same in C and C++, but in C++ the rules are as follows.

    Any name beginning with an underscore and capital letter, or containing two consecutive underscores anywhere, is reserved in all scopes. (In other words, compilers can define macros that stomp all over these identifiers.)

    Other identifiers beginning with an underscore -- for example, _1 -- are legal as long as they are not at global scope. If that enum is in a namespace or a class, or local to a function (I think you can do that), you're good-to-go. If it is global, then it's reserved to the implementation.)

  • Anonymous (unregistered)

    Actually the last example isn't all that bad once you get arund the _1 == 0 thing (the naming sucks, either you use enum class and C++0x or you prefix your enum values with the name of the enum, like VERSION_1).

    Using an extra value that contains the number of valid values is a neat trick for an enum that often gets modified (like this one). Probably exactly as the language designers intended, but still OK. I've seen that in a couple of projects that were definitely not WTF.

    As for INVALID, I guess it works and still doesn't make it worse than enum Enum ;-)

  • (cs)

    I don't think John should have "folded" so easily. Clearly he was the winner if he hadn't folded.

    After all, his had (1) the redundant declarative for the value of beta; (2) the stupid identifier _1; (3) constant doubling, wherein R22 = 22 = 2; (4) the stupid R456 declarative, that falls in the same class as "XYZZY" and has nothing to do with its value, 3; and (5) a nonsensical limit constant, because since these are ID's, why does it matter how many there are?

    Five enum constants, five WTF's. That's gotta be equivalent to a royal flush.

  • (cs) in reply to HeraclesCA
    HeraclesCA:
    Valid values for Stop Bits in the DCB for a serial port (from the Windows common header file WinBase.h) :

    #define ONESTOPBIT 0 #define ONE5STOPBITS 1 #define TWOSTOPBITS 2

    The same header file also includes (for some other API):

    #define STOPBITS_10 ((WORD)0x0001) #define STOPBITS_15 ((WORD)0x0002) #define STOPBITS_20 ((WORD)0x0004)

    Believe it or not, this isn't as dumb as it sounds. RS-232 communications provided for 1, 1.5 or 2 stop bits.

    While 1.5 stop bits might sound idiotic in terms of memory (where bits are inseparable units), RS-232 deals with serial transmission, where 1.5 stop bits means, "the stop bit time is 1.5 times a one-bit transmission interval."

    So at 9600 baud, 1 stop bit is .000104167 seconds, 2 is .00020833 seconds, and 1.5 stop bits is .00015625 seconds.

    Also, the second set of constants are the bit patterns for controlling a Universal Asynchronous Receiver Transmitter (UART) chip. It makes sense to have two sets of constants in this case, one for local software to use, and one for controlling the UART.

  • BrainSlugs83 (unregistered) in reply to frits

    Leave it to a java developer to miss the problem entirely...

    Also, the grammar in this article, it burns, and the goggles? They do nothing.

  • Somebody (unregistered) in reply to Coyne
    Coyne:
    HeraclesCA:
    Valid values for Stop Bits in the DCB for a serial port (from the Windows common header file WinBase.h) :

    #define ONESTOPBIT 0 #define ONE5STOPBITS 1 #define TWOSTOPBITS 2

    The same header file also includes (for some other API):

    #define STOPBITS_10 ((WORD)0x0001) #define STOPBITS_15 ((WORD)0x0002) #define STOPBITS_20 ((WORD)0x0004)

    Believe it or not, this isn't as dumb as it sounds. RS-232 communications provided for 1, 1.5 or 2 stop bits.

    While 1.5 stop bits might sound idiotic in terms of memory (where bits are inseparable units), RS-232 deals with serial transmission, where 1.5 stop bits means, "the stop bit time is 1.5 times a one-bit transmission interval."

    So at 9600 baud, 1 stop bit is .000104167 seconds, 2 is .00020833 seconds, and 1.5 stop bits is .00015625 seconds.

    Also, the second set of constants are the bit patterns for controlling a Universal Asynchronous Receiver Transmitter (UART) chip. It makes sense to have two sets of constants in this case, one for local software to use, and one for controlling the UART.

    Who UARTed?

  • (cs) in reply to Coyne
    Coyne:
    I don't think John should have "folded" so easily. Clearly he was the winner if he hadn't folded.

    After all, his had (1) the redundant declarative for the value of beta; (2) the stupid identifier _1; (3) constant doubling, wherein R22 = 22 = 2; (4) the stupid R456 declarative, that falls in the same class as "XYZZY" and has nothing to do with its value, 3; and (5) a nonsensical limit constant, because since these are ID's, why does it matter how many there are?

    Five enum constants, five WTF's. That's gotta be equivalent to a royal flush.

    I'm not prepared to go nearly as far as you did in condemning that example.

    (1) Redundancy is not, in-and-of-itself, a WTF. While I wouldn't write =0, I also would not fault someone terribly for doing so. (3) and (4) While I'm not so hopeful for this given the name of the enum (DebugId) and the general naming quality (and the 456), theoretically it is possible that R22 and R456 would be domain-specific things.

    Finally, (5) is virtually never a WTF. Having a limit can have a number of benefits. You can add runtime assertions that an enum value falls into the range [0, NUM_ENUM_VALUES); that alone is good enough for me. A lot of times (maybe not in this case) it's useful to be able to print out the value of an enum in a friendlier format than just "3"; probably the best way to do this is to have an array somewhere with string representations indexed by the enum. If you have a NUM_ENUM_VALUES in there, you can add a static assertion that the number of enum values and the size of the array are the same. Finally, just because it's an ID doesn't mean you won't ever want to iterate through them. (Again, may not apply in this case.)

Leave a comment on “An Enum or _2”

Log In or post as a guest

Replying to comment #:

« Return to Article