For some reason I keep calling to mind an example from the Springer-Verlag book on Ada style, author Dr (? Henry) Ledgard, which contained in its preamble the assertion that the book demonstrates Dr Ledgard's superb programming style. The example is:
function is_something (some parameters) return Boolean is
begin
if some relationship between parameters then
return TRUE;
else
return FALSE;
end if;
end;
It seems to me that this function violates a couple of rules:
1. It's longer than it needs to be.
2. It has multiple return points.
and that these failings would be rectified by rewriting thus:
function is_something (some parameters) return Boolean is
begin
return some relationship between parameters;
end;
which ought to be obvious to anyone who knows anything about functional or even `expression' languages from Algol-68 onwards.
So why did he do it the way he did ? Are there theoretical reasons for the more verbose version ? I can't believe that it's as straightforward as that he didn't think of the shorter way of doing it.
(Apologies BTW for the lack of indentation---I didn't know how to do the mark-up.)
|