Click here to Skip to main content
15,888,454 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
JokeRe: Let's just make sure? Pin
Super Lloyd16-Dec-09 10:47
Super Lloyd16-Dec-09 10:47 
GeneralRe: Let's just make sure? Pin
Super Lloyd16-Dec-09 11:57
Super Lloyd16-Dec-09 11:57 
GeneralRe: Let's just make sure? Pin
Member 35753717-Dec-09 5:26
Member 35753717-Dec-09 5:26 
GeneralRe: Let's just make sure? Pin
David Skelly17-Dec-09 22:38
David Skelly17-Dec-09 22:38 
GeneralRe: Let's just make sure? Pin
ericmas00124-Dec-09 6:04
ericmas00124-Dec-09 6:04 
GeneralRe: Let's just make sure? Pin
Timothy Byrd24-Dec-09 8:38
Timothy Byrd24-Dec-09 8:38 
GeneralRe: Let's just make sure? Pin
TobiasP31-Dec-09 1:13
TobiasP31-Dec-09 1:13 
GeneralRe: Let's just make sure? Pin
dojohansen7-Jan-10 22:06
dojohansen7-Jan-10 22:06 
David Skelly wrote:
part of the reason for using enums is to constrain the range of values


It is indeed. But I think C# strikes the right balance; another reason for using enums is that it provides a more readable alternative to hard-coded ints and a more efficient alternative to string literals.

C# does not allow implicit casts to enum values, precisely because it is unsafe. There is no run-time check when explicitly casting because it would introduce significant overhead.

I find it rather too strict if Java as you claim does not allow casting to enum types from integer types. Imagine you have a class with many fields that each have a small predefined set of legal values. We can define enums to represent these sets, use byte as the base value, and store such data in a database using one byte per attribute. Storing the names is extremely inefficient: Each column has to be sized according to the maximum length permitted in the set of values. You'd easily go to 20 characters in many cases, and sometimes more, which depending on encoding will require 20 to 40 bytes of storage space. If you have five such fields, you could end up using 200 bytes instead of 5. And large row size == bad performance. If you can't cast to enum values, you'd have to write switches instead (switch (value) { case 1: return CreditCard.MasterCard; break; ...}) which is pretty boring work!
General\r\n Pin
jofli2-Dec-09 23:20
jofli2-Dec-09 23:20 
GeneralRe: \r\n Pin
Thomas Weller3-Dec-09 3:40
Thomas Weller3-Dec-09 3:40 
GeneralRe: \r\n Pin
Ian Shlasko3-Dec-09 4:14
Ian Shlasko3-Dec-09 4:14 
GeneralRe: \r\n Pin
dan!sh 3-Dec-09 5:02
professional dan!sh 3-Dec-09 5:02 
GeneralRe: \r\n PinPopular
Ian Shlasko3-Dec-09 5:28
Ian Shlasko3-Dec-09 5:28 
GeneralRe: \r\n Pin
PIEBALDconsult3-Dec-09 5:33
mvePIEBALDconsult3-Dec-09 5:33 
GeneralRe: \r\n Pin
Ian Shlasko3-Dec-09 5:43
Ian Shlasko3-Dec-09 5:43 
GeneralRe: \r\n Pin
PIEBALDconsult4-Dec-09 3:41
mvePIEBALDconsult4-Dec-09 3:41 
GeneralRe: \r\n Pin
Ian Shlasko4-Dec-09 4:52
Ian Shlasko4-Dec-09 4:52 
GeneralRe: \r\n Pin
NormDroid7-Dec-09 2:38
professionalNormDroid7-Dec-09 2:38 
GeneralRe: \r\n Pin
dan!sh 3-Dec-09 6:09
professional dan!sh 3-Dec-09 6:09 
GeneralRe: \r\n Pin
OriginalGriff3-Dec-09 6:14
mveOriginalGriff3-Dec-09 6:14 
GeneralRe: \r\n Pin
Ian Shlasko3-Dec-09 6:20
Ian Shlasko3-Dec-09 6:20 
GeneralRe: \r\n Pin
peterchen11-Dec-09 2:48
peterchen11-Dec-09 2:48 
GeneralRe: \r\n Pin
Ian Shlasko11-Dec-09 2:55
Ian Shlasko11-Dec-09 2:55 
GeneralRe: \r\n Pin
Luc Pattyn11-Dec-09 3:57
sitebuilderLuc Pattyn11-Dec-09 3:57 
GeneralRe: \r\n Pin
PIEBALDconsult3-Dec-09 5:28
mvePIEBALDconsult3-Dec-09 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.