Re: Had an interview
- From: Robert Adsett <sub2@xxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 2 May 2008 17:16:56 -0400
In article <7tpm14h3ih2s46mnmul6qjpn8ck32e64ve@xxxxxxx>, Spehro Pefhany
says...
On Fri, 02 May 2008 11:23:13 -0700, Andrey Tarasevich
<andreytarasevich@xxxxxxxxxxx> wrote:
andrew.nesterov@xxxxxxxxxxxx wrote:
...
Once I've read a following joke in a programming errs and traps book:
Implement a block that inputs either 1 or 2 and outputs the opposite:
1 -> 2, 2 -> 1
The author continue with three hypotetical solutions:
1. A programming class instructor:
if ( x == 1) x = 2;
if ( x == 2) x = 1;
I don't know why you call it "solution", since it's obviously incorrect.
2. A programmer:
if ( x == 1) x = 2;
else if ( x == 2) x = 1;
That would be a beginner/inexperienced programmer.
A "programmer" would most likely opt for the '?:' operator in this case.
3. A mathematitian:
x = 3 - x;
In reality that would the solution for a _good_ programmer.
x^=3; // explain wtf this is doing right here
Changing a 2 to a 1 and a 1 to a two obviously ;) I have noted though
that besides trying for the most obscure code to prove their worthiness
to program no-one has actually verfied the inputs are in range.
Robert
** Posted from http://www.teranews.com **
.
- Follow-Ups:
- Re: Had an interview
- From: Andrew Smallshaw
- Re: Had an interview
- References:
- Re: Had an interview
- From: Andrey Tarasevich
- Re: Had an interview
- From: Spehro Pefhany
- Re: Had an interview
- Prev by Date: Re: A few novice questions
- Next by Date: Re: A few novice questions
- Previous by thread: Re: Had an interview
- Next by thread: Re: Had an interview
- Index(es):
Relevant Pages
|