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 536384
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE: Sad Truth
by phreck on Tue 25th Sep 2012 08:39 UTC in reply to "Sad Truth"
phreck
Member since:
2009-08-13

Why so complicated:

int abs (int val) {
return val<0 ? -val : val;
}

or

template <typename T>
T abs (T const &val) {
return val<0 ? -val : val;
}


and squaring the number first is, in the real world, prone to overflow and assumes the presence of a square rooter.

But I am glad you and your friendly colleague enjoyed your sadism over that poor soul.

Reply Parent Score: 2

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

Yes, you would get a big smile from me for writing such code. But still, it contains the same bug as my example and I'd ask you about that.

Sadism? No at all. By that I mean we weren't making fun of the individual, we were just laughing at the funny code he wrote. We never even care whether an applicant is normal looking or not, or whether he walks on his two feet or rolls in a wheelchair.

Reply Parent Score: 1

RE[3]: Sad Truth
by phreck on Tue 25th Sep 2012 12:47 in reply to "RE[2]: Sad Truth"
phreck Member since:
2009-08-13

What would that bug be that would imply that most C++ implementations are wrong?

Here is the GNU implementation, located in bits/stl_algobase.h (an implementation detail of the head "algorithm"):

template<typename _Tp>
inline const _Tp&
max(const _Tp& __a, const _Tp& __b)
{
// concept requirements
__glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
//return __a < __b ? __b : __a;
if (__a < __b)
return __b;
return __a;
}


And it is already sadism if you laugh about the product of someone's intellect, even if you do it behind closed doors, which would imply uncandidness, and possibly a breach of confidentiality regulations. But of course that is not my problem, so I stop lamenting about that.

Reply Parent Score: 1