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.

 
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!)

GeneralRe: Am I missing Something? Pin
PIEBALDconsult2-Nov-09 17:29
mvePIEBALDconsult2-Nov-09 17:29 
GeneralRe: Am I missing Something? Pin
Jorg DD1-Dec-09 22:03
Jorg DD1-Dec-09 22:03 
GeneralA new way to create a DateTime from the year! Pin
sergiogarcianinja30-Oct-09 7:48
sergiogarcianinja30-Oct-09 7:48 
GeneralRe: A new way to create a DateTime from the year! Pin
Jaime Olivares31-Oct-09 19:12
Jaime Olivares31-Oct-09 19:12 
GeneralRe: A new way to create a DateTime from the year! Pin
sergiogarcianinja5-Nov-09 5:41
sergiogarcianinja5-Nov-09 5:41 
GeneralRe: A new way to create a DateTime from the year! Pin
Chris Maunder5-Nov-09 5:20
cofounderChris Maunder5-Nov-09 5:20 
GeneralRe: A new way to create a DateTime from the year! Pin
dojohansen7-Jan-10 22:51
dojohansen7-Jan-10 22:51 
GeneralRe: A new way to create a DateTime from the year! Pin
David Skelly5-Nov-09 5:34
David Skelly5-Nov-09 5:34 
GeneralRe: A new way to create a DateTime from the year! Pin
sergiogarcianinja5-Nov-09 5:39
sergiogarcianinja5-Nov-09 5:39 
GeneralRe: A new way to create a DateTime from the year! Pin
David Skelly5-Nov-09 23:19
David Skelly5-Nov-09 23:19 
GeneralHow to test equality PinPopular
nathan.northcutt@gmail.com28-Oct-09 10:50
nathan.northcutt@gmail.com28-Oct-09 10:50 
GeneralRe: How to test equality Pin
Richard MacCutchan28-Oct-09 11:24
mveRichard MacCutchan28-Oct-09 11:24 
GeneralRe: How to test equality Pin
StM0n28-Oct-09 22:18
StM0n28-Oct-09 22:18 
GeneralRe: How to test equality Pin
Shameel26-Nov-09 20:03
professionalShameel26-Nov-09 20:03 
GeneralRe: How to test equality Pin
Jaime Olivares31-Oct-09 19:20
Jaime Olivares31-Oct-09 19:20 
GeneralRe: How to test equality Pin
dojohansen7-Jan-10 23:16
dojohansen7-Jan-10 23:16 
JokeRe: How to test equality Pin
Jeroen De Dauw28-Oct-09 11:44
Jeroen De Dauw28-Oct-09 11:44 

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.