5 years of experience but WTF!
-
I was code reviewing one of my team members code change. This is how it was,
void foo(...) { int abc = 0; . . . if(somecondition) { functioncall(...,abc); } else { abc = 1; functioncall(...,abc); } }
the param takes either 0 or 1. what happend to boolean?!? why cant true or false be passed directly to the function? Have you guys ever experienced such absurd codeing from a 5 year experienced guy?
-prakash -- modified at 5:16 Saturday 15th October, 2005
It might very well be that the param was originally intended to contain more values, and was just never changed to bool as the code requirements changed. You would certainly find examples like that in my code and I have a hell of a lot more than 5 years experience. My experience tells me that if the code is working - don't fix it. "Capitalism is the source of all true freedom."
-
It might very well be that the param was originally intended to contain more values, and was just never changed to bool as the code requirements changed. You would certainly find examples like that in my code and I have a hell of a lot more than 5 years experience. My experience tells me that if the code is working - don't fix it. "Capitalism is the source of all true freedom."
-
Mr.Prakash wrote:
you think using a variable was very smart thing to do?
Its cetainly not how I would have done it, but than, a lot of my code turns out not to be the way I would have done it given a more perfect understanding of the ultimate user requirements at the beginning of a project. One of the things that really gets under my skin is when someone looks at some code I wrote months or years before while trying to get an application finished under unrealistic deadlines, and then asks me contemptuously why I did something one way rather than another way. I stopped being a perfectionist decades ago. "Capitalism is the source of all true freedom."
-
I was code reviewing one of my team members code change. This is how it was,
void foo(...) { int abc = 0; . . . if(somecondition) { functioncall(...,abc); } else { abc = 1; functioncall(...,abc); } }
the param takes either 0 or 1. what happend to boolean?!? why cant true or false be passed directly to the function? Have you guys ever experienced such absurd codeing from a 5 year experienced guy?
-prakash -- modified at 5:16 Saturday 15th October, 2005
-
:confused: Doesnt sound like a big deal. A 3 byte savings if you are using C++ I guess. (not even that if it is a really old version of Visual C++) There are no failures.. only extended learning opportunities.
The code untimately goes into mobile phones, so saving 3 bytes is a big deal.
-prakash
-
Mr.Prakash wrote:
you think using a variable was very smart thing to do?
Its cetainly not how I would have done it, but than, a lot of my code turns out not to be the way I would have done it given a more perfect understanding of the ultimate user requirements at the beginning of a project. One of the things that really gets under my skin is when someone looks at some code I wrote months or years before while trying to get an application finished under unrealistic deadlines, and then asks me contemptuously why I did something one way rather than another way. I stopped being a perfectionist decades ago. "Capitalism is the source of all true freedom."
That is why we always tend to do the codereview before the code is checked in so that some obvious mistakes can be caught and corrected before it is a problem in the future.
-prakash
-
The code untimately goes into mobile phones, so saving 3 bytes is a big deal.
-prakash
David Wulf would know but I think modern phones have about 8MB of flash, old ones maybe 256KB-1MB. Elaine :rose: The tigress is here :-D
-
I was code reviewing one of my team members code change. This is how it was,
void foo(...) { int abc = 0; . . . if(somecondition) { functioncall(...,abc); } else { abc = 1; functioncall(...,abc); } }
the param takes either 0 or 1. what happend to boolean?!? why cant true or false be passed directly to the function? Have you guys ever experienced such absurd codeing from a 5 year experienced guy?
-prakash -- modified at 5:16 Saturday 15th October, 2005
Mr.Prakash wrote:
why cant true or false be passed directly to the function?
Careful what you suggest. You'll end up getting code like this:
if (somecondition)
functioncall(true);
else
functioncall(false);Mr.Prakash wrote:
a 5 year experienced guy?
In what, VB? Marc My website Traceract Understanding Simple Data Binding Diary Of A CEO - Preface
-
Mr.Prakash wrote:
why cant true or false be passed directly to the function?
Careful what you suggest. You'll end up getting code like this:
if (somecondition)
functioncall(true);
else
functioncall(false);Mr.Prakash wrote:
a 5 year experienced guy?
In what, VB? Marc My website Traceract Understanding Simple Data Binding Diary Of A CEO - Preface
Marc Clifton wrote:
In what, VB?
C/C++ :sigh:
-prakash
-
Mr.Prakash wrote:
why cant true or false be passed directly to the function?
Careful what you suggest. You'll end up getting code like this:
if (somecondition)
functioncall(true);
else
functioncall(false);Mr.Prakash wrote:
a 5 year experienced guy?
In what, VB? Marc My website Traceract Understanding Simple Data Binding Diary Of A CEO - Preface
Marc Clifton wrote:
Careful what you suggest. You'll end up getting code like this: if (somecondition) functioncall(true);else functioncall(false);
What is wrong in this? or are you sarcastic? w.r.t design of the software, passing true/false was the better way of doing it and He (dev) accepted it and he said that I am a good reviewer.:doh:
-prakash
-
Marc Clifton wrote:
Careful what you suggest. You'll end up getting code like this: if (somecondition) functioncall(true);else functioncall(false);
What is wrong in this? or are you sarcastic? w.r.t design of the software, passing true/false was the better way of doing it and He (dev) accepted it and he said that I am a good reviewer.:doh:
-prakash
Mr.Prakash wrote:
What is wrong in this? or are you sarcastic?
Yes, I was being sarcastic. Because if you're writing:
if (somecondition) functioncall(true);else functioncall(false);
you might as well write:
functioncall(somecondition);
right? Marc My website Traceract Understanding Simple Data Binding Diary Of A CEO - Preface
-
Mr.Prakash wrote:
What is wrong in this? or are you sarcastic?
Yes, I was being sarcastic. Because if you're writing:
if (somecondition) functioncall(true);else functioncall(false);
you might as well write:
functioncall(somecondition);
right? Marc My website Traceract Understanding Simple Data Binding Diary Of A CEO - Preface
Marc Clifton wrote:
you might as well write: functioncall(somecondition);
I had thought of this, but it is not always the preferred way of doing it, In this case the condition was quite complex and so using the if case was better way of doing it for readablity. plus there were other statements in if & else block. :)
-prakash
-
Mr.Prakash wrote:
Have you guys ever experienced such absurd codeing from a 5 year experienced guy?
In my limited corporate experience, No. :^) BTW, the if brace is not matched. Cheers, Vikram.
Google talk: binarybandit
upsdude: when I looked at laurens profile, a couple of gears got stripped in my brain. Michael Martin: Too bad she bats for the other team.
-
I was code reviewing one of my team members code change. This is how it was,
void foo(...) { int abc = 0; . . . if(somecondition) { functioncall(...,abc); } else { abc = 1; functioncall(...,abc); } }
the param takes either 0 or 1. what happend to boolean?!? why cant true or false be passed directly to the function? Have you guys ever experienced such absurd codeing from a 5 year experienced guy?
-prakash -- modified at 5:16 Saturday 15th October, 2005
Mr.Prakash wrote:
void foo(...){ int abc = 0; . . . if(somecondition) { functioncall(...,abc); } else { abc = 1; functioncall(...,abc); }}
Or how about: void foo(...) { . . . if(somecondition) { functioncall(..., 0); } else { functioncall(..., 1); } } or: void foo(...) { . . . functioncall(..., !somecondition); } or use the ?: operator. Mind you, I can write perfectly good crap when I'm in the mood, like: if(somevalue = TRUE) dosomething(); But then we use the PREFAST DDK compiler to catch this. It is interesting though, in this world of auto checking compilers etc how a code review can pull out a load of bugs and innefficiencies. Nunc est bibendum
-
Vikram A Punathambekar wrote:
BTW, the if brace is not matched.
Is it? Looks matched to me??? Nunc est bibendum
It was not. He edited it. Now it is. :) Cheers, Vikram.
http://www.geocities.com/vpunathambekar
Google talk: binarybandit
After all is said and done, much is said and little is done.
-
It was not. He edited it. Now it is. :) Cheers, Vikram.
http://www.geocities.com/vpunathambekar
Google talk: binarybandit
After all is said and done, much is said and little is done.
-
Mr.Prakash wrote:
What is wrong in this? or are you sarcastic?
Yes, I was being sarcastic. Because if you're writing:
if (somecondition) functioncall(true);else functioncall(false);
you might as well write:
functioncall(somecondition);
right? Marc My website Traceract Understanding Simple Data Binding Diary Of A CEO - Preface
I love that one. Each time I see something like
Marc Clifton wrote:
if (somecondition) functioncall(true);else functioncall(false);
or the variation
if(condition)
return true;
else
return false;instead of
return condition;
I am split between laughters and tears :sigh:
The great error of nearly all studies of war has been to consider war as an episode in foreign policies, when it is an act of interior politics - Simone Weil Fold with us! ยค flickr
-
I was code reviewing one of my team members code change. This is how it was,
void foo(...) { int abc = 0; . . . if(somecondition) { functioncall(...,abc); } else { abc = 1; functioncall(...,abc); } }
the param takes either 0 or 1. what happend to boolean?!? why cant true or false be passed directly to the function? Have you guys ever experienced such absurd codeing from a 5 year experienced guy?
-prakash -- modified at 5:16 Saturday 15th October, 2005
If the code is supposed to be portable and compile with any C compiler(note not C++), then the 5 year guy isn't as dumb as you think. Bool does not exist in ANSI C.
-
I was code reviewing one of my team members code change. This is how it was,
void foo(...) { int abc = 0; . . . if(somecondition) { functioncall(...,abc); } else { abc = 1; functioncall(...,abc); } }
the param takes either 0 or 1. what happend to boolean?!? why cant true or false be passed directly to the function? Have you guys ever experienced such absurd codeing from a 5 year experienced guy?
-prakash -- modified at 5:16 Saturday 15th October, 2005
Why were you voted down for this one? Anyone care to explain?
-
Mr.Prakash wrote:
void foo(...){ int abc = 0; . . . if(somecondition) { functioncall(...,abc); } else { abc = 1; functioncall(...,abc); }}
Or how about: void foo(...) { . . . if(somecondition) { functioncall(..., 0); } else { functioncall(..., 1); } } or: void foo(...) { . . . functioncall(..., !somecondition); } or use the ?: operator. Mind you, I can write perfectly good crap when I'm in the mood, like: if(somevalue = TRUE) dosomething(); But then we use the PREFAST DDK compiler to catch this. It is interesting though, in this world of auto checking compilers etc how a code review can pull out a load of bugs and innefficiencies. Nunc est bibendum
you could not actually guess the right answer coz for the right answer there are many other things involved. I just gave a small section to highlight the point of passing the param to the function.
-prakash