Click here to Skip to main content
15,887,585 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: Ultimate Database Fail Pin
AspDotNetDev3-Mar-11 12:02
protectorAspDotNetDev3-Mar-11 12:02 
GeneralRe: Ultimate Database Fail Pin
Andy Brummer3-Mar-11 12:22
sitebuilderAndy Brummer3-Mar-11 12:22 
GeneralRe: Ultimate Database Fail Pin
AspDotNetDev3-Mar-11 12:51
protectorAspDotNetDev3-Mar-11 12:51 
GeneralRe: Ultimate Database Fail Pin
wizardzz3-Mar-11 11:55
wizardzz3-Mar-11 11:55 
GeneralRe: Ultimate Database Fail Pin
AspDotNetDev3-Mar-11 12:09
protectorAspDotNetDev3-Mar-11 12:09 
GeneralRe: Ultimate Database Fail Pin
Andy Brummer3-Mar-11 12:32
sitebuilderAndy Brummer3-Mar-11 12:32 
GeneralRe: Ultimate Database Fail Pin
wizardzz22-Mar-11 4:35
wizardzz22-Mar-11 4:35 
GeneralStrings: the perfect way to compare numbers. Pin
OriginalGriff27-Feb-11 23:30
mveOriginalGriff27-Feb-11 23:30 
I'm not saying exactly where this came from (to protect the guilty), but it was a question on this very site. (I have also changed the field and variable names)

A code fragment you may appreciate:
float result = 0F;
SqlCommand cmd = new SqlCommand("Select SUM(myField) From myTable Where myOtherField = 'Value'", con);
if (cmd.ExecuteScalar().ToString() != "0" && cmd.ExecuteScalar().ToString() != "") 
   result= float.Parse(cmd.ExecuteScalar().ToString().Trim());

Three lines of code; How many don't-do-its can you spot?
Two extra database accesses
Three unnecessary int-to-string conversions
One unnecessary Trim operation (with the output guaranteed to equal the input)
One unnecessary Parse operation
Six unnecessary string creations

Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

GeneralRe: Strings: the perfect way to compare numbers. Pin
fjdiewornncalwe28-Feb-11 3:25
professionalfjdiewornncalwe28-Feb-11 3:25 
GeneralRe: Strings: the perfect way to compare numbers. Pin
OriginalGriff28-Feb-11 3:30
mveOriginalGriff28-Feb-11 3:30 
GeneralRe: Strings: the perfect way to compare numbers. Pin
fjdiewornncalwe28-Feb-11 8:08
professionalfjdiewornncalwe28-Feb-11 8:08 
GeneralRe: Strings: the perfect way to compare numbers. Pin
OriginalGriff28-Feb-11 8:32
mveOriginalGriff28-Feb-11 8:32 
GeneralRe: Strings: the perfect way to compare numbers. [modified] Pin
musefan1-Mar-11 0:49
musefan1-Mar-11 0:49 
GeneralRe: Strings: the perfect way to compare numbers. Pin
GibbleCH1-Mar-11 4:13
GibbleCH1-Mar-11 4:13 
GeneralRe: Strings: the perfect way to compare numbers. [modified] Pin
musefan1-Mar-11 4:46
musefan1-Mar-11 4:46 
GeneralRe: Strings: the perfect way to compare numbers. Pin
GibbleCH1-Mar-11 5:56
GibbleCH1-Mar-11 5:56 
GeneralRe: Strings: the perfect way to compare numbers. Pin
musefan1-Mar-11 6:17
musefan1-Mar-11 6:17 
GeneralRe: Strings: the perfect way to compare numbers. Pin
_Erik_2-Mar-11 0:27
_Erik_2-Mar-11 0:27 
GeneralRe: Strings: the perfect way to compare numbers. Pin
musefan2-Mar-11 0:44
musefan2-Mar-11 0:44 
GeneralRe: Strings: the perfect way to compare numbers. Pin
_Erik_2-Mar-11 1:00
_Erik_2-Mar-11 1:00 
GeneralRe: Strings: the perfect way to compare numbers. [modified] Pin
_Erik_2-Mar-11 0:00
_Erik_2-Mar-11 0:00 
GeneralRe: Strings: the perfect way to compare numbers. Pin
musefan2-Mar-11 0:30
musefan2-Mar-11 0:30 
GeneralRe: Strings: the perfect way to compare numbers. Pin
_Erik_2-Mar-11 0:48
_Erik_2-Mar-11 0:48 
GeneralRe: Strings: the perfect way to compare numbers. Pin
musefan2-Mar-11 1:24
musefan2-Mar-11 1:24 
GeneralRe: Strings: the perfect way to compare numbers. Pin
_Erik_2-Mar-11 1:41
_Erik_2-Mar-11 1:41 

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.