Click here to Skip to main content
15,867,308 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.

 
GeneralGreat implementation Pin
cansino6-Jul-12 2:53
cansino6-Jul-12 2:53 
GeneralRe: Great implementation Pin
Bernhard Hiller6-Jul-12 4:27
Bernhard Hiller6-Jul-12 4:27 
GeneralRe: Great implementation Pin
PIEBALDconsult6-Jul-12 5:40
mvePIEBALDconsult6-Jul-12 5:40 
GeneralRe: Great implementation Pin
cansino8-Jul-12 21:19
cansino8-Jul-12 21:19 
GeneralRe: Great implementation Pin
OriginalGriff8-Jul-12 21:46
mveOriginalGriff8-Jul-12 21:46 
GeneralRe: Great implementation Pin
Henning Dieterichs9-Jul-12 5:45
Henning Dieterichs9-Jul-12 5:45 
JokeToString() and ToUpper() are like, so cool! Pin
Nathan D Cook5-Jul-12 9:27
Nathan D Cook5-Jul-12 9:27 
GeneralRe: ToString() and ToUpper() are like, so cool! Pin
CDP18025-Jul-12 10:17
CDP18025-Jul-12 10:17 
Nathan D Cook wrote:
 
First, why check for null every time and a ToString().ToUpper() every
time? Why not just check it once and set a string that we can check? Confused | :confused:

Absolutely correct. That kind of code comes from people who have no idea what the compiler will be able to make out of this. String operations do not translate to single machine instructions. They usually are loops that go through an array of characters. Only nested loops can slow down the processor even more than having to go through one loop after another. So avoid string operations if you can do the job another way (like using an enum for example) and otherwise try to use them as sparingly as possible.

Nathan D Cook wrote:
Third, in the VoidPayment function why are we doing yet another ToUpper when we
know we are passing in either a capitalized PAID or ADJUSTED string? VoidPayment
is only called from those two spots, and it's not really a function that should
be called elsewhere or added anywhere else later.
Here we have a tough choice. You are right, checking and adjusting the string may be redundant here. We might get away with doing it your way. For now. In a year another programmer may have to work on this code and may not know about your assumption that the parameter has already been checked and adjusted. If he calls the function without making sure of that precondition, he will introduce a bug without knowing it.

The whole mess could be avoided if you could use a more suitable datatype. One that's not nullable and can be tested cheaply. An enumeration.
At least artificial intelligence already is superior to natural stupidity




modified 5-Jul-12 17:38pm.

GeneralRe: ToString() and ToUpper() are like, so cool! Pin
OriginalGriff5-Jul-12 21:03
mveOriginalGriff5-Jul-12 21:03 
GeneralRe: ToString() and ToUpper() are like, so cool! Pin
Gary R. Wheeler6-Jul-12 1:47
Gary R. Wheeler6-Jul-12 1:47 
GeneralRe: ToString() and ToUpper() are like, so cool! Pin
OriginalGriff6-Jul-12 2:47
mveOriginalGriff6-Jul-12 2:47 
GeneralRe: ToString() and ToUpper() are like, so cool! Pin
Gary R. Wheeler6-Jul-12 3:16
Gary R. Wheeler6-Jul-12 3:16 
GeneralRe: ToString() and ToUpper() are like, so cool! Pin
TNCaver10-Jul-12 5:35
TNCaver10-Jul-12 5:35 
GeneralRe: ToString() and ToUpper() are like, so cool! Pin
V.6-Jul-12 1:53
professionalV.6-Jul-12 1:53 
GeneralRe: ToString() and ToUpper() are like, so cool! Pin
Nagy Vilmos6-Jul-12 2:21
professionalNagy Vilmos6-Jul-12 2:21 
GeneralRe: ToString() and ToUpper() are like, so cool! Pin
PIEBALDconsult6-Jul-12 3:48
mvePIEBALDconsult6-Jul-12 3:48 
Generalgot another codebase to work on... its full of surprises!!! Pin
Ankush Bansal4-Jul-12 23:45
Ankush Bansal4-Jul-12 23:45 
GeneralRe: got another codebase to work on... its full of surprises!!! Pin
OriginalGriff5-Jul-12 1:10
mveOriginalGriff5-Jul-12 1:10 
GeneralRe: got another codebase to work on... its full of surprises!!! Pin
Ankush Bansal5-Jul-12 3:28
Ankush Bansal5-Jul-12 3:28 
GeneralRe: got another codebase to work on... its full of surprises!!! Pin
Ankush Bansal5-Jul-12 3:38
Ankush Bansal5-Jul-12 3:38 
GeneralRe: got another codebase to work on... its full of surprises!!! Pin
Bernhard Hiller5-Jul-12 3:39
Bernhard Hiller5-Jul-12 3:39 
GeneralRe: got another codebase to work on... its full of surprises!!! Pin
Ankush Bansal5-Jul-12 3:41
Ankush Bansal5-Jul-12 3:41 
GeneralRe: got another codebase to work on... its full of surprises!!! Pin
Sentenryu5-Jul-12 3:46
Sentenryu5-Jul-12 3:46 
GeneralRe: got another codebase to work on... its full of surprises!!! Pin
RobCroll5-Jul-12 13:57
RobCroll5-Jul-12 13:57 
GeneralRe: got another codebase to work on... its full of surprises!!! Pin
Sentenryu6-Jul-12 0:40
Sentenryu6-Jul-12 0:40 

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.