Originally posted by: Erik
#define SWITCH(a) {char *_p = a; if (0)
Now you can do something like this:
void fn(char *p) {
That seemed like overkill. Let me propose this macro solution:
#define CASE(x) } else if (strcmp(_p, x) == 0) {
#define DEFAULT } else {
#define ENDSWITCH }}
SWITCH(p) {
CASE("Hello") {
SomeFn();
}
DEFAULT
SomeOtherFn();
END_SWITCH
}
Should work. IMO it's a better piece of code than the original one. However, I hardly find the subject worth discussing.
Originally posted by: Peter
Incidentally, I saw the website at www.new-line.de, the job section said "Best people for best work"...
uh, I beg to differ...
So in the interest of obfuscation, I propose the following solution to the statement:
int a = 0;
class Int
operator int() const
private:
Usage:
Please use this class in all your code. By the way, this is pure C++ so you do not need any special environment. And everyone knows that the absence of "special environment" means absolute simplicity. Also, please include the following notice when you use this code:
// I, <state your name>, hereby submit myself to public
I bow before your greatness as my title is not nearly as illustrious.
Sincerely,
Peter
With credentials like "Principal Developer at NEW LINE Software Development GmbH", it's hard to believe that you would propose such a obfusicated solution for an otherwise simple piece of code.
{
public:
Int( )
: theVar(0)
{ }
Int( int var )
: theVar(0)
{ }
Int& operator=( int var )
{ theVar = 0; return *this; }
{ return theVar; }
int theVar;
};
Int a;
a = 0;
// Internet ridicule by usage of this code. Upon usage,
// of this code, may my fingers be torn out by ravenous
// birds so that I must write code using a stick in my
// mouth henceforth.
In-duh-vidual contributor (read, peon) of a Global Fortune 100 company.
Reply
Originally posted by: mol
char * ArrayOfStrings={
...
switch(index){
other construction
"string1",
"string2",
"string3",
"string4",
"string5"
}
index=FindStringInArray(stringToSwitch,ArrayOfStrings);
//this function may be optimalized for special case
//may be you find difference for all case on index 3
//then use switch(stringToSwitch[3]){
case 0:{...}
case 1:{...}
case 2:{...}
case 3:{...}
case 4:{...}
default:{...}//not in array
Originally posted by: Nik Marshall-Blank
Very good as a thought experiment but when somebody comes to maintain this code a year later they'll have to spend time understanding your overly elegant solution.
For maintainability always think and use KISS
KEEP IT SIMPLE STUPID !!!.
Good though - Nik