• Dlareg (unregistered)

    Well in this code there are only 2 options. So the only other option would be to turn them around then Two == 0 and even worse Two == False. So to get to Two == 2 you should add a dummy variable.

    not so much a wtf.

  • Bradley (unregistered) in reply to Dlareg

    ...Or explicitly set Two = 2;

  • (nodebb) in reply to Dlareg

    Or, use a better name than Two.

  • snoofle (unregistered)

    One is the loneliest number that you'll ever do Two can be as bad as one It's the loneliest number since the number one ...

  • Sharp (unregistered) in reply to Dlareg

    ..Or not compare enum with an integer.

  • aaa (unregistered)

    Second!

  • (nodebb)

    The numeric value becomes important in the context of database storage and serialization.

  • Kleyguerth (github) in reply to Sharp

    Or use Java and laugh at those poor languages that force enums to be equal to numbers

  • Little Bobby Tables (unregistered)

    Come a little bit closer, baby Get it on, get it on 'Cause tonight is the night when two become one

  • Wizard (unregistered)

    Shall we just ignore the fact that it would throw a CA warning anyway? It should be "None", "Default", "Two" in which case (under the hood) "Two" would be numerically 2 anyway. I wonder if "One" was legacy and was removed when it should have been marked [Obsolete]. Have seen that dangerous practise before as well as someone deciding to order the enum values so they were alphabetical :-(

  • (nodebb)

    No, "Two" is not meant to represent the number 2. It is a three letter word, it means "The Wtfy Object".

  • Geoff (unregistered) in reply to Mr. TA

    Yea because being able to predictably serialize out enums as a simple integer is terrible.

  • gumpy_gus (unregistered)

    Could be worse, the tendency is to define enum boolean = ( true, false ); which is of course exactly backwards to convention.

  • (nodebb)

    I'm not sure which is more WTF. This, or my boss's tendency to define VARCHAR columns with values 'YES' and 'NO' for boolean fields?

  • (nodebb) in reply to Kleyguerth

    What?? Java enums don't have just one backing value, they can have many! That's in addition to the ordinal. That may or may not be a useful feature, but your implication that there's no comparing enums to integers or any other numeric value in java is plain wrong.

  • (nodebb) in reply to Barry Margolin 0

    We need to have a WTF Olympics!!!!

  • RichP (unregistered)

    My 2018 new year's resolution is to stop making off-by-one errors! (stolen from somewhere else online).

  • (nodebb)

    Obviously that’s because the frist case is missing.

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered)

    TRWTF is the lack of a File_Not_Found enum constant

  • Zach (unregistered) in reply to RichP

    :D That's great!

  • siciac (unregistered) in reply to snoofle

    That's a good tune.

  • siciac (unregistered) in reply to Kleyguerth

    Other languages don't need a full machine word to represent an enum with 4 choices.

  • (nodebb) in reply to Mr. TA

    Well, this specific example is C#, not Java, but as Remy points out that's not really relevant. But what mess are you working with that you can't reliably serialise/insert - deserialise/query an enum value without poking around in its innards? Don't the things have interfaces so you can avoid having to do that?

    I can see problems arising if you try to use a smallint to store an enum that has values that cast to something greater than 32767. Or are you talking about the serialised/database data being used by other systems that don't have your enum defined?

  • Rashev Markov (unregistered)

    X.509 certificate version field has numerical value 1 to represent "version 2" (and 2 to represent "version 3", current and most common one.) That's what this enum remind me of.

  • Object delete. (unregistered)

    Noone mentioned the type name yet. Why is it AddressPointerTable, hinting at an array or map, when it's an enum? Probably AddressPointerTableIndex describes better what it's for.

  • Oliver Jones (google)

    I'm too old and it's time to retire. Back when FORTRAN IV ruled the forest, there was a compiler that didn't catch the assignment statement "1=2". Guess what that statement did?

    Hint: it was rough on statements like DO 100 J=1,10

  • (nodebb) in reply to Watson

    1, legacy database where the integer column has certain values which you have to mimic in code. 2, enums are typically serialized using their names, but one can imagine a situation when a the consumer of serialized data expects integers. 3, you may want to leave room for inserting values between existing ones then you can specify backing integer values with gaps

  • (nodebb) in reply to Oliver Jones

    I know a fellow who was and is a skilled coder, but he loved to name his variables (in C) and his files numerically. There was a lot of " fp = fopen(33,'r') " and other hilarity. You had to get used to it.

  • (nodebb) in reply to Mr. TA

    enums are typically serialized using their names

    Very much not always! Once you start dealing with binary protocols, those enums will end up serialized as integers of various widths. Hopefully nothing other than 8, 16 or 32 bits wide (with 64 as an outside contender for when four billion enum values aren't enough).

  • (nodebb) in reply to dkf

    Agree, binary is a whole different ballgame. I was referring to text serialization formats. However even when serializing to a text format, integers are sometimes preferred/needed.

  • Barf4Eva (unregistered)

    One possibility could be that this is backed by a lookup table in a database with an ID column and a Description column, for which 0 == Default, and 1 == Two. Perhaps they set the ID as Identity to seed at 0? Maybe some company policy to seed at 0 and always include some sort of incrementing ident col? And then, they wanted to support this mapping to enums, which if using a convention over configuration approach, might result in one mapping to the int/byte/whatever values backing the enum.

    Just a possibility! Not saying that is what actually happened here. :D still funny tho!

  • OlegYch (unregistered)

    this is some php level obliviousness enumerated types have nothing in common with integer constants

  • Haakon (unregistered) in reply to Mr. TA

    Actually, Java enums are just objects. They have an ordinal value, but decent people shouldn't think too much about that.

    They don't have "backing values", they are values.

  • nasch (unregistered)

    "enumerated types have nothing in common with integer constants"

    In C#, they basically are integer constants.

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/enum

  • (nodebb) in reply to Haakon

    These objects can have fields with numbers and or other values set, so in effect, instead of 1 backing value like in C#, you have unlimited number of backing values. Again may or may not be useful, but it's there.

  • jay (unregistered)

    Without seeing how this enum is used, I don't think it's necessarily a problem. When I write an enum, 9 times out of 10 I don't care what the underlying values are. If all he ever does with the enum is pass values around and compare them to each other, it doesn't matter whether Two==2 or Two==1 or Two=8372. The whole point of an enum is that you can use the token as a token without even thinking about the underlying value.

    This is the same insane bug that ASCII "1" = 49 and not 1.

  • Brian (unregistered)

    And this is another reason I like Haskell. Enums are not identifiable with integers unless fromEnum is used.

  • LimaoBam (unregistered)
    Comment held for moderation.
  • LimaoBam (unregistered)

    What is the best method for me?

    I am looking for the best method to be rich.

    This place is correct for This? Limao

  • LimaoBam (unregistered)
    Comment held for moderation.
  • LimaoBam (unregistered)
    Comment held for moderation.
  • LimaoBam (unregistered)

    What is the best method for me?

    I am looking for the best method to be rich.

    This place is correct for This? Limao

  • MixAmady (unregistered)

    https://forum.proxmox.com/members/limaofep.141182/#about

    no minimum deposit casino

  • viperUSalf (unregistered)

    я гадюка. я жив в україні в маріополі зараз живу в польщі. де знайти роботу??? гадюка

  • viperUSalf (unregistered)

    я гадюка. я жив в україні в маріополі зараз живу в польщі. де знайти роботу??? гадюка

  • viperUSalf (unregistered)

    я гадюка. я жив в україні в маріополі зараз живу в польщі. де знайти роботу??? гадюка

  • viperUSalf (unregistered)
    Comment held for moderation.
  • BadSantakcv (unregistered)
    Comment held for moderation.
  • BadSantafrk (unregistered)
    Comment held for moderation.

Leave a comment on “Innumerable Enum”

Log In or post as a guest

Replying to comment #502453:

« Return to Article