Click here to Skip to main content
15,888,461 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: 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 
CDP1802 wrote:
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.


That's definitely true of assigning 0 to a variable. But there's a related case that's problematic:

sqlParams.Add(new SqlParameter("Quantity", 0));

Acutally assigns the "Quantity" parameter a value of null, because apparently this fits the definition for
SqlParameter(string parameterType, SqlDbType dbType)
better than it does for
SqlParamter(string parameterType, object value)
because 0 is a valid value for the enum SqlDbType and any match is a better match than object.

To assign a value of 0, you have to do:
sqlParams.Add(new SqlParameter("Quantity", Convert.ToInt32(0)));
(as for why you would do this... well, I'd rather not go into it...)

So maybe the original coder was confused by that very specific case? ...probably not...
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 
JokeRe: zero int? Pin
Stefan_Lang12-Dec-11 6:18
Stefan_Lang12-Dec-11 6:18 
GeneralRe: zero int? Pin
BobJanova23-Nov-11 5:14
BobJanova23-Nov-11 5:14 
GeneralRe: zero int? Pin
CDP180223-Nov-11 5:17
CDP180223-Nov-11 5:17 
GeneralRe: zero int? Pin
AspDotNetDev23-Nov-11 6:45
protectorAspDotNetDev23-Nov-11 6:45 
GeneralRe: zero int? Pin
harold aptroot23-Nov-11 7:24
harold aptroot23-Nov-11 7:24 
GeneralRe: zero int? Pin
AspDotNetDev23-Nov-11 11:08
protectorAspDotNetDev23-Nov-11 11:08 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 1:51
KP Lee3-Dec-11 1:51 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 2:14
harold aptroot3-Dec-11 2:14 
AnswerRe: zero int? Pin
Nagy Vilmos21-Nov-11 23:52
professionalNagy Vilmos21-Nov-11 23:52 
GeneralRe: zero int? Pin
CDP180221-Nov-11 23:57
CDP180221-Nov-11 23:57 
GeneralRe: zero int? Pin
Nagy Vilmos21-Nov-11 23:58
professionalNagy Vilmos21-Nov-11 23:58 

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.