Pls read other posts, i'm getting tired of getting the same remark over and over again :p
lordofawesome
Posts
-
False selection... -
False selection...Are you talking about the variables code or the 1 statement code? When you are talking about the variables code you are right (but like 9999999... people already stated that, and that solution was but a compromise for greater readability) If you are talking about the 1 statement code you are wrong.
-
False selection...if( analyzer.dimensionsNotEqual() )
result = false;look at what ur writing here... i'm not trying to insult you, but that just seems illogical to me.
analyzer.dimensionsNotEqual()
this method returns a boolean value, this enabling you to simply write:result = analyzer.dimensionsNotEqual();
this was what bothered me the most when i posted the code. The fact that someone tests for a boolean value within a if structure, and then depending on the outcome returns true or false, that seems so strange to me. if the above explanation isn't clear enough i'll explain a bit more below why this is so strange to me. the contents00if(boolean){contents00}else{contents01}
are executed when the boolean value is true. when the boolean is false the contents01 are executed. When the only command within the contents00 or contents01 is a command to put a certain value within a boolean variable, you really are testing for no reason. simply take the boolean value within the if structure, remove the if structure and directly put that value within that variable. I believe when you write stuf likeif(boolean00){boolean immaboolean = boolean00}
it is called 'False selection' not sure how people call it in english though. Hope i'm making my point clear here ;) -
False selection...That sounds reasonable to me. Your knowledge seems impressive. Nevertheless I think it is strange to return a boolean from the result of any if structure. It just seems strange to me. Just one remark on the variable/nonvariable matter. I don't know about C/C++ but in java when you combine boolean expressions using the && operator, automatically when 1 value is false the other expression are skipped. That's why i would assume that it has the same advantage of being able to skip part of the calculations. I would think when using the variables, that advantage would be partially lost because you'd split up the calculations, this enlarging the calculations i'd think. This is just theory i'm not sure of this sorry if i'm not clear i'm having trouble expressing myself in english
-
False selection...i could be saying dumb shit here but would it be faster to not use the variables and simply return the whole thing?
-
False selection...Wow this information is interesting. Thx for the effort. I could be wrong but i can't see the solution with 1 statement anywhere among your tests functions. I presume that using that solution would be even faster.
-
False selection...Check my last reply, 1 statement, no variables, only indenting to preserve readability and my personnal favorite
-
False selection...Ye i like the activity on this forum :D
-
False selection...ty for the clarification it appears that these need to be added to the line also. Though this changes nothing to the structural fail of the code
-
False selection...I think this is a code horror because all this could be done with 1 statement, this is the most performant way to do this AND with proper indenting the readability isn't compromised.
-
False selection...But aren't these simply constants? So the value would still have to be the same right? if so, this would mean that you don't need to take them into account. Or am i missing the point :s
-
False selection...Assuming it really is faster, this method isn't really part of the engine itself. it's not like this function will be run over and over again. Me personally, i wouldn't compromise readability over such a small performance increasement. But i'm severely starting to doubt myself, a lot of people seem to disagree this is a codehorror :s
-
False selection...I believe BIT_DEPTH_MULTI and REFRESH_RATE_UNKNOWN don't need to be there. they are constants. even if they should be there, it still would be a lot cleaner. I'm not saying this IS the best approach i'm just saying how i think is the cleanest solution. Even with 50 things to check it's much more readable using variables then doing some if structures :p
-
False selection...I'd probably go for this approach
/**
Determines if two display modes "match". Two display
modes match if they have the same resolution, bit depth,
and refresh rate. The bit depth is ignored if one of the
modes has a bit depth of DisplayMode.BIT_DEPTH_MULTI.
Likewise, the refresh rate is ignored if one of the
modes has a refresh rate of
DisplayMode.REFRESH_RATE_UNKNOWN.
*/
public boolean displayModesMatch(DisplayMode mode1,
DisplayMode mode2)
{
boolean isEqualDimention = (mode1.getWidth() == mode2.getWidth() && mode1.getHeight() == mode2.getHeight());
boolean isEqualDepth = (mode1.getBitDepth() == mode2.getBitDepth());
boolean isEqualRefreshRate = (mode1.getRefreshRate() == mode2.getRefreshRate());return (isEqualDimention && isEqualDepth && isEqualRefreshRate); }
I think this is much more readable and much simpler.
-
False selection...I believe i understand what you are saying, but i don't think the above solution is a good solution to that problem.
-
False selection...uhum that makes sence, but i'd probably try to simplify the expression using some describing variable names.
-
False selection...The code will work of course, but it should be obvious that the if structures are redundant... simply return the combined value of all the booleans
-
False selection...This is a piece of code i took from a book i read about java game development.
/**
Determines if two display modes "match". Two display
modes match if they have the same resolution, bit depth,
and refresh rate. The bit depth is ignored if one of the
modes has a bit depth of DisplayMode.BIT_DEPTH_MULTI.
Likewise, the refresh rate is ignored if one of the
modes has a refresh rate of
DisplayMode.REFRESH_RATE_UNKNOWN.
*/
public boolean displayModesMatch(DisplayMode mode1,
DisplayMode mode2)
{
if (mode1.getWidth() != mode2.getWidth() ||
mode1.getHeight() != mode2.getHeight())
{
return false;
}if (mode1.getBitDepth() != DisplayMode.BIT\_DEPTH\_MULTI && mode2.getBitDepth() != DisplayMode.BIT\_DEPTH\_MULTI && mode1.getBitDepth() != mode2.getBitDepth()) { return false; } if (mode1.getRefreshRate() != DisplayMode.REFRESH\_RATE\_UNKNOWN && mode2.getRefreshRate() != DisplayMode.REFRESH\_RATE\_UNKNOWN && mode1.getRefreshRate() != mode2.getRefreshRate()) { return false; } return true; }