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

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:
2009-08-13

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

RE[6]: Sad Truth
by rr7.num7 on Tue 25th Sep 2012 19:10 in reply to "RE[5]: Sad Truth"
rr7.num7 Member since:
2010-04-30

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.


+1

Also, as others already said, there are simpler ways (even as simple as using unary minus operator) to solve this than using bitwise operations. I think anyone who choses the latter is nothing but a show-off. It might be acceptable in a student, but not in a professional.

Reply Parent Score: 1