Re: Had an interview
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 02 May 2008 16:38:04 -0400
Andrey Tarasevich wrote:
andrew.nesterov@xxxxxxxxxxxx wrote:
...
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.
I vote for:
if (1 == x) x = 2;
else x = 1;
which is clear, and has no undefined states. Self-healing code.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
.
- Follow-Ups:
- Re: Had an interview
- From: Paul Carpenter
- Re: Had an interview
- References:
- Re: Had an interview
- From: Andrey Tarasevich
- 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
|