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

 
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 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 3:02
KP Lee3-Dec-11 3:02 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 3:27
harold aptroot3-Dec-11 3:27 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 10:21
KP Lee3-Dec-11 10:21 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 10:42
harold aptroot3-Dec-11 10:42 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 11:06
KP Lee3-Dec-11 11:06 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 11:19
harold aptroot3-Dec-11 11:19 
GeneralRe: zero int? Pin
Chris Berger22-Nov-11 8:46
Chris Berger22-Nov-11 8:46 
GeneralRe: zero int? Pin
greldak23-Nov-11 2:59
greldak23-Nov-11 2:59 
GeneralRe: zero int? Pin
CDP180223-Nov-11 3:03
CDP180223-Nov-11 3:03 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 0:40
KP Lee3-Dec-11 0:40 
GeneralRe: zero int? Pin
harold aptroot23-Nov-11 4:12
harold aptroot23-Nov-11 4:12 
GeneralRe: zero int? Pin
jsc4223-Nov-11 7:44
professionaljsc4223-Nov-11 7:44 
JokeRe: zero int? Pin
harold aptroot23-Nov-11 8:01
harold aptroot23-Nov-11 8:01 

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.