# Wacky Programming Tales

Abigail abigail at delanet.com
Sun Aug 15 23:40:06 CEST 1999

```Kaz Kylheku (kaz at ashi.FootPrints.net) wrote on MMCLXXV September MCMXCIII
in <URL:news:slrn7re808.77t.kaz at ashi.FootPrints.net>:
## On 15 Aug 1999 03:14:48 GMT, Ben Caradoc-Davies <bmcd at es.co.nz> wrote:
## >[strange programming]
## >The most confidence uninspiring piece of code I ever had the displeasure to
## >maintain contained something like this (allegedly C++, but mainly it's
## >intersection with C):
## >
## >	i = 0;
## >	while( i < max_index ) {
## >		/* some copying or update (not modifying i) goes here */
## >		i = i + 1;
## >	}
## >
## >This was written by a *very* expensive consultant working for a large
## >multinational accountancy firm.
##
## So what's wrong with that? Granted, the for loop construct would have
## been better for the task instead of while, and the expensive consultant shoul
## have seen that. But what about the i = i + 1 increment? It smacks of BASIC, b
## there is nothing wrong with it.  It's not any less efficient than i++ or ++i.

I would still argue we don't know enough about the program to say it's
wrong or bad style. The last line is easily modified to "i = i + 2", or
"i = i * 1.5", or "i = i + a", where a is depending on the rest of the
statements in the block. I would prefer using "i = i + 1" or "i += 1"
if I mean "I add a number to i, which happens to be 1 in this case" over
"i ++", which in my book means, "I am counting" or "it's the next one".
I don't think using 'for (i = 0; i < max_index; i = i + 1) {}' is going
to buy me anything over the while. Except that's less flexible. Thinking
about the next programmer? Gimme a break. A programmer that gets confused
when seeing a while that could be written as a for shouldn't touch the
code anyway.

It's the same with !i and i == 0. With !i, i is acting as a boolean, while
in "i == 0", I am comparing i to a specific value. That the value just
happens to be 0 doesn't warrent a change in syntax.

Abigail
--
\$" = "/"; split \$, => eval join "+" => 1 .. 7;
*{"@_"} = sub  {foreach (sort keys %_) {print "\$_ \$_{\$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};

-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----

```