Click here to Skip to main content
15,902,842 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: Straight from the horse's mouth Pin
JackDingler14-Feb-12 9:02
JackDingler14-Feb-12 9:02 
GeneralRe: Straight from the horse's mouth Pin
patbob14-Feb-12 11:43
patbob14-Feb-12 11:43 
GeneralRe: Straight from the horse's mouth Pin
KP Lee14-Feb-12 13:54
KP Lee14-Feb-12 13:54 
GeneralRe: Straight from the horse's mouth Pin
K Quinn15-Feb-12 8:10
K Quinn15-Feb-12 8:10 
GeneralRe: Straight from the horse's mouth Pin
mbb0117-Feb-12 2:31
mbb0117-Feb-12 2:31 
GeneralRe: Straight from the horse's mouth Pin
Rob Grainger17-Feb-12 3:43
Rob Grainger17-Feb-12 3:43 
GeneralRe: Straight from the horse's mouth Pin
mbb0117-Feb-12 22:32
mbb0117-Feb-12 22:32 
GeneralDo you want string or string? Pin
BotCar9-Feb-12 21:10
BotCar9-Feb-12 21:10 
OK, by Hall Of Shame standards, this isn't too bad. Still worth sharing...

C#
KeyValuePair<DateTime, string> lastItem;
//Some code...
if (lastItem.Value != null && lastItem.Value.ToString().Trim() != "")
{
//Some more code...


Three things jump out at me:
1. Use of empty string literal instead of String.Empty
2. Seperate testing of null and empty string instead of String.IsNullOrEmpty()
3. Calling ToString() on something that is already a string.

#1 and #2 isn't too serious, especially if you consider that you also want to trim the string, so you need to check for null before trying to trim anyway. #3, on the other hand, confuses me. Why would you want to call ToString() on a string?
GeneralRe: Do you want string or string? Pin
GibbleCH10-Feb-12 3:41
GibbleCH10-Feb-12 3:41 
JokeRe: Do you want string or string? Pin
Chris Meech10-Feb-12 6:33
Chris Meech10-Feb-12 6:33 
GeneralRe: Do you want string or string? Pin
fjdiewornncalwe10-Feb-12 8:12
professionalfjdiewornncalwe10-Feb-12 8:12 
GeneralRe: Do you want string or string? Pin
Julien Villers13-Feb-12 22:07
professionalJulien Villers13-Feb-12 22:07 
GeneralRe: Do you want string or string? Pin
Dan Neely10-Feb-12 12:47
Dan Neely10-Feb-12 12:47 
GeneralRe: Do you want string or string? Pin
V.12-Feb-12 23:38
professionalV.12-Feb-12 23:38 
GeneralRe: Do you want string or string? Pin
OriginalGriff13-Feb-12 0:37
mveOriginalGriff13-Feb-12 0:37 
GeneralRe: Do you want string or string? Pin
CDP180213-Feb-12 2:22
CDP180213-Feb-12 2:22 
GeneralRe: Do you want string or string? Pin
OriginalGriff13-Feb-12 2:36
mveOriginalGriff13-Feb-12 2:36 
GeneralRe: Do you want string or string? Pin
KP Lee14-Feb-12 14:15
KP Lee14-Feb-12 14:15 
GeneralRe: Do you want string or string? Pin
KP Lee14-Feb-12 14:21
KP Lee14-Feb-12 14:21 
GeneralRe: Do you want string or string? Pin
BobJanova13-Feb-12 3:48
BobJanova13-Feb-12 3:48 
GeneralRe: Do you want string or string? Pin
BotCar13-Feb-12 18:56
BotCar13-Feb-12 18:56 
JokeRe: Do you want string or string? Pin
ZurdoDev13-Feb-12 5:53
professionalZurdoDev13-Feb-12 5:53 
JokeRe: Do you want string or string? Pin
BotCar13-Feb-12 19:06
BotCar13-Feb-12 19:06 
GeneralRe: Do you want string or string? Pin
KP Lee14-Feb-12 15:28
KP Lee14-Feb-12 15:28 
GeneralRe: Do you want string or string? Pin
KP Lee14-Feb-12 14:30
KP Lee14-Feb-12 14:30 

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.