Turn: forth Language

Source: Internet
Author: User
Tags compact

From: http://blog.codingnow.com/2010/06/masterminds_of_programming_forth.html

Extract interesting paragraphs:
As long as I hear someone boast that the Code has reached millions of lines, I know they must have understood the problem. Currently, there is no problem with writing millions of lines of code. Either programmers are too careless, project managers are too asshole, or they are compatible with non-existent requirements.
---
Oh, I went to Stanford in 1960s, where a group of graduate students were writing a version of the ALGOL Compiler-Burroughs 5500. At that time, I thought they were only three or four people, and three or four people sat there and wrote a compiler. I was so arrogant.
---
The operating system is another strange thing. The operating system is complex and useless. It is a brilliant concept that Bill Gates successfully sells to the world. This may be the biggest scam in the world.
The operating system is absolutely useless for you. In fact, you have something that is enough: a subroutine called a disk driver, a subroutine called a communication support program. In modern society, the operating system has nothing to do with it. In fact, Windows has spent a lot of time on the packaging layer, or Something unrelated like the Disk Manager. You have a GB disk and M memory. The world landscape has changed, making the operating system less useful.

The content is reproduced later.

This evening, I continued to read masterminds of programming. I couldn't help but translate another half-Chapter interview about the father of forth. I have read several interviews with him earlier, and I have some knowledge about his views. When I was a child, I was particularly fascinated by forth. This nagging old man is very interesting.

I have not read the original translation, but I have translated the First Half of Chapter 4th forth according to my own understanding. I am also a very fond man of forth. I also know what the term ITC (indirected-threaded Code) in forth refers to, but I still feel that translation is a little difficult.

Let's take a look at forth's loving classmates.

Forth language and language design

How do you define forth

Chunk: forth is a computer programming language, and its syntax scale is simplified to the extreme. Separating the parameter stack is a major feature of the language, which makes subprogram calls very efficient. Therefore, the language uses a suffix expression (first column parameter, then operator), and encourages the style of dividing the program height into many short subprograms. These subroutines share the parameters on the stack.

I have read about the forth name, which is said to represent the fourth generation of software development. Can you introduce us more?

Chunk: forth originated from the word "fourth (fourth. It refers to "the fourth generation of computer language ". As I recall, I skipped my generation. FORTRAN/COBOL is the first generation; ALGOL/lisp is the second generation. These languages emphasize syntax. The more detailed the syntax, the more error can be checked. However, most errors are syntax errors. I decided to minimize the syntax element and emphasize its semantics. The loaded forth word truly expresses its meaning.

You use forth as a language tool set. I understand this perspective in this way: it provides simpler syntax than other languages, and the ability to build a vocabulary with shorter words than other languages. What else do I miss?

Chunk Moore: That's it. The key point is that we do our best to break it down. A forth program contains a large number of small words. Comparatively, the same C program uses less words, and each word must be larger.

Short words refer to words that can be defined using a line of source code. You can use the newly defined words to define the next new word. In this way, thousands of words are defined and the language is formed. The challenge is: 1) determine which words are useful. 2) Remember all defined words. The application I am writing now has thousands of words. So I wrote a tool to search for these words, but you must first remember this word and probably how to work it out.

Now, with a completely different programming style, it takes some time for programmers to adapt. I have read too many forth programs, just like a literal translation from the C program. This is not the case. The correct method is to start from scratch. There is another interesting thing about this toolset. As long as you do well, the newly defined words are no different from the pre-defined words in the kernel. They are equally efficient and have the same external meaning. There is no additional overhead for defining your own words.

The external structure seems to be composed of many small words. Is this due to the implementation of forth?

Chunk: this is the result of our highly efficient subroutine call sequence. There is no parameter transfer here, because the language is stack-based. All is called and returned. The stack is exposed. Let the language recognized by the machine be compiled together. To enter and exit a Word program, you only need to translate it into a call command and a return command. You can get equivalent commands at the assembly language level. You can define a word to execute a real machine command instead of a subroutine call. This way, it can be more efficient than other languages.

In this way, there is no consumption of C calls.

Chunk: Yes. This gives programmers great flexibility. If you can intelligently break down the problem, you are not only an efficient and complete task, but also the process of completion becomes extremely easy to read.

On the other hand, if you do a terrible job, you can only interpret your final code in the world-even your knowledgeable manager cannot understand the code you have written. You can write tianshu. Therefore, this is a double-edged sword. What you can do is flawless and dirty.

What can you say (or show Code) to let developers in other programming languages fall in love with forth?

Chunk: It's hard to interest experienced programmers in forth. This is because he has invested heavily in the language/operating system-related tool learning he is using. He has accumulated a lot for his applications. Even if they are told that forth will be smaller, more block, simpler, and not at the cost of rewriting everything. A novice programmer, or an engineer who needs to write some code without such interference, may be more likely to accept it. Well, there may be an experienced programmer who wants to launch a new project, and this project has some new constraints, such as the multi-core chip I am working on.

You mentioned that a large number of forth programs you have seen look like C Programs. So how do you design a better forth program?

Chunk: bottom-to-bottom.

First, you may expect some I/O signals to be generated. Well, we will generate them. In this way, you can write some code to control the generation process of these signals. Then you will know a little bit about how to finally build high-level words. Suppose you name it go. Next, you can knock on go. Everything will happen as scheduled.

I don't believe in the top-down system analysis method. They determine what the problem is, and then break it down, but it is difficult to implement it.

We recommend that you use the customer's words to describe the business logic. What is the connection between creating a dictionary and using terms in your problem domain?

Chunk: it is best for programmers to understand that field before they start writing code. I will communicate with the customer. I will listen to his words and try to use them so that he can understand what the program is doing. Forth is easy to read because it uses the suffix mark method.

If I write an economic application, I may use the word "percent. You can write "2.03 percent" in the code ". Here the percent parameter is 2.03, and everything is as natural as it looks.

A project from the computer age of punched cards has been so useful to modern computers in the Internet age. Forth was designed and applied on IBM 1968 in 1130. It's amazing that it will continue to be used for Parallel Processing in 2007.

Chunk: forth also evolved. However, forth may be the most concise computer language. It does not impose any constraints on programmers. He or she can define words precisely to suit the problem in a layered manner.

When designing a program, do you want to make the program read as English?

Chunk: at a very high level, this is the case. However, English is not a good language for functional description. English is not designed to do this, but English and forth have a common feature, that is, you can define new words.

You can define new words by interpreting many previously defined words. For natural languages, it is possible that they are not rigorous. If you look up the dictionary, you will find that some are loop definitions, and you cannot find the essential content.

Does it mean to focus on a bunch of words, so forth can write programs with better taste than the brackets in C?

Chunk: hope so. This allows forth programmers to focus on the appearance of things, not just their functions. It will be nice if you can organize a series of words and arrange them in an orderly manner. That's why I developed colorforth. I used to worry about the old syntax in forth. For example, to comment on the current method, you must enclose it with a left bracket and a right bracket.

I looked at all punctuation marks and said, "Okay, there may be a better way ." One of the most troublesome ways to do this is to add a tag to each word in the source code. If I can endure this overhead, all the symbols will disappear comfortably. Instead, each word will have a color. For me, this is an elegant way to express its functionality.

I was attacked by the color blind group. They are angry with me for trying to put them out of the ranks of programmers. However, someone finally thought of a trick and replaced the color distinction with the font distinction, which is also a good method.

The key point is that each word has a four-digit tag, which can differentiate 16 things. The compiler can immediately perceive what it is going to do, without being inferred from the context.

Both the second and third generation languages have converted to minimalism. For example, meta-circular bootstrapping is achieved (self-lifting of ring, and self-running of itself ). Forth is the best example of minimalism in terms of language concepts and hardware requirements. Is this the characteristic of the times or the innovation you have made across the Times?

Chunk: neither. At that time, the design goal was to make the smallest kernel as much as possible. Only predefine the most necessary words, and then let the programmer add what he thinks is appropriate. The main factor is portability. In that era, the big and small computers were followed by a large computer. And I have to get forth to so many machines.

I want to do this as easily as possible. What I want to do is to create a kernel with a hundred words to form an operating system, but it is not entirely an operating system, there are several hundred words for use in this article. Then you can develop on this page.

I will provide the first two stages of work for programmers to do the third. I also often work as an application development programmer. Defining Words I know is always necessary. The first one hundred words may be defined in machine language or assembly language, at least directly dealing with specific platforms. The second and second words can be high-level words, minimizing machine dependence at a lower level. Next, the application will be able to achieve maximum machine independence, so that it is easy to transplant the program from one machine to another.

Can you easily migrate data on the second stage?

Chunk: Absolutely. For example, I have a text editor used to edit the source code. It is always available on a variety of machines without modification anywhere.

There is a legend circulating everywhere. Every time you see a new machine, you immediately start to transplant forth to it. Is that true?

Chunk: Yes. In fact, it is the easiest way to understand how a machine works; to understand the strange machine features that can be used to more easily implement the word in the forth standard package.

How did you invent indirect-threaded code?

Chunk: code is a very subtle concept. Each forth word has an entry in the dictionary. For direct-threaded code (), the code to be executed is directly pointed to the position where each word is referenced. Indirect clue-based encoding (indirect-threaded code translated as indirect string encoding) indicates a location that contains the address of the Code. This allows information outside the address to be accessed-for example, the value of a variable.

This may be the most compact word organization method. It can be equivalent to direct clue-based encoding and subprogram-based encoding (subroutine-threaded code, that is, the method of directly calling subprograms compiled by C language ). Of course, this concept and term were not found in 1970. But for me, this is the most natural way to implement various words.

How does forth affect the future of computer systems?

Chunk: this is already happening. I have been working on Microprocessor Optimization for 25 years. The newest core of a multi-core chip is forth computer.

What does forth provide? As a simple language, it makes such a simple computer: local memory with 256 characters; two lower-pressure stacks; 32 commands; asynchronous operations; easy to communicate with adjacent machines; low Power Consumption.

Forth encourages highly decomposed programs. This is very suitable for Parallel Processing on multi-core chips. A large number of small programs encourage every one of you to think carefully about the design. In this way, you may only need to write 1% of the Code.

As long as I hear someone boast that the Code has reached millions of lines, I know they must have understood the problem. Currently, there is no problem with writing millions of lines of code. Either programmers are too careless, project managers are too asshole, or they are compatible with non-existent requirements.

Using Forth is a huge fork strategy for programming on small computers. Other languages cannot provide considerable modular capabilities and scalability. In particular, computers are getting smaller and smaller, and network collaboration is required between them (Smart Dust ?), This is the future environment.

This sounds like one of the most important UNIX principles: with many programs, each of which does only one thing and interacts with each other. Is this still the best design today? Will multiple programs running on one machine be replaced by multiple programs running on the network?

Chunk: The concept of Running code on multiple threads is implemented by UNIX and other operating systems. This is a pioneer in parallel processing. But there are some important differences.

A large computer can afford the cost of multithreading. Finally, a huge operating system is created. For parallel processing, the more computers, the better.

When resources are limited, more computers mean smaller computers. However, small computers cannot afford the cost of large computers.

The network of a small computer will occur on the chip and be connected to the chip through RF. Small computer memory is also small. The operating system has nowhere to go. Computers must be autonomous and capable of maintaining communications. Therefore, the communication process must be simple-there are no painstaking protocols. The software must also be compact and efficient. The most ideal application is forth.

Those systems that require millions of lines of code will fade out of the historical stage, creating a huge central computer. Distributed Technology requires different ideas.

If a language is designed to support complicated code and stick to the code, it will encourage programmers to write huge programs. And proud of it. There is no pressure to find a compact solution.

Code generated in a language defined by complex syntaxes can also be small, but it is usually not possible. The implementation process with syntax-implied results in clumsy and less efficient target code. This is not suitable for small computers. A well-designed language has a one-to-one relationship between the source code and the target code. This shows programmers how to generate the final code from the source code. Focusing on performance, reducing the need for documents, so that programmers can feel satisfied.

Forth is designed to compact the source code and binary input target code, which is also widely used in embedded development. However, programmers in many other fields have other reasons to use other languages. Does it mean that some aspects of the design of these languages only increase the cost of the original code or target code?

Chunk: forth is indeed compact. One factor is that his syntax is small.

Other languages seem to intentionally add some syntaxes and work out some redundancy, which can help syntax checks and error detection.

Forth does not provide any opportunity for error checks because it does not have redundant information. This also makes the source code very compact.

I feel that almost all the errors in other languages are in syntax. Designers seem to have created conditions for programmers to make compiler-ready errors. This has no economic value. Isn't that a problem for writing the correct code.

For example, type check. Assignment errors between different numeric types are detected. The unintentional consequence is that programmers must convert the types themselves. Sometimes they want to avoid type checks and get what they really want.

Another result of syntax is that it must adapt to the intent of all applications. This will become more and more complex. Forth is an extensible language. Programmers can create structures with the same performance only through compiler improvements in other languages. All capabilities do not need to be provided in the first place.

One of the features of forth is the use of suffix operators. This simplifies the compiler and provides a one-to-one relationship from the source code to the target code. A programmer's full understanding of the Code he wrote can increase the computation of the Code after compilation.

** Many recent computer languages (especially Python and Ruby) have cited readability as a key benefit. What can forth learn and maintain in comparison to this aspect? What can forth teach other languages in terms of readability?

Chunk: all computer languages claim to be readable. But they are not readable. It may be readable for people who understand the language. But beginners are still confused.

The problem lies in the obscure, arbitrary, and hidden syntax. Those parentheses, & characters, and so on. You try to learn why they appear there, and finally infer that there is no good reason. But you still need to follow the rules.

You cannot speak this language. You must read all the symbols like Victor Borgia.

Forth reduces this problem by minimizing the syntax. Which of the following are the mysterious symbols used by @ and! It can be read as "Fetch" and "save ". These symbols are used because they appear too frequently.

Programmers are encouraged to use natural language words. They are not separated by punctuation. If you select a word, you can construct a meaningful sentence. In fact, someone uses forth to write poems.

Another advantage is suffix representation. A phrase like "6 inch" can act on parameter 6 with the operator "Inch", which is a natural expression. Very readable.

On the other hand, the programmer's task is to develop a group of words to describe the problem. This dictionary will become very large. Readers need to understand the entire dictionary to make the program readable. Programmers must define words well.

All in all, using any language affects program reading.

How do you define success in your work?

Chunk: an elegant solution.

People do not use forth programming. Forth is a program. They add new words to create a dictionary to define the problem. When the correct words are defined, everything will be done. Next, you can interact with each other to solve all relevant problems.

For example, I can define some words to describe a circuit. In the future, I want to add this circuit to a chip, display the layout of the circuit, verify the setting rules, and run the simulation. The words used to do these things determine the application form. If you carefully select these words and provide a compact and effective tool set, I will do it.

Where did you learn to write the compiler? Do everyone have to write a compiler in that age?

Chunk: Oh, I went to Stanford in 1960s, where a group of graduate students are writing a version of the ALGOL Compiler-Burroughs 5500. At that time, I thought they were only three or four people, and three or four people sat there and wrote a compiler. I was so arrogant.

I think, "depending on what they want to do, I can do it too ." Then I did it. In fact, it is not difficult at all. It was a bit mysterious to write a compiler.

It's still mysterious to the west.

Chunk: Well, it's not that mysterious. As you can see, new languages are emerging one by one. I don't know whether the explanatory or compiled language is used. No matter what, hackers want to be one.

The operating system is another strange thing. The operating system is complex and useless. It is a brilliant concept that Bill Gates successfully sells to the world. This may be the biggest scam in the world.

The operating system is absolutely useless for you. In fact, you have something that is enough: a subroutine called a disk driver, a subroutine called a communication support program. In modern society, the operating system has nothing to do with it. In fact, Windows has spent a lot of time on the packaging layer, or Something unrelated like the Disk Manager. You have a GB disk and M memory. The world landscape has changed, making the operating system less useful.

What should I do if the device supports it?

Chunk: You have a subroutine for each device. It is a database, not an operating system. Which one do you need to load.

After work gap, how do you continue programming?

Chunk: I will not interrupt my code when I am troubled. I will think about problems with enthusiasm and dream about them all. I think this is a forth feature: focus on solving a problem within a short period of time (in days. This helps forth applications be naturally divided into sub-projects. Almost all forth code is easy to read. When I really want to do some extreme things, I will make comments. Good comments can help me back to the problem in the future, but it is still necessary to read and understand the code again.

What is the biggest mistake you have made in design or programming? What have you learned?

Chunk: more than 20 years ago, I wanted to develop a tool for designing a large-scale chip. I don't have forth on my new computer, so I want to use another method to write machine languages. If it is not an assembly, it is a hexadecimal code to knock on machine commands.

I write code as I write the forth program, and define simple words related to each other in different layers. The final solution is completed. I used this item for 10 years. But it cannot be maintained, and there is no documentation. In the end, I used forth to rewrite it. It became much more compact and simple.

My conclusion is that forth is more efficient than machine language. Some of them are due to their interactivity, while others are due to their syntax. One of the most beautiful aspects of forth is that numbers can be expressed in a document using their expressions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.