From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cfe6bee6cb133ace X-Google-Attributes: gid103376,public X-Google-Thread: 1094ba,3e0895d4223034d7 X-Google-Attributes: gid1094ba,public From: bglbv@my-dejanews.com Subject: Re: Fortran Myths & Disinformation Wanted Date: 1999/02/13 Message-ID: <87iud6tp2o.fsf@bglbv.my-dejanews.com>#1/1 X-Deja-AN: 443957230 References: <87g18d3lsv.fsf@bglbv.my-dejanews.com> <19990210201511.04389.00000245@ng-fx1.aol.com> <36C3BEA7.F96F80FC@ix.netcom.com> Organization: CyberCity Internet Newsgroups: comp.lang.fortran,comp.lang.ada Date: 1999-02-13T00:00:00+00:00 List-Id: eachus@spectre.mitre.org (Robert I. Eachus) writes: > > Fortran can also be fairly terse, if you just use the f77 way: > > function f(a, x) > g(x) = 1-a*x**2 > f = sin(g(2*x)) - cos(g(x/2)) > end > > > >That example is a little too simple to be interesting. Anyway, > > >Here is the Ada 95 version: {reformatted for clarity} > > with Ada.Numerics.Elementary_Functions; > use Ada.Numerics.Elementary_Functions; > function F (A, X: Float) return Float is > function G (X: Float) return Float is begin return 1.0-A*X**2; end G; > begin return Sin(G(2.0*X))-Cos(G(X/2.0)); end F; > > Looked at this way the difference in size is obviously due to > requiring all declarations to be explicit, and some added reserved > words (begin and return). Yes. Note that the full-fledged Fortran 95 version with explicit declarations and an internal procedure replacing the statement function reads: REAL FUNCTION F (A, X) IMPLICIT NONE REAL, INTENT(IN) :: A, X F = SIN(G(2.0*X))-COS(G(X/2.0)) CONTAINS REAL FUNCTION G (X) REAL, INTENT(IN) :: X G = 1.0-A*X**2 END FUNCTION G END FUNCTION F which has the same number of lines as my Ada version did before Robert Eachus reformatted it. And I'll reiterate that this example is too simple to be interesting, in that it is not representative of most numerical analysis code. Statement functions are not *that* common in practice, and subprograms tend to be longer (which makes IMPLICIT NONE more valuable than in this example). One thing this example shows is that Fortran is actually among the more verbose languages out there. The verbosity was gained in recent revisions of the language, and comes from features added to make debugging and automated checking easier. On the other hand Fortran 90/95 added features that promote higher code density, in primis array operations. This corresponds to what Robert Dewar has called a "higher level of abstraction"; I'm not sure whether he had Fortran 77 or Fortran 95 in mind when making his claim that Ada had an advantage on that count. (And I won't go into the merits of that claim here.) In my book, terseness is OK when a program unit is short enough that I can contemplate it in its entirety in my mind. As soon as it grows beyond the point where I need to keep written notes, explicitness begins to win (i.e. I might as well make sure that my notes are thorough; and if the compiler can understand them and make good use of them in its diagnostics, so much the better). > > There should be no difference in generated code between the two > versions, so the tradeoff is the traditional Ada tradeoff of more > required text to reduce errors and make maintenance easier. If you > don't care about maintenance, use APL which is even terser than > Fortran. I do. And if you do care about maintenance of Fortran code, you may like some of the new features, even though they come at the expense of terseness.