Click here to Skip to main content
15,886,362 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: Stored Procedure Hell Pin
Jörgen Andersson28-Nov-13 12:16
professionalJörgen Andersson28-Nov-13 12:16 
GeneralRe: Stored Procedure Hell Pin
Rob Grainger28-Nov-13 22:19
Rob Grainger28-Nov-13 22:19 
GeneralRe: Stored Procedure Hell Pin
Rob Grainger28-Nov-13 9:41
Rob Grainger28-Nov-13 9:41 
GeneralRe: Stored Procedure Hell Pin
Nicholas Marty28-Nov-13 21:56
professionalNicholas Marty28-Nov-13 21:56 
GeneralConvert.ToInt32 Pin
Silvabolt27-Nov-13 7:29
Silvabolt27-Nov-13 7:29 
GeneralRe: Convert.ToInt32 PinPopular
Ron Beyer27-Nov-13 7:58
professionalRon Beyer27-Nov-13 7:58 
GeneralRe: Convert.ToInt32 Pin
Silvabolt27-Nov-13 8:09
Silvabolt27-Nov-13 8:09 
GeneralRe: Convert.ToInt32 Pin
Ron Beyer27-Nov-13 8:23
professionalRon Beyer27-Nov-13 8:23 
There are even more usage scenarios than that, take for example the following code:

C#
public void SomeDummyMethod(int myNumber)
{
    double myDouble = Convert.ToDouble(myNumber);

    return myDouble * 1000.1f;
}


Now, lets say later down the line you get somebody who says "wait, myNumber needs to be a signed byte!"...

Well now you only have to change one line of code:

C#
public void SomeDummyMethod(SByte myNumber)
{
    double myDouble = Convert.ToDouble(myNumber);

    return myDouble * 1000.1f;
}


Then later somebody comes around and says, "no, it should be a double to begin with"...

C#
public void SomeDummyMethod(double myNumber)
{
    double myDouble = Convert.ToDouble(myNumber);

    return myDouble * 1000.1f;
}


This is an overly simplified case obviously, but imagine if there were 100 or 200 lines of code in the function, if they didn't have Convert.ToDouble(double) the one change at the top would break unknown lines of code below.

Plus, the design strategy for the class was Convert should convert from any numeric type any other numeric type. Oddly enough that also means converting from something back to itself...

On top of all that, it really helps support the IConvertable [^]interface later on, and even says in the documentation:

"The common language runtime typically exposes the IConvertible interface through the Convert class. The common language runtime also uses the IConvertible interface internally, in explicit interface implementations, to simplify the code used to support conversions in the Convert class and basic common language runtime types."

So much more useful than you think Smile | :)
GeneralRe: Convert.ToInt32 Pin
krumia27-Nov-13 17:00
krumia27-Nov-13 17:00 
GeneralRe: Convert.ToInt32 Pin
Ron Beyer27-Nov-13 17:41
professionalRon Beyer27-Nov-13 17:41 
GeneralRe: Convert.ToInt32 Pin
Richard Deeming28-Nov-13 1:11
mveRichard Deeming28-Nov-13 1:11 
GeneralRe: Convert.ToInt32 Pin
OriginalGriff28-Nov-13 3:29
mveOriginalGriff28-Nov-13 3:29 
GeneralRe: Convert.ToInt32 Pin
Lutosław27-Dec-13 0:48
Lutosław27-Dec-13 0:48 
GeneralRe: Convert.ToInt32 Pin
PIEBALDconsult27-Nov-13 13:01
mvePIEBALDconsult27-Nov-13 13:01 
GeneralRe: Convert.ToInt32 Pin
Vasudevan Deepak Kumar29-Nov-13 1:57
Vasudevan Deepak Kumar29-Nov-13 1:57 
GeneralRe: Convert.ToInt32 Pin
Ravi Bhavnani27-Nov-13 8:07
professionalRavi Bhavnani27-Nov-13 8:07 
GeneralRe: Convert.ToInt32 Pin
Lutosław27-Dec-13 0:56
Lutosław27-Dec-13 0:56 
GeneralRe: Convert.ToInt32 Pin
Argonia28-Nov-13 4:17
professionalArgonia28-Nov-13 4:17 
GeneralRe: Convert.ToInt32 Pin
Richard Deeming28-Nov-13 4:23
mveRichard Deeming28-Nov-13 4:23 
GeneralRe: Convert.ToInt32 Pin
Rob Grainger28-Nov-13 10:05
Rob Grainger28-Nov-13 10:05 
GeneralRe: Convert.ToInt32 Pin
robocodeboy2-Dec-13 0:17
robocodeboy2-Dec-13 0:17 
GeneralRe: Convert.ToInt32 Pin
Argonia2-Dec-13 0:48
professionalArgonia2-Dec-13 0:48 
GeneralRe: Convert.ToInt32 Pin
robocodeboy2-Dec-13 1:06
robocodeboy2-Dec-13 1:06 
GeneralRe: Convert.ToInt32 Pin
robocodeboy2-Dec-13 1:10
robocodeboy2-Dec-13 1:10 
GeneralRe: Convert.ToInt32 Pin
Argonia2-Dec-13 1:18
professionalArgonia2-Dec-13 1:18 

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.