Basic tech stuff

Programming and Linux administration

Archive for the ‘funny’ Category

Can you write smarter code?

Posted by Daniel Brahneborg on 2007 February 26

Today the Swedish newspaper Computer Sweden has a job ad with the above headline, and a code snippet:

private int extraRounder(float nr) {
  switch (nr) {
    case Float.parseFloat("4.0"): return 4;
    case Float.parseFloat("4.5"): return 4;
    case Float.parseFloat("5.0"): return 5;
    case Float.parseFloat("5.5"): return 5;
    default: return 0;

First, using an unnecessary switch is a bit stupid, yes.

Second, it doesn’t even work, since the comparisons with floats never will match due to rounding errors. Because of this, practically all programmers in the world can write smarter code than this (but see the next paragraph). Therefore, the requirements on the applicants can’t be very high. Not really a company I’d like to work for.

The thing that made this really painful though, is that there was a person in my class at the university who actually wrote a function like this, but converting from characters to character codes.

Posted in funny, programming | Leave a Comment »