📜 ⬆️ ⬇️

Say a word about poor FORTRAN

I tried to write my first post here by pushing an article about choosing the first programming language , where vt4a2h suggests using C ++ for learning. Yes, many copies were broken on this topic.

I, like most schoolchildren in the vast expanses of our immense Motherland, began to comprehend the basics through a blue screen, but not death, but Turbo Pascal 7.0. There was, of course, Basic, which I first encountered at the pre-school age on the Soviet computer "Electronics". Then he seemed a strange text editor, because the computer through the eyes of a child was created for games. However, at the institute, I became acquainted with the language of Fortran, having learned that, I still wonder why it is not used for teaching.

Yes, many will say that the language is dead, does not correspond to modern realities, and textbooks with the title, as in the picture, cause only a smile. I will try to explain why this language is so wonderful and why I recommend it as a first language. If interested, welcome under cat.


I believe that the basis for the basics of programming should be laid back in school years, at least in high school. Even if in life a computer will be used only for typing in Word or for communication in social networks, minimal knowledge of what an algorithm is and how to structure a sequence of actions to get the desired result will at least not harm a young teenager in an adult. life, and most likely help to form a special mindset.
')
In order for computer science lessons to be a joy, and not to dream in nightmares, the learner must understand what he does, how he does it, and why it happens so and not otherwise. After all, in fact, you need to properly convey information about the cycle and the conditional operator, so that a person can write programs independently. In this case, the simpler the language syntax, the easier it is to understand the logic of writing code. If a person learns to compose the correct algorithm, then for programming in other languages, he will only need to learn the syntax of this language, and the basis will already be laid.

Why is Fortran so wonderful?


Let us turn to the history of the creation of this language. It appeared in the distant 50s of the last century, when computers were still large, there were few programmers, and computer science was not taught at school, and in general was considered pseudoscience. A simple language was needed that would help engineers and scientists to “feed” computers formulas written on paper, even through punch cards.

Hence the name of the language itself: For mula Tran slator or “formula translator”. Those. Initially, the language was aimed at people without special training, which meant it had to be as simple as possible.

Well, the simplicity creators succeeded. The classic first program looks like this:

program hw write(*,*) 'Hello, World!' end 

The syntax is even a little simpler than Pascal, there is no need to put at the end of the line " ; " or " : " before the equal sign. Moreover, people with minimal knowledge of the English language, to understand the meaning of the simplest program is not difficult.

Here I want to note that Fortran has several revisions of standards, the main of which are 77 and 90 (while maintaining continuity). 77 Fortran is really archaic, there is a limit on the length of the line, and it is necessary to indent at the beginning of the line, which can cause a culture shock for a young candidate for programmers. It is not without reason that programs written in 77 Fortran received from the lips of my acquaintance the capacious name “Brezhnev Code”. Therefore, all my text refers to the standard language 90 and newer.

For example, I will give the code for calculating the sum of non-negative integers from 1 to n, entered from the keyboard, written by my diploma student when teaching her programming from scratch. It was there that I experienced teaching Fortran as a first language. I hope that this has benefited her, but my experiment was a success. At least she learned the basics in a couple of classes, the first of which went to a lecture about language.

 program chisla implicit none ! Variables integer n,i,s ! Body of chisla s=0 write (*,*) ' n' read (*,*) n if (n.le.0) then write (*,*) '  ' else do i=1,n s=s+i end do write (*,*) '=', s end if end 

It is easy to see that as we think, and write the code. No difficulties for the student can arise in principle. An attentive reader will of course ask that for implicit none and two asterisks in brackets separated by commas. implicit none tells us that we explicitly specify the type of variables, whereas without this record the compiler will guess the type itself. The first asterisk indicates that input and output occur on the screen, and the second indicates that the input / output format is automatically detected. Actually, programs in Fortran look no more complicated than the piece of code written above.

What about the software environment?


In schools, and in any state institutions, there is often a question about software, in particular about its licensing. Because the money for these needs are not particularly allocated. At least in my time, there was a problem with this, maybe the situation has now changed for the better.

For writing programs in Fortran fit any text editor. If you want syntax highlighting, you can use Notepad ++ (supports only 77 standard syntax) or SublimeText. The program was written, what will we compile? Everything is simple, you can use the free GNU Fotran. If non-commercial use is planned, then the compiler from Intel, which is well optimized for the processors of the same name and comes with the minimum necessary IDE, is also allowed to sweep. Those. threshold of entry is very preferential.

According to many users, Compaq Visual Fortran 6.6 is the best development environment for Fortran, the latest version of which was released in the early 2000s. Why did it happen that the environment based on Visual Studio 6.0, which, without dancing with a tambourine, brings a maximum to Windows XP 32 bit, and has a restriction on the memory used, has gained such popularity among the forwarders. The answer is shown in the figure below.



This is Compaq Array Visualizer, which is a very handy tool for visualizing 1, 2 and 3-dimensional arrays in the process of debugging a program directly from a debagger. As they say, having tasted it once and now. The fact is that FORTRAN is now used mainly in science (which will be discussed later), in particular in the field I deal with, namely, in atmospheric physics. When debugging programs, arrays represent various meteorological fields, such as temperature, pressure, wind speed. It is much simpler to look for an error in graphic fields than in a set of numbers, all the more, it is usually known how approximately the field should look, therefore obvious errors are cut off instantly.

Unfortunately, all the compiler developments have moved from Compaq to Intel. Intel initially supported the Array Visualizer, although already those versions were a pale reflection of the product from Compaq, working with them was not as convenient as before, but at least minimal performance was supported. Alas, Intel has ceased to develop new versions of the Array Visualizer, putting an end to this handy tool. That is why the Fortran community for the most part writes programs and debugs them under Compaq Visual Fortran on Windows, and launches combat calculations on servers running Linux using Intel-based compilers. Intel, please hear the pleas of users, return the normal tool for visualizing arrays to your debugger!

Place Fortran in the modern world



And now we come to the very topic that usually causes a heated discussion with my colleagues using Matlab, who claim that the rare language described in this post is useless. Here I disagree with them. The fact is that Fortran was historically used in engineering or scientific calculations, and therefore over time it acquired a lot of ready-made libraries and program codes for solving a particular task.

The code is literally handed down from generation to generation, and it is also well documented. You can find a lot of ready-made solutions of equations of mathematical physics, linear algebra (here we should note the successful implementation of working with matrices), integral and differential equations, and much more. Probably hard to find a problem in the field of physics mathematics for which the algorithm in the Fortran language would not be implemented. And if we take into account the excellent optimization of Intel compilers for Intel’s processors, support for parallel computing on high-performance clusters, it becomes clear why this language takes first place in the scientific community. I think on any supercomputer you can find an installed Fortran compiler.

Most serious models, at least from the area of ​​atmospheric physics, are written in Fortran. Yes, the weather forecast, which everyone is interested from time to time, is obtained in the course of calculations of models written in this language. Moreover, the language is not in stagnation, but is constantly being improved. So, after the previously described standards 77 and 90, new editions of 95, 2003, 2008 have appeared, the support of which has been incorporated into actual compilers. The latest versions of Fortran somewhat refreshed the old time-tested language, exceeding the support of the modern style, adding object-oriented programming, the absence of which was almost the main asset of the opponents of this language. Moreover, The Portland Group has released a PGI CUDA Fortran Compiler, which allows for highly parallel calculations on video cards. Thus, the patient is more than alive, which means programmers at Fortran remain in demand until now.

Instead of an afterword


And now I would like to return to the initially touched topic on teaching programming, and try to articulate the main advantages of FORTRAN when choosing it as a first language.


So why not FORTRAN?

Source: https://habr.com/ru/post/202680/


All Articles