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 536403
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[3]: Sad Truth
by phreck on Tue 25th Sep 2012 12:01 UTC in reply to "RE[2]: Sad Truth"
Member since:

Now you are showing ridiculous behaviour.

You show to your working comrades a young boys code for teh lulz (which is a form of sadism), and then don't even now that abs() is a standard function?

Fellows and Me: "What."

Seriously: If you want a simple and elegant solution:

#include <algorithm>

Edited 2012-09-25 12:09 UTC

Reply Parent Score: 1

RE[4]: Sad Truth
by JeeperMate on Tue 25th Sep 2012 12:45 in reply to "RE[3]: Sad Truth"
JeeperMate Member since:

Phreck, again, the question is essentially "do you have an idea how abs()" is implemented? If you answered "just use abs()," you're screwed.

The point of the question is to test basic programming knowledge and skill (i.e. to answer the question: "can this young man think like a programmer?")

If you don't like that kind of question, you can either avoid programming job interviews, or don't ask them to interviewees.

Edit: when I was in the interviewee's position (a long time ago) I was even asked to write a FizzBuzz code. Now that's ridiculous.

Edited 2012-09-25 12:49 UTC

Reply Parent Score: 1

RE[5]: Sad Truth
by phreck on Tue 25th Sep 2012 12:52 in reply to "RE[4]: Sad Truth"
phreck Member since:

By your original question, this would be correct:

#include <cstdint>
#include <algorithm>

int32_t myAbs(int32_t val) {
return std::abs(val);

This is even more correct than my other solution, because you explicitly mention 32 bit signed integers. The datatype "int" can also be 64 bit, so your solution is not even portable.

And if you would tell me not to use "3rd-party libs" for standard-C++ functions like std::abs(), I would immediately quit the interview under the assumption that your dev-department heavily suffers the NIH-syndrome and missed the last 20 years of C++ standardization.

Reply Parent Score: 2