Exercise 1: Do your friggin job!
category: general [glöplog]
You are an overpaid software developer in America. Due to your six figure income your credit rating is excellent and allows you to finance a McMansion in suburbia which you can not really afford. After you arrived at work in your 10mpg SUV this morning, your boss presented you with the task for today. "Please review the code below and fix any potential bugs. The library has to be shipped to an important customer by tomorrow."
Here are the questions:
-Which company do you work at?
-Who is the customer?
-What could be potential consequences of a bug in this routine?
Code:
year = ORIGINYEAR;
while (days > 365)
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
}
}
else
{
days -= 365;
year += 1;
}
}
Here are the questions:
-Which company do you work at?
-Who is the customer?
-What could be potential consequences of a bug in this routine?
The program calculates the year that will be in the given number of days. It's trivial. Your story is most probably untrue because a company that sells such software will not generate much revenue and thus won't be able to pay its employees much. There is no customer, as nobody needs such a program. The potential consequences of a bug in this routine are therefore none.
Adok: again, this was not an IQ test. This is a true case of Zune software failure.
A MS developer surely does NOT make a "six figure income". :) (I'm guessing this is about the Zune incident)
tomaes: Microsoft is the costumer, Freescale Semiconductor wrote it.
link
link
"incident", heh.
my iPod hangs up if it loops a 30 second track for more than an hour, needs a reboot every second time it's connected to a computer, and album covers conspicuously turn black every now and then.
my iPod hangs up if it loops a 30 second track for more than an hour, needs a reboot every second time it's connected to a computer, and album covers conspicuously turn black every now and then.
btw, the code "solutions" in that thread are fucking hilarious.
will the Freescale Semiconductor programmer who wrote the routine be fired?
if it were an iq test, adok just failed.. wave your mensa membership goodbye, my son!
well, it only hangs on day 366 of a leapyear, i dont see any problem in that
just let the battery die whist it crashed, reload it and then turn it back on, that should fix the problem.. :)
fr33ke: And how does that contradict my statement? ;) Anyway, point taken. Also, the whole way of retriving the date is messed up, fixed code or not.
Quote:
btw, the code "solutions" in that thread are fucking hilarious.
At least the first 3 that posted code didn't understand what the problem was. Thedailywtf.com will have a field day. :)
Haha, adok is such a mongoloid :D
adok got pwn3d bigtime - classic :)
Adok: You failed to notice the bug in the routine.
Tomaes: For a good embedded developer in the US, a six figure salary should not be out of reach. Actually the average EE salary is already close to $100K
This whole thing is hilarious. I bet we are going to see a zillion articles about the shortcomings of C, bad software development practices and microsoft bashing during the next days. This will be a textbook example.
Tomaes: For a good embedded developer in the US, a six figure salary should not be out of reach. Actually the average EE salary is already close to $100K
This whole thing is hilarious. I bet we are going to see a zillion articles about the shortcomings of C, bad software development practices and microsoft bashing during the next days. This will be a textbook example.
The bug is easy to fix: Replace
Code:
with while (days > 365)
Code:
while (days > 366 || (days == 366 && !IsLeapYear(year)))
The actual fix is to recode that mess. So, maybe, like so:
(untested, flame away :D)
Code:
for ( year = ORIGINYEAR; days >= 0; year++ )
{
days -= ( 365 + IsLeapYear(year) );
}
(untested, flame away :D)
The "C way" of fixing it would of course be
Code:
;-)while (days > 365 + !!IsLeapYear(year))
tomaes: Your code requires
Code:
at the end.year--
Code:
of course.year--;
Or just an additional "-1" behind ORIGINYEAR. :)
Yes.
tomaes: and your days count won't be valid anymore (although that's easy to fix)
src: True. But I just wanted to calc the years, nothing else.