- 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
Admin
What a true Nagesh speaks is Hinglish, not Engrish.
When we get a visit from Haruki, we'll see some Engrish.
On the other hand, it's possible that he's a fakir.
Admin
this would be true if we were checking against absolute values, or the order of the enum members was relevant.
Admin
strait copy paste, you idiot!
Admin
This comment shouldn't never happen.
Admin
Storing enums in databases is asking for trouble. You can never extend your enum without upgrading all applications using this db table and row. (Unless, of course, there is just one application accessing this table.) At my place, we now use some kind of "safe enum" which accept any string for deserialization. (Yes, I know, this isn't an enum.) When an unknown string is encountered, we just log a warning and go further as nothing happened.
/J
Admin
That reminds me, I once wrote a library that has classes that kinda work like enums, but can be instantiated based on external values, like those in a database. But I forgot how it works, and I doubt I ever actually used it.
Admin
I personally wouldn't say that, BUT, the more you know, the better you would program. Do it is not a matter of saying "I don't want to know this" or "I am not supposed to know this", but instead "I know a lot about the internals, that makes me even better programmer, that makes the difference sometimes"
Admin
Admin
trust only copy-paste everything else is waist.
Admin
Yes, each programmer needs to break down the code into machine language in their head and then simulate the electrical pulses in their brain.
You mean... everyone doesn't do this?
Admin
"Real programmers set the universal constants at the start such that the universe evolves to contain the disk with the data they want." (http://xkcd.com/378/)
Admin
Garbage collection is simply one way of dealing with the tricky problem of memory management. It doesn't always work, and is very bad in some circumstances.
There are many other ways, for example RAII, reference counting etc.
Java forces you to use a GC to the exclusion of all other possible methods, which is probably part of the reason why a lot of people don't like it.
Dumb pointers as in C require the programmer to handle memory management themselves. In a lot of cases this isn't actually very difficult - it only gets hard when the same piece of data has more than one conceptual 'owner'. It is however quite easy to accidentally lose something like this.
Incidentally, it's practically certain that the program you were complaining about was written in C - which is not a low-level language.
Admin
Yet another case of Stringly-Typed programming.
How to do it : convert anything you access to string, then work your way from there.
Why do it : types are such a hassle. Human-readable is so much better, besides it stops the compiler from complaining.
Oh, and bonus points for the useless if/else/return.
Admin
Admin
why even bother with the method and not just call ordinal directly...?
Admin
You cannot use ordinal because:
Returns the ordinal of this enumeration constant (its position in its enum declaration, where the initial constant is assigned an ordinal of zero). Most programmers will have no use for this method. It is designed for use by sophisticated enum-based data structures, such as EnumSet and EnumMap.
You should instead create enum values with a (private) constructor that takes a number during declaration, and return that with a getter. This way, the returned value is clear, and you can easily add enum values before, after etc. Or, if you don't like keeping that in line with the code using the int, try a hash table enum -> int.
Admin
Unsure if Java Enums are the same as .Net Enums, but .Net Enums are indeed very bad news in all but a few very trivial cases. The primary issue is their lack of ability to be bound to the database, hence lack of flexibility. I'm not saying there's a better fluent approach, just that they do in fact add no real value to an enterprise application.
Admin
If you must persist the status somewhere (usually in a database) you need an integer or a string. The ordinal attribute makes perfect sense in this case. 99% of the enums in our project work this way, and we don't have such horrid implementation.