Re: Starting to doubt fortran
- From: "highegg" <highegg@xxxxxxxxx>
- Date: 29 Mar 2007 13:10:15 -0700
On Mar 29, 8:54 pm, Ben Hetland <ben.a.hetl...@xxxxxxxxx> wrote:
Dmitry V. Gorbatovsky wrote:
Noma...@xxxxxxxxx wrote:[...]
is it better or faster than C??So it depends on problem in hand.
Probably true, but ...
For numerical code Fortran is definitely
better than any alternatives, without doubts. The code itself would be
simpler(clearer) so your performance as programmer would be higher with
less bugs.
I would probably also disagree, because I consider it to bold a
statement.
How can you claim this?Given only scalar expressions, that's true. Perhaps the exponentiation
I just see too many contradictions to such a claim:
1. For "numerical code" the difference between C and Fortran is only
minor. (In fact C borrowed a lot of its formula syntax from just
Fortran...) That favors neither of the two significantly.
operator is a point for Fortran.
2. Whether or not the code is simple or clear depends partly on how
familiar the reader is with the syntax/language at hand, partly on the
skills of the code's author. It is possible to write virtually
unreadable code in both languages. Traditional Fortran code using only
capitals can be argued to be less readable, but that argument isn't
relevant these days when modern compilers accept lower case just the
same. So no specific advantage to any party here either.
It could be just my opinion (although definitely shared by plenty of
people) that most Fortran constructs is somewhat easier to read - IF-
END IF,DO-END DO vs C's {} for everything. OTOH, C is easier to write
by the same argument :)
3. When judging the degree of freedom the author has for producing code
with good readability, Fortran has the disadvantage of rigid and
odd/archaic line formatting rules (in fixed format), and imposes limits
on line lengths (72 or 132), both of which enforce limitations in the
freedom the author has to arrange his/her formulas with a readable
layout in mind. (66 character positions to play with is really not
much!) C does not have this limitation, but on the other hand too long
lines don't behave very well when printed for instance. I.e., I'd say
this isn't so much a relevant issue to favor one over the other in
practical life.
Fixed format is obsolete. I agree that the line length limitation can
sometimes cause trouble. OTOH, I was never sure with the semicolons in
C.
4. In Fortran it's often necessary to use more temporary variables to
store intermediate sub-expressions, or even literal numeric values (ever
used IONE or IZERO anyone?). This generally requires more lines of code
for expressing the same calculation in Fortran than in C.
I don't think so. Fortran's array-valued functions, vector indexing
etc. usually let you omit a temporary that you would need with C.
Also, intrinsics like HUGE() usually need to be replaced by predefined
constants in C.
In C, you can sometimes spare a local variable by reusing a function
argument. (is in F2003) Others, however, consider this a bad practice.
Dunno what IZERO or IONE is.
5. Regarding this:> And all that without any performance penalty on run time
(execution).
That is in fact not always the truth. In both of these languages it is
an important principle that "you don't pay for what you don't use", but
in real life things aren't always that ideal. Since the claim quoted
above was about numerical code, I think the common feature of run-time
checking of array indices[1] can serve as a good example.
Dunno what you have on mind. Fortran does not mandate bounds checking.
No compiler I'm aware of has array bounds checking turned on by
default.
You don't pay
this price in C, but then again you are allowed to shoot yourself in the
foot if you like, and bugs in the code causing for instance indexing
errors unfortunately tend to magically intrude into code of either
language.
Stricter rules regarding aliasing can give a Fortran optimizer
an advantage with arrays for instance, but there might also be an
advantage in the almost complete freedom (flexibility) given to the C
programmer dealing in the pointer/array minefield.
True; moreover, much of aliasing problems are addressed by C99's
strict pointers. I think it's particularly pointers what makes C so
powerful.
I think that it is practical for numerics to know both C and Fortran
at least a little, as one will certainly meet code in both.
I decided to go with Fortran particularly because of its array
facilities and the fact that it claims to be numerically targeted -
thus, chances are that it will incorporate important numerical
features more easily in the future.
.
- Follow-Ups:
- Re: Starting to doubt fortran
- From: glen herrmannsfeldt
- Re: Starting to doubt fortran
- From: Ben Hetland
- Re: Starting to doubt fortran
- References:
- Starting to doubt fortran
- From: Nomad.C@xxxxxxxxx
- Re: Starting to doubt fortran
- From: Ben Hetland
- Starting to doubt fortran
- Prev by Date: RE: Converting a string to reals
- Next by Date: LQ Decomposition and Null Space
- Previous by thread: Re: Starting to doubt fortran
- Next by thread: Re: Starting to doubt fortran
- Index(es):
Relevant Pages
|