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

 
GeneralSimple yet entertaining Pin
Steven M Hunt5-Nov-09 5:27
Steven M Hunt5-Nov-09 5:27 
GeneralRe: Simple yet entertaining Pin
Jeremy Tierman5-Nov-09 5:47
Jeremy Tierman5-Nov-09 5:47 
GeneralRe: Simple yet entertaining Pin
wout de zeeuw25-Nov-09 8:32
wout de zeeuw25-Nov-09 8:32 
GeneralRe: Simple yet entertaining Pin
Shameel26-Nov-09 23:18
professionalShameel26-Nov-09 23:18 
GeneralRe: Simple yet entertaining Pin
wout de zeeuw26-Nov-09 23:21
wout de zeeuw26-Nov-09 23:21 
GeneralRe: Simple yet entertaining Pin
Shameel27-Nov-09 5:29
professionalShameel27-Nov-09 5:29 
GeneralRe: Simple yet entertaining Pin
wout de zeeuw27-Nov-09 5:47
wout de zeeuw27-Nov-09 5:47 
Generalwhere's waldo? Pin
Wes Jones4-Nov-09 14:26
Wes Jones4-Nov-09 14:26 
GeneralRe: where's waldo? Pin
Jeroen De Dauw4-Nov-09 21:06
Jeroen De Dauw4-Nov-09 21:06 
GeneralRe: where's waldo? Pin
David Skelly4-Nov-09 22:43
David Skelly4-Nov-09 22:43 
General4GL horror Pin
Andrew Carrell2-Nov-09 10:09
Andrew Carrell2-Nov-09 10:09 
GeneralAm I missing Something? Pin
outside cosmic31-Oct-09 22:08
outside cosmic31-Oct-09 22:08 
GeneralRe: Am I missing Something? Pin
OriginalGriff31-Oct-09 22:13
mveOriginalGriff31-Oct-09 22:13 
GeneralRe: Am I missing Something? Pin
outside cosmic31-Oct-09 22:24
outside cosmic31-Oct-09 22:24 
GeneralRe: Am I missing Something? Pin
OriginalGriff31-Oct-09 22:40
mveOriginalGriff31-Oct-09 22:40 
GeneralRe: Am I missing Something? Pin
outside cosmic31-Oct-09 22:54
outside cosmic31-Oct-09 22:54 
GeneralRe: Am I missing Something? Pin
Nagy Vilmos2-Nov-09 4:02
professionalNagy Vilmos2-Nov-09 4:02 
GeneralRe: Am I missing Something? Pin
PIEBALDconsult1-Nov-09 6:02
mvePIEBALDconsult1-Nov-09 6:02 
GeneralRe: Am I missing Something? Pin
Diego.Martinez1-Nov-09 21:53
Diego.Martinez1-Nov-09 21:53 
GeneralRe: Am I missing Something? Pin
Steven Kirk25-Nov-09 8:44
Steven Kirk25-Nov-09 8:44 
GeneralRe: Am I missing Something? Pin
Keith Barrow2-Nov-09 4:15
professionalKeith Barrow2-Nov-09 4:15 
GeneralRe: Am I missing Something? Pin
0x3c02-Nov-09 4:33
0x3c02-Nov-09 4:33 
GeneralRe: Am I missing Something? Pin
Keith Barrow2-Nov-09 4:58
professionalKeith Barrow2-Nov-09 4:58 
GeneralRe: Am I missing Something? Pin
0x3c02-Nov-09 8:21
0x3c02-Nov-09 8:21 
GeneralRe: Am I missing Something? Pin
Keith Barrow2-Nov-09 9:54
professionalKeith Barrow2-Nov-09 9:54 
I just made a throw-away observation that perhaps the orginal coder meant to perform some form of null checking and got it wrong (possibly by deleting it), then the error was repeated copied and pasted.

Personally I work hard to eradicate the nulls in the first place. I tend to check parameters for null when they are passed. Becuase I want code where nulls are the driven out, I beleive in handling null reference exceptions (such as the one that would occur on <string>string.length) as exceptions as a null value is an unexpected value (ie indicates a bug). Or at least I attempt this Smile | :) !

That said, if I had to, I'd wrap the <string>string.length as per my method. This has a few of benefits: developers don't have to worry about a special -1 value; No extra code is needed to handle the -1 value (null reference exceptions will, as described above) indicate a true bug ; the result can be displayed in a UI directly as end users would assume the -1 is a bug.

CCC solved so far: 2 (including a Hard One!)

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.