Readable code (Was: Re: [H-GEN] Which is better?)
Harry Phillips
harry at tux.com.au
Wed Apr 28 06:21:45 EDT 2004
Russell Stuart wrote:
>
> A fine recommendation, and I don't recall anyone arguing against it when
> others said similar things in this thread. Exactly what constitutes
> "clean maintainable code" is possibly the real subject of this debate.
>
On the subject of readable code, will I have to get used to reading code
that looks like this:
if (orient==east) {
if (x+radius>side) {
if (clockwise) {orient=south;} else {orient=north;}
}
else {x=x+step;}
}
else if (orient==south) {
....
I find it alot easier to read:
if (orient==east)
{
if (x+radius>side)
{
if (clockwise) {orient=south;}
else {orient=north;}
}
else {x=x+step;}
}
else if (orient==south) {
.....
You can easily see what code is executed during which if statement. I
know doing it that way would create long lines for deeply nested if
statements (or for loops). Is that why most of the code I see is written
the first way?
BTW The above code was the "official solution" to our first assignment,
and it doesn't work as the assignment required.
The border check should have been:
if (x + step > side - radius) {...
--
Regards,
Harry Phillips
--- Failure is not an option,
it comes bundled with your Microsoft product.
More information about the General
mailing list