Click here to Skip to main content
15,887,596 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: False selection... Pin
PIEBALDconsult11-Oct-10 15:44
mvePIEBALDconsult11-Oct-10 15:44 
GeneralRe: False selection... Pin
ghle12-Oct-10 16:09
ghle12-Oct-10 16:09 
GeneralRe: False selection... Pin
ghle12-Oct-10 16:28
ghle12-Oct-10 16:28 
GeneralRe: False selection... Pin
_Erik_15-Oct-10 5:19
_Erik_15-Oct-10 5:19 
GeneralRe: False selection... Pin
ghle17-Oct-10 14:45
ghle17-Oct-10 14:45 
GeneralRe: False selection... [modified] Pin
_Erik_18-Oct-10 2:06
_Erik_18-Oct-10 2:06 
GeneralRe: False selection... Pin
ghle19-Oct-10 1:36
ghle19-Oct-10 1:36 
GeneralRe: False selection... [modified] Pin
_Erik_19-Oct-10 2:10
_Erik_19-Oct-10 2:10 
The 2 vote was another mistake of mine, sorry for that. I wanted to go to page 2 to see the original post, clicked the vote 2 instead, and forgot to make the correct vote to your post. I've just corrected it with the vote it really deserves, a 5.

I know my final logic does the same as the original but is slower. It is obvious. And it is much clearer, and this is also obvious. The sample I give just before does the same also, and is faster. Both of them improve the original in readability, and the first one also improves it in speed. If you had to manage a team of developers, some of them newcomers with very little experience, tell me, having the original code and the two samples I am giving, which one would you choose?

I would choose the last one, though I know it is slower, but I also know that the overhead is just negligible in this case, becouse this operation will not be used over and over again within de context of a long and complex batch process.

I don't mind to have several "return" in the same method... if it improves readability and/or performance. In the case presented here, it does not improve readablity neither performance, so that is the reason why I consider it a horror. Nobody is obligated to agree, I am just sharing my point of view.

Edit

Sorry again, I was forgetting the las part. The implementation for bitdepth and refreshrate is given just before, but like you wonder how they should be, I will give some extra clues:

return mode1.getWidth() == mode2.getWidth() && mode1.getHeight() == mode2.getHeight() && // This checks sizes
    (mode1.getBitDepth() == mode2.getBitDepth() ||                 // These three lines
    mode1.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI ||          // are checking if 
    mode2.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI)            // bit depths match
    &&
   (mode1.getRefreshRate() == mode2.getRefreshRate() ||            // These three lines
    mode1.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN ||  // are checking if
    mode2.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN);   // refresh rates match


Thank you

modified on Tuesday, October 19, 2010 9:28 AM

GeneralRe: False selection... Pin
AspDotNetDev11-Oct-10 6:38
protectorAspDotNetDev11-Oct-10 6:38 
GeneralRe: False selection... Pin
OriginalGriff11-Oct-10 8:00
mveOriginalGriff11-Oct-10 8:00 
JokeRe: False selection... PinPopular
AspDotNetDev11-Oct-10 9:32
protectorAspDotNetDev11-Oct-10 9:32 
GeneralRe: False selection... Pin
ghle12-Oct-10 15:59
ghle12-Oct-10 15:59 
GeneralRe: False selection... Pin
FSANB15-Oct-10 14:49
FSANB15-Oct-10 14:49 
GeneralRe: False selection... Pin
ghle19-Oct-10 1:41
ghle19-Oct-10 1:41 
GeneralRe: False selection... Pin
Simon Dufour15-Oct-10 8:55
Simon Dufour15-Oct-10 8:55 
GeneralSomething's out of round here PinPopular
PIEBALDconsult9-Oct-10 5:11
mvePIEBALDconsult9-Oct-10 5:11 
GeneralRe: Something's out of round here Pin
oggenok649-Oct-10 10:34
oggenok649-Oct-10 10:34 
GeneralRe: Something's out of round here Pin
Bigdeak10-Oct-10 23:15
Bigdeak10-Oct-10 23:15 
GeneralClever Convert. Really? Pin
Svetlin Panayotov8-Oct-10 3:28
Svetlin Panayotov8-Oct-10 3:28 
GeneralRe: Clever Convert. Really? Pin
GibbleCH8-Oct-10 3:35
GibbleCH8-Oct-10 3:35 
GeneralRe: Clever Convert. Really? Pin
Svetlin Panayotov8-Oct-10 3:54
Svetlin Panayotov8-Oct-10 3:54 
GeneralRe: Clever Convert. Really? Pin
Jörgen Sigvardsson9-Oct-10 21:11
Jörgen Sigvardsson9-Oct-10 21:11 
GeneralRe: Clever Convert. Really? Pin
BillW338-Oct-10 3:48
professionalBillW338-Oct-10 3:48 
GeneralRe: Clever Convert. Really? Pin
Matt Gerrans8-Oct-10 20:16
Matt Gerrans8-Oct-10 20:16 
Generalvb 6, ep. 3 PinPopular
Lutosław7-Oct-10 14:53
Lutosław7-Oct-10 14:53 

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.