• two 2 or not too bee (unregistered) in reply to Your Retarded
    Your Retarded:
    You're knot even joking either, are you?

    he must be knew to the internets

  • (cs)

    Seems to me back when I was learning Pascal, booleans were defined as a specific instance of enum.

  • Shinobu (unregistered) in reply to hoodaticus
    hoodaticus:
    Delphi? You're making this up - there's no such thing as Delphi.
    Nobody knows where Alesia is!
  • an old friend (unregistered) in reply to mmmmm
    mmmmm:
    me loves cum
  • (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.

    Consequently, it will not let you use enums as flags at low level libraries. Guess the place where enums are mostly popular in C.

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

    Yep. I/O is dangerous stuff. Keep it out of the way of newbies.

    That said, the only ironic thing up there is the "keep it out of the way..." part. The rest is just true.

  • (cs) in reply to Mcoder
    Mcoder:
    PedanticCurmudgeon:
    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.

    Yep. I/O is dangerous stuff. Keep it out of the way of newbies.

    That said, the only ironic thing up there is the "keep it out of the way..." part. The rest is just true.

    So that's why Stroustrup used the shift operator for I/O!

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

    It's the one with superior set handling, dummy.

  • (cs) in reply to frink
    frink:
    hoodaticus:
    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.

    It's the one with superior set handling, dummy.

    You're a towel!

  • (cs) in reply to hoodaticus
    hoodaticus:
    frink:
    hoodaticus:
    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.

    It's the one with superior set handling, dummy.

    You're a towel!

    flannel!

  • (cs) in reply to hoodaticus
    hoodaticus:
    frink:
    hoodaticus:
    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.

    It's the one with superior set handling, dummy.

    You're a towel!

    why would anyone want to use a set of enums anyway? That's just craazy talk...

  • J.J. (unregistered) in reply to Those who live in glass houses...
    Those who live in glass houses...:
    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.
    Uh...interesting choice of name. Actually, in computer science, Polymorphism references a specific idiom: multiple methods of the same name which each have a different count and set of argument types. I'm not entirely sure how frits thinks that polymorphism solves the problem the enums in the article obviously are solving, however.
  • HeraclesCA (unregistered) in reply to Coyne

    Agreed, 1.5 stop bits is important, at least historically.

    The WTF I was talking about is that you fill in a DCB with a number of data bits, a number of stop bits, etc. The code for data bits is 7 for 7 bits, 8 for 8 bits. But the code for 1 stop bit (which is 99% of the cases) is

    #define ONESTOPBIT 0

  • Kasper (unregistered) in reply to pjt33
    pjt33:
    Would have been a better troll with references to PHP and VB.
    Not to be confused with PHB and VP.
  • praesent (unregistered) in reply to EvanED
    EvanED:
    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.
    White Space? I don't remember a WTF about White space....

    I think it's Mr Bunny's Big Cup o' Java that demonstrates the simplest Java program is just whitespace.

  • tristique (unregistered) in reply to Severity One
    Severity One:
    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:
    <snip>

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

    I'm having De'ja' vu....

    I have a suspicion [strikeout]Microsoft Java[/strikeout] C# is much the same. And I thought we'd had arguments about it already, with the general consensus as the OP: If you want a class, make a class.

  • (cs)

    Reminds me of the time one of my colleagues defined a not-very-good enum. It made maintenance difficult till it was fixed.

  • tristique (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?

    CAPTCHA: enim

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

    Pyva and Jathon

  • Spoc42 (unregistered) 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.
    I totally agree. I consider this one of the strengths of Delphi, that strong typing is enforced, but typecasting is still possible, if necessary.
  • Spoc42 (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.

    Been there, done that. I had to use such a system of contants during the development of an embedded system programmed in assembler for a 6502-derivative. I needed two sets of contants for precisely those reasons. System is still running over 20 years later, so I must have done something right. . .

  • (cs) in reply to tristique
    tristique:
    I have a suspicion [strikeout]Microsoft Java[/strikeout] C# is much the same. And I thought we'd had arguments about it already, with the general consensus as the OP: If you want a class, make a class.
    No, actually. C# enums can't contain methods or fields (other than the enumerated values if they count - I can't be bothered to check whether they're fields according to the language spec or something else). In addition, and very annoyingly, you can't use "T : Enum" as a bound on a type variable T.
  • Spoc42 (unregistered) in reply to frink
    frink:
    hoodaticus:
    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.

    It's the one with superior set handling, dummy.

    Ah yes, the pleasure of creating a set of an enum. I'm sure that will freak any C-type programmers, since they don't have proper sets. Muahahahaha. . .

  • (cs) in reply to tristique
    tristique:
    If you want a class, make a class.
    Actually, could we please make this a general rule for programming?

    If you want X, make X.

    I'm tired of people inventing Y to solve/replace/complement X, simply because they don't understand X.

  • (cs) in reply to J.J.
    J.J.:
    Those who live in glass houses...:
    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.
    [troll meme]
    I'm not entirely sure how frits thinks that polymorphism solves the problem the enums in the article obviously are solving, however.
    I'm not entirely sure where frits claimed that polymorphism would solve the problem the enums in the article are supposedly solving.

    Good thing he finished with that bit about constants though, amirite?

  • (cs)

    One question, and I'm surprised nobody asked yet, but I (for one) am interested to know:

    1. Exactly what was the warning that John clicked on?
  • Peter (unregistered) in reply to Spoc42
    Spoc42:
    Been there, done that. I had to use such a system of contants during the development of an embedded system programmed in assembler for a 6502-derivative. I needed two sets of contants for precisely those reasons. System is still running over 20 years later, so I must have done something right. . .
    Twenty years later and it's still running? Isn't that rather a long time? In every system I've ever programmed, the aim has been for runs to finish in substantially less than twenty years.
  • (cs) in reply to Peter
    Peter:
    Spoc42:
    Been there, done that. I had to use such a system of contants during the development of an embedded system programmed in assembler for a 6502-derivative. I needed two sets of contants for precisely those reasons. System is still running over 20 years later, so I must have done something right. . .
    Twenty years later and it's still running? Isn't that rather a long time? In every system I've ever programmed, the aim has been for runs to finish in substantially less than twenty years.

    Hey! It's sending a 16 TB file at 9,600 baud; uncompressed; with 1.5 stop bits. It'll finish sometime around 2560.

    (Ah, how spoiled we are and don't know it.)

  • (cs) in reply to Those who live in glass houses...
    Those who live in glass houses...:
    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.
    Forced meme is forced.
  • (cs) in reply to pjt33
    pjt33:
    tristique:
    I have a suspicion [strikeout]Microsoft Java[/strikeout] C# is much the same. And I thought we'd had arguments about it already, with the general consensus as the OP: If you want a class, make a class.
    No, actually. C# enums can't contain methods or fields (other than the enumerated values if they count - I can't be bothered to check whether they're fields according to the language spec or something else). In addition, and very annoyingly, you can't use "T : Enum" as a bound on a type variable T.

    True, in C# you can actually compile this:

    object x;
    Enum.TryParse<object>("Try parse this, bitch!", out x);
    

    which actually will raise an exception at runtime, although you thought that using TryParse would protect you against them.

    Even uglier is that

     object Enum.Parse(Type, string)
    method for which even backwards compatibility is not a good excuse to still exist.

  • (cs) in reply to boog
    boog:
    One question, and I'm surprised nobody asked yet, but I (for one) am interested to know:
    1. Exactly what was the warning that John clicked on?
    Good question. I'm hoping the dialog simply said:
     WARNING: WTF is this?
  • (cs) in reply to tristique
    tristique:
    Severity One:
    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:
    <snip>

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

    I'm having De'ja' vu....

    I have a suspicion [strikeout]Microsoft Java[/strikeout] C# is much the same. And I thought we'd had arguments about it already, with the general consensus as the OP: If you want a class, make a class.

    See, I don't entirely agree there. The fact that an enum in Java is a class that can be extended is a very powerful feature.

    Of course, the problem with powerful features is that they can easily be abused, and I could imagine the case where someone writes a database connection pool in an enum. Why? Why not?

    What I like about Java over C# is that Sun/Oracle/JCP are a bit more careful with adding new features. It took them a while to add enums, but the chosen solution is quite elegant, contrary to how they did generics.

    Although Java 7 is long overdue; in fact, it's gone stone cold in terms of coffee.

  • QJo (unregistered) in reply to Severity One
    Severity One:
    tristique:
    Severity One:
    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:
    <snip>

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

    I'm having De'ja' vu....

    I have a suspicion [strikeout]Microsoft Java[/strikeout] C# is much the same. And I thought we'd had arguments about it already, with the general consensus as the OP: If you want a class, make a class.

    See, I don't entirely agree there. The fact that an enum in Java is a class that can be extended is a very powerful feature.

    Of course, the problem with powerful features is that they can easily be abused, and I could imagine the case where someone writes a database connection pool in an enum. Why? Why not?

    What I like about Java over C# is that Sun/Oracle/JCP are a bit more careful with adding new features. It took them a while to add enums, but the chosen solution is quite elegant, contrary to how they did generics.

    Although Java 7 is long overdue; in fact, it's gone stone cold in terms of coffee.

    Java 7 was released last Thursday - although I understand that Apache may have found some bugs in it.

  • (cs) in reply to Hortical
    Hortical:
    airdrik:
    Yeah, in fact they've already had kids, including Jython and Groovy (which actually has a 3rd parent in Ruby).
    Trisexualism? Fucking queers!
    Or maybe they're Azadis. Let's find out by asking them about what sorts of games they want to play.
  • Jibble (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.

    Java coders found a way around this on about day 2.

    Result of Java nannying: It has the same amount of trash as languages with enums, it's just more verbose and harder to read.

  • Jibble (unregistered) in reply to Ed
    Ed:
    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.

    Enums in the global namespace = bad idea.

    Scoped enums together with strong type checking = good idea.

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

    Trisexualism? Fucking queers!

    raises an eyebrow

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

    Trisexualism? Fucking queers!

    Polymorphic perversion.

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

    Trisexualism? Fucking queers!

    raises an exception

    FTFY

  • Xeross (unregistered)
    dohpaz42:
    <?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.

    Your syntax is too far off, that array is completely unneeded.

    <?php
    function enum() {
        foreach (func_get_args() as $k => $enum)
            define(strtoupper($enum), $k);
    }
    
    enums(
        'frist',
        'wtf',
        'file_not_found',
    );
    
    echo FRIST . PHP_EOL;
    echo WTF . PHP_EOL;
    echo FILE_NOT_FOUND . PHP_EOL;
    
    ?>
    
  • (cs) in reply to Ocson
    Ocson:
    I didn't want to post this comment but you left me know choice.
    The editor should of caught that one.

    Language Abuse

  • Harrow (unregistered) in reply to Peter
    Peter:
    Spoc42:
    Been there, done that. I had to use such a system of contants during the development of an embedded system programmed in assembler for a 6502-derivative. I needed two sets of contants for precisely those reasons. System is still running over 20 years later, so I must have done something right. . .
    Twenty years later and it's still running? Isn't that rather a long time? In every system I've ever programmed, the aim has been for runs to finish in substantially less than twenty years.
    Did you ever work for Microsoft? My WIN NT system used to finish two or three times a day.

    -Harrow.

  • pip010 (unregistered) in reply to frits

    fuk JAVA

  • Harrow (unregistered)

    'John continues, "I didn't even realize that _1 was a valid identifier..."'

    John undoubtedly also does not know that '' is a valid identifier. (Or '', '', etc.)

    I often include this constant definition:

    _=0;

    which I then use to mark unused constant array entries, to distinguish them from required entries equal to zero.

    When anybody questions this practice I explain that a singulized underscore is a perfectly cromulent symbol.

    -Harrow.

  • Xami (unregistered)

    It's the perpetuation of this stereotype that frustrates me to no end playing poker with new players.

    I'll see your x and raise you y!

    No, you said I'll see your x. End of bet. You can't raise after that, it's a string bet that you're making with your mouth.

  • gha (unregistered)

    The OP first states that fixing bugs is a high priority for him. Then, being a sensible developer, he finds that replacing an identifier that he did not know was syntactivally valid (due to his unfamiliarity with the language he's using) is even a higher priority than fixing bugs. That does not fit well with my definition of "sensible," sorry. To me, the WTF is with his assessment of priorities, not with the code.

  • just me (unregistered) in reply to praesent
    praesent:
    EvanED:
    Seriously, is there a language feature out there that we haven't seen multiple WTFs about?
    White Space? I don't remember a WTF about White space....

    I think it's Mr Bunny's Big Cup o' Java that demonstrates the simplest Java program is just whitespace.

    Very easy to abuse white space:

    if (i != 0)
        printf("i is not zero, let's divide something by it!");
        int y = 100 / i;
    
  • gha (unregistered) in reply to Harrow

    This is what we do in OCaml: _ stands for any formal argument (or, generally, part of a structured value pattern) that you do not want to refer to and, hence, do not want to bind to a name.

  • (cs) in reply to just me
    just me:
    Very easy to abuse white space:
    if (i != 0)
        printf("i is not zero, let's divide something by it!");
        int y = 100 / i;
    
    There are languages, such as Python, that are not context-free and as such, this would work (if we ignore for a moment that the above is not valid Python). Indenting your code is always important, but it's really important in Python.
  • (cs) in reply to J.J.
    J.J.:
    Those who live in glass houses...:
    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.
    Uh...interesting choice of name. Actually, in computer science, Polymorphism references a specific idiom: multiple methods of the same name which each have a different count and set of argument types. I'm not entirely sure how frits thinks that polymorphism solves the problem the enums in the article obviously are solving, however.
    I think polymorphism has more emphasis on substitution of types with different behavior than it does on overloading. I could give up method overloading before I could give up inheritance.

    The enums in the OP specify versions. You can just see them being passed to methods to specify which version of behavior you want the method to follow. This is handled better by polymorphism, wherein behavior is specified by type rather than parameter.

    Of course, at some point you have to decide which subtype to construct. Hopefully, these enums are only being used in a switch block with constructor calls in them and nowhere else. But I have my doubts.

  • QJo (unregistered) in reply to Xami
    Xami:
    It's the perpetuation of this stereotype that frustrates me to no end playing poker with new players.

    I'll see your x and raise you y!

    No, you said I'll see your x. End of bet. You can't raise after that, it's a string bet that you're making with your mouth.

    So what exactly is the correct terminology for matching the amount of money being put into the centre of the table, then adding a little bit more, with the intention that it go round the table once more?

Leave a comment on “An Enum or _2”

Log In or post as a guest

Replying to comment #:

« Return to Article