There is something as to making it too obfuscated. Now you're just creating unreadable code.
Only now? I think both his last posts were an obfuscation, the later simply being worse.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
He asked for an alternative, I provided an alternative. Can you say the same?
To be fair, it wasn't about an unreadable alternative. Everyone can do that.
There. Now I've provided and alternative. It just might not compile on all compilers, but it should be standard.Code:#include <iso646.h> if (gross_income >= 2000 and gross_income <= 4000)
I guess that's closer than mine. Seeing as it is an alternative for the operator, like he really asked for, not an expression that evaluates the same for a specific case(as my examples do). My point was to twist the expression around in a cool way, that happens to solve a particular problem, not to serve a purpose.
A cool alt for (x != x) that I kinda based the second one off of: (x - x)
There should also be #include <iso646.h>, and then this is a debatable alternative in that it is a macro that would be replaced by && anyway.Originally Posted by Elysia
Anyway, I agree that cyberfish probably has the right idea, if we assume a competent instructor. Saying that one provided an alternative is no defense for obfuscated code that misses the point when there has already been a sensible answer.
EDIT:
Start your own contest. We have a contests board, if you were not aware. What you are doing here is basically showing off to a beginner who may be dangerously impressed.Originally Posted by User Name:
Last edited by laserlight; 07-22-2010 at 01:51 PM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
<Stroustrup> macro !!!Code:#include <iso646.h> if (gross_income >= 2000 and gross_income <= 4000)
<Stroustrup> macros are evil(TM)!!!
Whether it's a macro (as in C) or a keyword (as in C++), "and" in code is functionally equivalent to "&&". It might be argued that if you are using one, you are using the other, so changing "&&" to "and" is not a valid response to the question asked.
One solution would be to use the old ternary operator.
is - because of short circuiting that the operators support - functionally equivalent toCode:if ((gross_income >= 2000)? (gross_income <= 4000) : 0)
I personally consider, of the two, the second is more readable.Code:if (gross_income >= 2000 && gross_income <= 4000)