Newsgroups: comp.lang.misc Path: utzoo!utgpu!news-server.csri.toronto.edu!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!mroussel From: mroussel@alchemy.chem.utoronto.ca (Marc Roussel) Subject: Re: Learning other languages (Was: Fortran vs. C for numerical work) Message-ID: <1990Dec7.174243.29683@alchemy.chem.utoronto.ca> Organization: Department of Chemistry, University of Toronto References: <13457@chaph.usc.edu> <8960031@hpfcso.HP.COM> Date: Fri, 7 Dec 90 17:42:43 GMT In article <8960031@hpfcso.HP.COM> mjs@hpfcso.HP.COM (Marc Sabatella) writes: >> C on the other hand was not designed for math. It was designed for >>systems programming and any other use is incidental. It's not so much >>that C is difficult, it's that its syntax is unnatural for scientific >>programming. C is a lovely language if you're writing an OS. I think >>that those of us who say that we don't want to learn C because it's >>"difficult" really mean this: C is not particularly well-suited to our >>purposes so that beating our problem into C would be quite a chore. > >But what makes you say this? About the only significant difference in syntax >(as far as translating mathemetical formulae) is that C has no exponentiation >operator; instead you must call a library function. Other than that, why is > > C = SQRT( SIN(X) + LOG(Y) ) > >perceived to be more "natural" than > > c = sqrt( sin(x) + log(y) ); The two lines you have written make it look like it's not a big deal. However, consider the case where x,y and c are complex. Then in Fortran I simply put COMPLEX C,X,Y in the declaration section of my program and the compiler does the rest, right down to selecting the right sqrt, sin and log routines for complex values. On the other hand, in C I would have to supply: a) the complex type b) the addition operator for complex numbers c) sqrt, sin and log for complex arguments on top of which I would have to write c = csqrt(cadd(csin(x),clog(y))) which, at least in my opinion, obscures the meaning much more than the form above. Creating a complex type in C is not a particularly big deal, nor is writing an addition function, but providing a whole complex library could be a lot of work. Sure you only have to do it once and perhaps not even that since someone else might make his code available to you... But what's the point since Fortran knows all about complex types? And what about array operations? My impression was that C's array handling was less than impressive. Pointers are fine, but they don't represent a vector in as obvious a way as a one-dimensional array. Passing a pointer to an array to a subroutine is just not quite the same as passing a vector to a subroutine that deals with vectors. A similar argument applies to higher order tensors. If scientific programming never involved anything more than simple algebraic operations on scalar real numbers and integers, I'd be less resistant to the idea that C might be just as good as Fortran for this purpose. Unfortunately, practically all Fortran code involves matrices or complex numbers. Writing the same programs in C would just not be as easy. Marc R. Roussel mroussel@alchemy.chem.utoronto.ca