Both language are using the opposite paradigm. In short, Forth is a minimalistic programming language while C has a tendency to produce larger programs. On a first look, the Forth language fits very well to the needs of programmers, but a closer look on the problem will show that not Forth but C has became the dominant programming language.
In a c program there are variables available and the functions are larger. The typical length of a function is 100 lines of code that means an entire file is used to store a function. In contrast, in a Forth program a function which is called a word is very small That means the code is factored and no variables at all are used.
Let us take a look into the reality. A typical example for a software written in C is gnuplot. The main feature of gnuplot is, that the sourcecode is very long. The program takes lots of megabyte and the end user can adjust endless amount of parameters. The question is, if the program is so large and complicated why it is used so often? From a computer perspective, gnuplot wastes a lot of RAM and most of the code wasn't programmed very efficient. That means, the code wasn't factored very much.
The answer is, that gnuplot isn't thought from a hardware perspective, but the idea is to create a plotting software which can draw bar charts, 2d plots and lots of other formats. Basicially spoken, gnuplot and most of other Unix program doesn't care about main memory and CPU needs, but the goal is to write a full blown software which can be used by the end user.
In contrast, the paradigm of Forth is the opposite. Here is the idea that the needs of the CPU are important, and that the program needs to run efficient in terms of low memory footprint and low amount of cpu cycles. It simply doesn't make sense to write a program like gnuplot in Forth.
The main idea behind the c language is to abstract from low level machine operation. C provides the programmer a virtual machine which has endless amount of variables, long functions, files and libraries. This virtual machines makes it easy to write long complicated programs which are documented in endless amount of books in contrast, the idea of Forth is, that the user writes only small programs which have 20 words and doesn't need a documentation.
to understand the difference it makes sense to take a look back in the late 1980s. At this time the transation was made from 8bit home computers to modern PC like computers which were equipped with harddrives and 32bit cpus. The Unix operating system and the c language was never a great success on 8bit homecomputers. The reason was, that hardware of 8bit homecomputers is too small to run larger programs. Even 16bit home computers like the Amiga 500 have not enough main memory and disc capacity to run a unix operating system.
The situation has changed dramatically with the advent of the PC. If the computer hardware is more powerful it is possible to run modern cpu demanding c programs. For today's ears it sounds a bit uncommon but in the 1980s it was very complicated to provide 2 MB and more of RAM to run a program. That means, a software which needs so much RAM can't be executed in the past.
If a 32bit PC is available which has 16mb and more RAM in combination with a harddrive is it possible to run all sorts of C programs, which includes Unix, microsoft Windows or any other operating system. What these programs have in common is, that they are providing lots of programming libraries and the software will need very much RAM to operate. On the other hand the value for the end user is higher. He can use the computer to draw pictures, write a text and play games. Today's situation is, that C has replaced any other programming language and especially the Forth paradigm has felt into obscurity.
What Forth programmers are doing today is to assume a different ecosystem. They are imagine that there is only a 8bit cpu available, no harddrive and low amount of RAM, and then they are writing a program for this computer. It is easy to show that in such a restricted envrionment Forth performs much better than C. Simply because of the reason that a c program can't be executed on such a minimal computer.
No comments:
Post a Comment