Click here to Skip to main content
15,904,652 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.

 
GeneralRe: What should you do if assigning is going to crash your application? PinPopular
CDP180229-Nov-11 21:38
CDP180229-Nov-11 21:38 
GeneralRe: What should you do if assigning is going to crash your application? Pin
Julien Villers29-Nov-11 21:40
professionalJulien Villers29-Nov-11 21:40 
GeneralRe: What should you do if assigning is going to crash your application? Pin
CDP180229-Nov-11 21:42
CDP180229-Nov-11 21:42 
GeneralRe: What should you do if assigning is going to crash your application? Pin
dawmail3331-Dec-11 2:25
dawmail3331-Dec-11 2:25 
GeneralRe: What should you do if assigning is going to crash your application? Pin
CDP18021-Dec-11 3:37
CDP18021-Dec-11 3:37 
GeneralRe: What should you do if assigning is going to crash your application? Pin
Vladimir Svyatski1-Dec-11 6:22
professionalVladimir Svyatski1-Dec-11 6:22 
GeneralRe: What should you do if assigning is going to crash your application? Pin
VallarasuS3-Dec-11 20:24
VallarasuS3-Dec-11 20:24 
GeneralRe: What should you do if assigning is going to crash your application? Pin
YvesDaoust1-Dec-11 2:41
YvesDaoust1-Dec-11 2:41 
GeneralRe: What should you do if assigning is going to crash your application? Pin
BobJanova1-Dec-11 5:25
BobJanova1-Dec-11 5:25 
GeneralRe: What should you do if assigning is going to crash your application? Pin
dawmail3331-Dec-11 14:53
dawmail3331-Dec-11 14:53 
GeneralRe: What should you do if assigning is going to crash your application? Pin
BobJanova2-Dec-11 0:11
BobJanova2-Dec-11 0:11 
GeneralRe: What should you do if assigning is going to crash your application? Pin
TorstenFrings2-Dec-11 0:21
TorstenFrings2-Dec-11 0:21 
GeneralRe: What should you do if assigning is going to crash your application? Pin
KP Lee2-Dec-11 21:44
KP Lee2-Dec-11 21:44 
Rant+1 -1 code patch.... or how to make my brain explode.... PinPopular
Alberto Bar-Noy28-Nov-11 1:12
Alberto Bar-Noy28-Nov-11 1:12 
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
KP Lee2-Dec-11 23:35
KP Lee2-Dec-11 23:35 
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
Alberto Bar-Noy3-Dec-11 0:57
Alberto Bar-Noy3-Dec-11 0:57 
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
KP Lee3-Dec-11 2:16
KP Lee3-Dec-11 2:16 
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
Alberto Bar-Noy3-Dec-11 4:27
Alberto Bar-Noy3-Dec-11 4:27 
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
KP Lee3-Dec-11 2:32
KP Lee3-Dec-11 2:32 
Questionzero int? Pin
b1054374821-Nov-11 12:33
b1054374821-Nov-11 12:33 
AnswerRe: zero int? Pin
CDP180221-Nov-11 23:30
CDP180221-Nov-11 23:30 
The declaration and initialisation could of course have been done in one line, but that makes little difference. From this I get the impression that the developer who wrote this is very 'modern'. He probably has no idea what the compiler will generate from those simple code lines and added the type cast just in case this assignment might be problematic.

Ironically, assingning zero to a variable of a numeric type is the most unproblematic case of all, since it turns out to be one or more zero bytes, no matter if we are looking at an integer type, a floating point type, signed or unsigned. The compiler knows the size (in bytes) of the variable the value is assigned to and there are no special ways to represent the number 'zero'. Therefore no special type information is needed in the assignment.

Bottom line: I see this as clumsy code, but not as a real horror. It does what it is supposed to and I see no potentially harmful side effects. However, I would also see it as an indicator that the developer should perhaps learn more about what happens under the hood, even if that's not 'modern'.
And from the clouds a mighty voice spoke:
"Smile and be happy, for it could come worse!"

And I smiled and was happy
And it came worse.



GeneralRe: zero int? Pin
Nagy Vilmos21-Nov-11 23:50
professionalNagy Vilmos21-Nov-11 23:50 
GeneralRe: zero int? Pin
CDP180221-Nov-11 23:52
CDP180221-Nov-11 23:52 
GeneralRe: zero int? Pin
KP Lee2-Dec-11 23:51
KP Lee2-Dec-11 23:51 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 2:11
harold aptroot3-Dec-11 2:11 

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.