Re: Current coding standard documentation
- From: "42" <life@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 6 Nov 2006 10:35:09 -0500
"Chris Burrows" <cfbsoftware@xxxxxxxxxxx> wrote in message news:454eaa10@xxxxxxxxxxxxxxxxxxxxxxxxx
"42" <life@xxxxxxxxxxxxxxxxxxx> wrote in message
news:454bd0c9$1@xxxxxxxxxxxxxxxxxxxxxxxxx
"Chris Burrows" <cfbsoftware@xxxxxxxxxxx> wrote in message
news:4548187d@xxxxxxxxxxxxxxxxxxxxxxxxx
Actually the beginning of this syntax style was ALGOL. Wirth fixed up a
few
of ALGOL's problems in Pascal but didn't resolve the others until
Modula-2.
The fixes that elegantly avoid the semicolon problems, dangling elses
etc.
etc. are:
IF ... END
IF ... ELSE ... END
IF ... ELSIF ... ELSIF ... ELSE ... END
(not a BEGIN in sight)
What we need is a SELECT statement:
select
when condition then statement
when condition then statement
:
when condition then statement
[otherwise statement]
end
OK - not a bad idea on first sight, but on closer inspection, we have two
new keywords and an alternative use for an existing one, where one new one
keyword is necessary and sufficient. There is also added redundancy.
Note that the introduction of keywords (particularly commonly used words) in
an existing language (particularly one that is case-insensitive) needs to be
done with utmost care to avoid clashes with existing code. This is much
harder to resolve with mechanical translation / migration tools than the
other syntactic changes involved in this discussion.
To illustrate what I mean, consider the case where there is only one
selection:
select when condition then
statement
otherwise
statement
end
This is totally redundant as it is just a more verbose form of the 'if then
else'. If we substitute 'if' for 'select when' and 'else' for 'otherwise' it
reduces to
if condition then
statement
else
statement
end
Of course, having a completely redundant statement like 'case' is fine, right? :)
After all, you can write the same code using only if then else. Oh, and naturally,
case expr0 of
expr1 : statement1;
else statement
end
can be written as
if expr0 = expr1 then
statement1
else
statement
but it's clear that when someone uses the case statement instead of the if
statement, it's an obvious indication that that part of code will probably
be extended in the future (or contained more in the past).
Moreover, we can eliminate the compound statement as well, they are
completely redundant. Why write
if cond then
begin
statement1;
:
statementN
end;
when
proc1: procedure;
begin
statement1;
:
statementN
end;
if cond then
proc1;
does the same thing?
All we then need to do is introduce a new keyword 'elsif' instead of the
more common usage keyword 'when' and we have:
if condition then
statement
elsif condition then
statement
elsif condition then
statement
else
statement
end
which gets us back to the way it has been successfully done for decades in
other languages.
I dislike this construct because I think it does nothing to make the code look
more readable. More if then else is exactly the opposite of what I want. The
SELECT statement (similarly to the CASE statement) makes the code much
cleaner. (While we are at it, I would like to be able to use OTHERWISE
instead of ELSE in the CASE statements as well!)
I always hated the concept of reserved words (and null terminated strings,
but that's another topic) as in my opinion it hinders the development of the
language. There are many things that could be added to the language if we
just got rid of the concept. However, since it is unlikely to happen to Delphi,
why not make a bunch of extensions and have a compiler switch that people
can use? This way the backward compatibility is maintained and at the same
time new projects can take advantage of the language extensions.
For example, in addition to the above suggestions, I would love to see the
addition of rol/ror operators and the for var := expr to|downto expr BY expr
construct, and other things that would help make the code considerably easier
to write and maintain.
.
- Follow-Ups:
- Re: Current coding standard documentation
- From: Chris Burrows
- Re: Current coding standard documentation
- References:
- Re: Current coding standard documentation
- From: Serge Dosyukov \(Dragon Soft\)
- Re: Current coding standard documentation
- From: Chris Burrows
- Re: Current coding standard documentation
- From: 42
- Re: Current coding standard documentation
- From: Chris Burrows
- Re: Current coding standard documentation
- Prev by Date: Re: World's Most SMART and *Stupid* Company! (Open Letter)
- Next by Date: Re: World's Most SMART and *Stupid* Company! (Open Letter)
- Previous by thread: Re: Current coding standard documentation
- Next by thread: Re: Current coding standard documentation
- Index(es):
Relevant Pages
|
Loading