How Not to Write FORTRAN in Any Language
gManZboy writes "In an article that's sure to p/o Fortran programmers, Donn Seeley has assembled a rant that posits there are characteristics of good coding that transcend all programming languages, except Fortran. Seriously though, his point is that early FORTRAN made coding ugly. Thus the joke 'Don't write FORTRAN' was applied to anyone with ugly code. Though Fortran has in recent years overcome its early challenges, the point -- 'Don't write FORTRAN' (i.e. ugly stuff) -- still applies."
While I take issue with his blantant anti-FORTRANism, he makes the excellent point: Write good code in whatever language you write. Just because you can write Perl that looks like line noise does not meen you must.
How does the Slashdot Effect happen given that no slashdotters ever RTFA?
The name "FORTRAN" came from "FORmula TRANslator." It was created so that engineers and scientists could write programs to perform calculations. They wouldn't need a degree in programming, and they wouldn't be reliant on programming staff. They would be able to independently take advantage of a company's (or university's) computing resources. It wasn't DESIGNED to be a pretty language; it was designed to be used by people who would have stared blankly at you if you'd mentioned the concept of a pretty language. It served its purpose well.
It reminds me of SQL in that respect. I have worked with managers who knew less about computers than their secretaries, but they were able to use SQL to write queries to get information that they wanted. SQL was written for that purpose. It ain't pretty, but it serves its target market.
I doubt that designers of armored cars and dump trucks worry about the slings and arrows of the Ferrari's designers; I think this rant is pretty much in the same vein as that. Beauty and utility are not synonymous.
So are they using "FORTRAN" as a adjective replacing "crappy" and then whipped up an article that has been covered in about 5,000 different programming books and/or documentation regarding some largely accepted guidelines for writing clean, manageable and efficient code?
Why is this on the front page?
"Acmqueue Click-thrus ACTIVATE!! Go Go Go!"
Sehr geehrter Toilettenbenutzer!
if the article weren't broken
into such small pieces.
That way I could
print it for my students.
Sort of amusing for an article that discusses using white space in a good way.
As Nietsche famously said, "If you stare too long into the Abyss, 1d4 Tanar'ri of random type will attack you."
I have to say my interest in the article plunged through the floor when I saw the example using Bush/WMDs as the subject. I immediately realized I'm either reading something written by a college student or someone who has not matured much beyond that. How gauche.
Regardless of how you feel about the politics, it's just not kosher to use examples like that. Clearly this is a person with an axe to grind.
I read the fucking article. I didn't see too much very insightful, or see any specific reference to Fortran at all.
Since major companies like IBM have chosen to produce compilers that perform best with FORTRAN. (absoft markets the compilers with a front end)
I like C, and a slew of other languages much better...
But my G5 dual-processor desktop machine can be optimized to run at around 35 GFLOPS. Try that on an 8086 derivative What, maybe you can get 2-4 GFLOPS per machine (if a dual-processor system)? I have a low-end supercomputer on my desk! Unfortunately, without FORTRAN, it wouldn't be so super.
FORTRAN is the only language that will easily take advantage of the HW (Altivec 'velocity engine' and parallel processing).
Each language is good for some tasks. FORTRAN happens to be good for performance in science and engineering work.
Fortran has been dieing longer than BSD has. People still write code in it, people still learn it as their first language, and there are millions of huge bug free programs that still need to be kept up to date. As many people have pointed out here, there are lots of virtues to Fortran 90 that make it worth using over other languages for certian applications. Fortran has made its way into the woodwork and it is here to stay!
...except that each time a page loads, a new set of ads is displayed, potentially making it more profitable for the author.
So the artificial 'page' breaks are a byproduct of profit motive, nothing more.
Sad, but true.
Actually, real fortan programs tend to be quite large.
Not OS large, but 10 to 100 megabytes of source code is not
uncommon. The typical program is hacked on by grad
students two or three at time over the progress of years.
Which is a shame really because you should be judging the quality of the application - and not what it was written in. Seriously, if it does x and it does it quickly and well with a nice user interface - does it really matter that it was written in Algol 68?
As a by no-means perfect example, check out this site which is, I think, a reasonably nice looking application written in Visual Basic (it acts as a GUI to the free SMS gateways out there). I don't claim to have it perfect, but the feedback I've had from people indicate that they don't think it's the usual run-of-the-mill-vb-application.
Disclaimer: I wrote it and the preference section is a little nasty, but I'm working on it. Also, I know that VB is only really for doing RAD but I don't have the time or inclination to learn Visual C++.
Avantslash - View Slashdot cleanly on your mobile phone.
We're still using F77 here, so I didn't know that. :-)
Fortran 90/95/2003 are well worth 'upgrading' to -- for starters, the array syntax is fantastic. If A and B are arrays, you can assign from one to another simply by 'A=B'. Likewise, 'A=sin(B)' would set each element of A to the sine of the corresponding element of B. Code like this is a doddle to parallelize automatically, enabling one to write parallel code with very little effort.
Tubal-Cain smokes the white owl.
As somebody that has been programing for 25 years, all I can say with regard to this article is "Well, duh! Tell me something I don't already know!" Seriously, if you've been programming for more than 3 years and haven't already figured out by yourself (and by bad example) how to write understandable code, maybe you shouldn't be programming!
I've abandoned my search for truth; now I'm just looking for some useful delusions.
The point of multidimensional arrays in FORTRAN is simple and straightforward: they're contiguous blocks of storage. In C, multidimensional arrays are a fiction, because a[i][j] is given exactly the semantics of *(*(a + i) + j), instead of *(a + i * second_dim + j). That extra dereference takes away a huge number of optimization opportunities.
Pointers are useful in systems programming, but K&R made C a much less useful scientific language by not including the multidimensional array dereference operator. That's fine -- they weren't writing a language for scientific computation. I even think they made the right design choice, since there was already one around; it was called "FORTRAN".
Generally, I mean sustained heavy calculation with large blocks of data.
'
Sure, you *can* write those operators and templates, but they tend to already be there in Fortran. And if they're not, it's near certain that you can find existing, well-tested libraries.
The "less code" was my own experience several years ago while still using both for this kind of work. It's been long enough that I"m straining to remember specifics, but the dusty brain cells want to say [no, scratch this example; it make no sense].
Whether you use pointers or not, the C compiler may be forced to make allowances for it. Fortran pointers are far more limited, and the compiler needn't consider the extra possibilities.
And as for goto? Why is it any worse that one exists in Fortran than C? I've used one twice in the last ten years (or is it once). The alternative was setting a status variable to be checked to skip the block of code (for the general case) immediately following the select case structure. I *could* have avoided the goto, but the code was much clearer by using it.
hawk
I think part of the problem is that many of us learned FORTRAN 77. I had a prof in college who was a FORTRAN fanboy, and he quoted someone saying, "I don't know what the language of 2000 will be, but it will be called FORTRAN." Basically, rather than dumping the old design and starting over with a new math-based language, they are just evolving the old one to the point where it is no longer the same beast it used to be. I haven't even looked at the latest versions, but I gather they might be acceptable to a computer scientist.
Whether this is a good thing or a bad thing is another discussion. Programmers like to start over with the assumption that "it's going to be right this time." Often, though it's better to make incremental changes on a well established base. It all comes down to how much change is required, I guess.
Lucky for us all, there's no lock-in on languages. You can use FORTRAN, I can use C, someone else can use Perl. Here's to healthy competition (which seems to be a rarity these days.)
FORTRAN (FORmula TRANslation) was never meant to be a general-purpose programming language, it is strongly biased towards scientific calculations. It has native support for doing fast computations with scalars and arrays of integer, real and complex data types. In modern revisions of the language (F90/95, Fortran 2000/2003) it gained support for dynamic memory allocation (although there is no garbage collection), abstract data types, pointers and object-oriented programming but few people use these capabilities. And yes, it is possible to write beautiful programs in FORTRAN although bad practices prevail due to the backwards capability of modern FORTRAN with F66/F77.
- You don't have enough experience reading/writing code. You have to read (more so than write) a tremendous amount of code to get good at reading code.
- You don't understand the problem the code is solving.
- The code is very badly designed at a higher level than things like white space and underscores.
A lot of people get frustrated when they don't understand code right away, and rather than trying to grok why they don't understand it (because 2/3rds of the time it is the reader's fault, not the coders), they just bitch about white space and brace placement. That is never the problem.