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, embarrasing 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.
|
|
 |

|
While editing a much tweaked process that I wrote, I found this T-SQL:
DECLARE @NumDays INT;
SELECT @NumDays =
CASE
WHEN @Client = 'Client1' THEN @DaysBack
WHEN @Client = 'Client2' THEN @DaysBack
ELSE @DaysBack
END;
This is what happens when you go from actual numbers to a variable, without checking the code.
|
|
|
|

|
yeah you clearly missed the
@DaysBack
is this a signature ?
|
|
|
|

|
I've done something similar to this recently. It was like this:
SELECT CASE
WHEN Field1 = 'Something #1' THEN 'Result #1'
WHEN Field1 = 'Something #2' THEN 'N/A'
WHEN Field1 = 'Something #3' THEN '(Empty)'
ELSE 'N/A'
END
And I continued to wonder why even when 'Something #1' was not met, I was seeing 'N/A' in the results. Took me a bit to figure it out.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|

|
djj55 wrote: What was I thinking
about Client3's perky assets?
|
|
|
|

|
My personal favorite from C#. Someone was testing the value of a boolean variable.
if (someBooleanVariable == true)
return true;
else
return false;
Later they refactored it to this thinking it was an improvement.
return someBooleanVariable == true ? true : false;
|
|
|
|

|
You mean they missed the totally obvious contraction to
return someBooleanVariable ? true : false
They should hang their head in shame!
cheers,
Chris Maunder
The Code Project | Co-founder
Microsoft C++ MVP
|
|
|
|

|
well, it should be just
return someBooleanVariable
|
|
|
|

|
cheers,
Chris Maunder
The Code Project | Co-founder
Microsoft C++ MVP
|
|
|
|

|
It took this long to get this simple return?
|
|
|
|

|
You're not following good form. You should use CONSTANTS for things that like.
return someBooleanVariable ? Boolean.Parse(Boolean.TrueString) : Boolean.Parse(Boolean.FalseString);
|
|
|
|
 |
|
|
General
News
Suggestion
Question
Bug
Answer
Joke
Rant
Admin