- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
...Or explicitly set Two = 2;
Admin
Or, use a better name than
Two
.Admin
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 ...
Admin
..Or not compare enum with an integer.
Admin
Second!
Admin
The numeric value becomes important in the context of database storage and serialization.
Admin
Or use Java and laugh at those poor languages that force enums to be equal to numbers
Admin
Come a little bit closer, baby Get it on, get it on 'Cause tonight is the night when two become one
Admin
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 :-(
Admin
No, "Two" is not meant to represent the number 2. It is a three letter word, it means "The Wtfy Object".
Admin
Yea because being able to predictably serialize out enums as a simple integer is terrible.
Admin
Could be worse, the tendency is to define enum boolean = ( true, false ); which is of course exactly backwards to convention.
Admin
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?
Admin
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.
Admin
We need to have a WTF Olympics!!!!
Admin
My 2018 new year's resolution is to stop making off-by-one errors! (stolen from somewhere else online).
Admin
Obviously that’s because the frist case is missing.
Admin
TRWTF is the lack of a File_Not_Found enum constant
Admin
:D That's great!
Admin
That's a good tune.
Admin
Other languages don't need a full machine word to represent an enum with 4 choices.
Admin
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?
Admin
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.
Admin
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.
Admin
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
Admin
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
Admin
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.
Admin
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).
Admin
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.
Admin
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!
Admin
this is some php level obliviousness enumerated types have nothing in common with integer constants
Admin
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.
Admin
"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
Admin
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.
Admin
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.
Admin
And this is another reason I like Haskell. Enums are not identifiable with integers unless fromEnum is used.
Admin
What is the best method for me?
I am looking for the best method to be rich.
This place is correct for This? Limao
Admin
What is the best method for me?
I am looking for the best method to be rich.
This place is correct for This? Limao
Admin
https://forum.proxmox.com/members/limaofep.141182/#about
no minimum deposit casino
Admin
я гадюка. я жив в україні в маріополі зараз живу в польщі. де знайти роботу??? гадюка
Admin
я гадюка. я жив в україні в маріополі зараз живу в польщі. де знайти роботу??? гадюка
Admin
я гадюка. я жив в україні в маріополі зараз живу в польщі. де знайти роботу??? гадюка