- 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
No FILE_NOT_FOUND? Son, I am disappoint.
Also, frist-ish.
Admin
public enum Frist {
_INB4 = 'file_not_found'
}
Admin
_2nd. (= 1)
Here's betting that some "developer" had a text editor set to elide all underscores.
Admin
I didn't want to post this comment but you left me know choice.
Admin
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.
Admin
Most ugly code can be fixed, but public enum ugly is forever!
Admin
Admin
I'm not sure how that keeps you from having:
CAPTCHA: haero.. anybody tere?
Admin
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.
Admin
"know choice"
seriously? That's another WTF right there :P
Admin
Admin
me loves enum
Admin
Admin
Admin
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 .
Admin
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.
Admin
Admin
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.
Admin
Enums are meant to be typed constants but then, things like this happen :(
Admin
Seems to me like the owner was being trolled by his own employees.
Admin
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.
Admin
"Being the sensible developer that I am, I emailed the team that we refactor the code."
Is this Alex-speak for "Do the needful"?
Admin
Java has enums :|
Admin
You're knot even joking either, are you?
Admin
Seriously, is there a language feature out there that we haven't seen multiple WTFs about?
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.Admin
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)
Admin
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 }
Admin
You see, you can f*** up enums in Java as well, but much more elegantly than in most other languages.
Admin
Admin
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...
Admin
Winston Churchill references FTW.
Admin
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++.
Admin
Admin
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.
Admin
Right. Because nothing replaces a mechanism for creating closed/fixed sets like two mechanisms for creating open sets.
Admin
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>Admin
Admin
Trisexualism? Fucking queers!
Admin
Admin
Admin
Admin
Admin
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...
Admin
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.)
Admin
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 ;-)
Admin
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.
Admin
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.
Admin
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.
Admin
Admin
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.)