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

Question no. 1:
Really? we encounter ternary operator on a day-to-day basis. It's very common here. That snippet in my original post is just an example, for the sake of brevity.

Question No. 3:
This is already answered in one of my earlier replies. To put it another way, my question to the applicant was essentially "could you write an example of abs() implementation for me?".

As for No. 4:
Very few people forget such basic operation. Most fresh (or semi-fresh) grads still remember. And it's not a matter of optimization whatsoever. Again, that's just an example. It doesn't mean I would frown at solutions different from mine. I just don't like bad solutions.

Even the solution I wrote in my original post has a bug, which I would've asked about, if he would've come up with something similar. But this follow-up question is only meant to test his mastery, which is not compulsory for the position he was being interviewed for.

Question No. 5:
Given such solution, I would ask the applicant about overflows, but again, this is a test of mastery and is not compulsory for the position in question, but a test that must be performed nonetheless.


1. Yes really, I find that ternary operator out of place in your example. But as I said in another discussion, it is a matter of personal preference, and as such hardly worth a long discussion.

3. When you put it like that, it is a whole another story. In normal C++ code, one would use abs(num) and be done with it. But the way I read your posts here, it sounds like you think (or have thought) that abs is some sort of non standard, third library, hack. Another strange thing I noticed in some of your posts, was criticizing use of Google. What is the problem with that? Google is a great tool to find quick and simple solutions for small problems. In fact, Google will more likely that not (in my experience), point to the standard (most typical) way.

4. Still it is relatively complex and unintuitive binary hack and if I was mentoring you, I'd point that function as something that needs to be simplified. You say that you don't like bad solution, and converting to string for testing of presence of minus sign is certainly a bad solution, but I would argue that your implementation is also a bad solution just to a lesser degree. And the second solution you offered is bad in both performance and correctness as it covers only numbers up to 2**16 (for 32 bit integers).

And what bug are you talking about? Passing in unsigned int?

5. Fair enough.

The thing is, your original post made a lot of sense until you wrote your own code. You have obviously interviewed a newbie, and his mistakes were naive, even funny, but then you offered something from the same neighborhood. That is what I was aiming at.

BR
Loreia

Reply Parent Score: 1