Click here to Skip to main content
15,887,027 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
David Skelly11-Oct-10 1:53
David Skelly11-Oct-10 1:53 
GeneralRe: False selection... Pin
lordofawesome11-Oct-10 4:28
lordofawesome11-Oct-10 4:28 
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 
Yes, you're right. I think I misunderstood the initial post. I thought it should return false if one of the modes was BIT_DEPTH_MULT or REFRESH_RATE_UNKNOWN. Instead, what I understand now is that bit depth matches if both are equal or one of them is BIT_DEPTH_MULTI, and refresh rate matches if both are equal or one of them is REFRESH_RATE_UNKNOWN. Am I right? I am sure you agree that looking at the original code does not help too much to figure out what it has to do, and that is exactly what we all are talking about here:

return mode1.getWidth() == mode2.getWidth() && mode1.getHeight() == mode2.getHeight() &&
    (mode1.getBitDepth() == mode2.getBitDepth() ||    
    mode1.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI ||   
    mode2.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) 
    &&    
    (mode1.getRefreshRate() == mode2.getRefreshRate() ||
    mode1.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN ||
    mode2.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN);    


I think this would be much more readable, even without any comment explaining what it has to do.

Edit

That said, I think it would be still better to split this into three methods (sizeMatch, bitDepthMatch, refreshRateMatch), so displayModesMatch would still become much easier to read.

return sizeMatch(mode1, mode2) && bitDepthMatch(mode1, mode2) && refreshRateMatch(mode1, mode2);


You see, there are many ways to get the same result, and I think the given example here in the first post is a coding horror becouse it is one of the worst approaches.

See you.

modified on Monday, October 18, 2010 9:41 AM

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 
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? PinPopular
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 

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.