|
Well, just hold your phone at 42 degrees .
And also, there were worse f'ups: (Steve Jobs "Don't hold it that way", anyone?) Actually, there were none
|
|
|
|
|
Guess the author is afraid of "AddWithZeroException"
|
|
|
|
|
I a very humble opinion, I think the original developer cared about performance.
There is a big and ugly monster living in or closes that will eat us if we write less performing code.
The problem is, that almost all developers don't understand about performance and do wrong things.
Here, I think he/she are trying to avoid a sum using a comparison. In some cases, like division, it will be a great code.
|
|
|
|
|
For the sake of learning here, why do some of the examples use the abs function in their answers. Why not just i++?
|
|
|
|
|
Rewritten:
return (i == 0) ? 1 : i++;
In division, specifically in the denominator, this code eliminates the divide by zero issue. I think the OP (original programmer) had good intentions.
|
|
|
|
|
Bug Alert. I think you meant perhaps:
return (i == 0) ? 1 : ++i;
|
|
|
|
|
Why not use i++? Obfuscation. The original coder was trying to obfuscate it by using an if statement, so people are running with that theme
We can program with only 1's, but if all you've got are zeros, you've got nothing.
|
|
|
|
|
MehGerbil wrote: Why not just i++? For one thing that would be the same as returning i. (Unless the i was passed with ref. Then you get two values for the price of one.)
MehGerbil wrote: For the sake of learning here That's rich. Trying to learn better coding by studying poor code harder.
|
|
|
|
|
The intent was to write: return i++;
KP Lee wrote: That's rich. Trying to learn better coding by studying poor code harder.
I think fixing bad code is a great way to learn, especially if you learn the "why" along the way.
|
|
|
|
|
It should be 'return i + 1'. ++i is a wasteful update of the variable i, assuming it's local (there's some serious issues if it isn't anyway), and i++ is just wrong because it returns i (before the statement) and not i + 1.
|
|
|
|
|
That was interesting.
Why is it that ++i is less efficient then returning i + 1?
Isn't a calculation made (total of i + 1) made in memory somewhere regardless?
|
|
|
|
|
It's likely that compiler optimisations make it irrelevant in this case. But in the general case, she using ++i the value is copied into i after being calculated, then copied into the return variable. Using i+1 only copies it to the return variable (one less copy).
|
|
|
|
|
Interesting.
Thank you for the informative response.
|
|
|
|
|
I'm not surprised, see it all the time. This happens as a result of changing the condition, i.e. the code was written for one condition, then the condition changed, and the code was updated without logical refactoring.
Also, some developers like making code temporarily unreachable rather than commenting it out, i.e. putting the code into a block like:
if(false){...code...}
|
|
|
|
|
Developer took special math classes...
|
|
|
|
|
Almost 12 years ago (before I joined the company ), this little beauty almost made it into the release build of one of our applications:
CString strTimeZone;
timeb timeptr;
ftime(&timeptr);
long TimeZone = (long)timeptr.timezone/(long)60;
switch(TimeZone)
{
case 8:
strTimeZone = "P";
break;
case 7:
strTimeZone = "M";
break;
case 6:
strTimeZone = "C";
break;
case 5:
strTimeZone = "E";
break;
default:
AfxMessageBox("Invalid TimeZone. Please Move.");
}
Soren Madsen
|
|
|
|
|
It's not a horror - at least he checked - but it's not that helpful an error message, I must admit. However, it does give advice on how to solve the problem which is a vast improvement on most MS error messages of 12 years ago!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
You are a true the-glass-is-half-full guy
Soren Madsen
|
|
|
|
|
I think that serves people right for living in invalid timezones!
I'm glad someone was finally willing to tell them
I'm pretty sure the programmer was thinking of timezones such as GMT+4,35 and GMT-27
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}
|
|
|
|
|
I wanted to share this, so I actually went to find it in our old SourceSafe database. I deleted a few lines of code that really did nothing, so what you see is what it did.
Today in its place, the code formats a date/time with abbreviated time zone and Daylight saving information - getting the TZ abbreviation right is still a hit and miss (when TZ is outside the US), but at least you don't have to move
Soren Madsen
|
|
|
|
|
SoMad wrote: getting the TZ abbreviation right
You mean something like "MST"?
Simple solution then - there is no deterministic way to solve this because there are time zone abbreviations that are the same for different zones. Best one can do is to
- Use a numeric offset
- Require an environment configuration that matches that offset.
|
|
|
|
|
I recall seeing an error message something like
that a while back.
I thought it was rather stupid, given the fact that
I had just clicked on an item in a drop down list.
I think someone was trying to be funny.
ST
|
|
|
|
|
Well i suppose it wasn't meant to be used outside North America, so it may help avoid the use of illegal copies of that program on China.
|
|
|
|
|
Well, he accounted for EST, not EDT, so I assume for most of the year he got an error for east coast users.
|
|
|
|
|