pouët.net

Go to bottom

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."

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?
added on the 2009-01-01 14:44:18 by Calexico Calexico
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.
added on the 2009-01-01 14:49:34 by Adok Adok
Adok: again, this was not an IQ test. This is a true case of Zune software failure.
added on the 2009-01-01 15:02:43 by texel texel
A MS developer surely does NOT make a "six figure income". :) (I'm guessing this is about the Zune incident)
added on the 2009-01-01 15:04:21 by tomaes tomaes
tomaes: Microsoft is the costumer, Freescale Semiconductor wrote it.
link
added on the 2009-01-01 15:21:15 by fr33ke fr33ke
"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.
added on the 2009-01-01 15:28:44 by Gargaj Gargaj
btw, the code "solutions" in that thread are fucking hilarious.
added on the 2009-01-01 15:32:02 by Gargaj Gargaj
will the Freescale Semiconductor programmer who wrote the routine be fired?
added on the 2009-01-01 15:33:21 by Tigrou Tigrou
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
added on the 2009-01-01 15:43:17 by the_Ye-Ti the_Ye-Ti
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.
added on the 2009-01-01 15:48:07 by tomaes tomaes
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. :)
added on the 2009-01-01 15:57:53 by tomaes tomaes
Haha, adok is such a mongoloid :D
added on the 2009-01-01 16:00:05 by okkie okkie
adok got pwn3d bigtime - classic :)
added on the 2009-01-01 16:20:15 by button button
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.
added on the 2009-01-01 16:20:37 by Calexico Calexico
The bug is easy to fix: Replace
Code:while (days > 365)
with
Code:while (days > 366 || (days == 366 && !IsLeapYear(year)))
added on the 2009-01-01 16:29:14 by Adok Adok
The actual fix is to recode that mess. So, maybe, like so:

Code: for ( year = ORIGINYEAR; days >= 0; year++ ) { days -= ( 365 + IsLeapYear(year) ); }


(untested, flame away :D)
added on the 2009-01-01 16:36:57 by tomaes tomaes
The "C way" of fixing it would of course be
Code:while (days > 365 + !!IsLeapYear(year))
;-)
added on the 2009-01-01 16:37:29 by Joghurt Joghurt
tomaes: Your code requires
Code:year--
at the end.
added on the 2009-01-01 16:45:13 by Adok Adok
Code:year--;
of course.
added on the 2009-01-01 16:45:46 by Adok Adok
Or just an additional "-1" behind ORIGINYEAR. :)
added on the 2009-01-01 16:53:48 by tomaes tomaes
Yes.
added on the 2009-01-01 16:55:17 by Adok Adok
tomaes: and your days count won't be valid anymore (although that's easy to fix)
added on the 2009-01-01 16:59:25 by src src
src: True. But I just wanted to calc the years, nothing else.
added on the 2009-01-01 17:06:21 by tomaes tomaes

login

Go to top