Linked by Thom Holwerda on Mon 24th Sep 2012 15:07 UTC, submitted by MOS6510
General Development "I've been programming professionally for about 3 years at this point, and I've noticed some interesting patterns in other programmers I've worked with. One of the key differentiators among programmers is motivation. I'm not referring to an individual's passion to simply be successful in their career, but rather the type of work they want to pursue. The thing they want to do with computers every day, the types of problems they are interested in solving."
Thread beginning with comment 536366
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE: Sad Truth
by Neolander on Tue 25th Sep 2012 06:07 UTC in reply to "Sad Truth"
Neolander
Member since:
2010-03-08

In case anyone is curious, this one liner function gives you the absolute value of some 32-bit integer 'num':

"int myAbs(const int num) { return num < 0 ? (~num) + 1 : num; }"

There is another way: multiply the number by itself and return the square root of the multiplication (which will make it work with real numbers if you replace all instances of 'int' with 'double'). But the above code should suffice, given the requirement explicitly states 'some 32-bit signed integer'.

Computer Engineering/Computer Science graduates who don't understand why or how the above code works have wasted years of life studying a subject they're not even interested in.

Just out of curiosity, would this have been a valid option in your opinion ?

int absolute(const int num) { return (num>=0)?num:-num; }

That would pretty much have been my spontaneous answer to your problem (except with an if ... else structure instead of the trigraph).

Reply Parent Score: 1

RE[2]: Sad Truth
by JeeperMate on Tue 25th Sep 2012 10:30 in reply to "RE: Sad Truth"
JeeperMate Member since:
2010-06-12

Yes, that is an adequate answer.

There are often lots of solutions to every problem, we just have to avoid bad ones. That's what I always want to see from an applicant and team members (i.e. whether he/she can avoid bad solutions).

Reply Parent Score: 1

RE[2]: Sad Truth
by JeeperMate on Tue 25th Sep 2012 11:36 in reply to "RE: Sad Truth"
JeeperMate Member since:
2010-06-12

Addendum:

And btw, both your solution and the solution I wrote in my original post have a bug, which I would've asked about, if he would've come up with something similar to mine or yours. But this follow-up question is only meant to test his mastery, which is not compulsory for the position he was being interviewed for. We don't want to assign maintenance works to someone who really masters his/her field -- such person deserves more challenging tasks.

Reply Parent Score: 1

RE[3]: Sad Truth
by peejay on Tue 25th Sep 2012 18:38 in reply to "RE[2]: Sad Truth"
peejay Member since:
2005-06-29

Addendum: And btw, both your solution and the solution I wrote in my original post have a bug...

The bug is that none of the code is commented. ;)

I'm basing this especially on "Computer Engineering/Computer Science graduates who don't understand why or how the above code works have wasted years of life studying a subject they're not even interested in" which implies that no one else is going to understand even this simple function.

Edited 2012-09-25 18:41 UTC

Reply Parent Score: 2