[Translate] Compiler (4)-Language design

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Here's the original. It is also recommended to read Master Wang's "design and develop Yin language" and you will see another completely different language design idea.
———— Translation Divider Line ————

Compiler (4)-Language design

The first part: Introduction
Part II: compilation, Translation and interpretation
Part III: Compiler Design Overview

The first section outlines what this series of articles will cover. In the second to third part of the rough view of the computer language compilation of the various steps.

In this article, it will be a little more detailed than what was described in the previous few overviews. I will discuss the specification of the language.

Language Design Overview

Did I just say I'm not going to have too much of an overview? As soon as I turned around, I became a despicable liar.

To get us into the coding phase faster, I've tried to be brief and concise. I also want to make it clear that this is a very imperfect language design. Computer language design is a topic that you can struggle for a lifetime. I can't provide you with the theory of support design in Calc. I'm not going to discuss that.

In fact, I'll just tell you what the language spec is.

I have to admit that Calc is not a real programming language. Its starting point is to build a basic compiler for teaching, and to use it as a cornerstone of the future version of Calc for future series posts.

Language design is difficult, very difficult. Say "I want this feature, that feature, and the other features." "It's easy. Why? For what purpose? How do I make it match the design? Is it confusing for users? Is it necessary? Who are your target users, and do they want or need this feature?

Cycle

Even with a wealth of experience, these are not easy questions to answer. There are some features, such as a looping structure, that don't seem to be thinking, but really? Take a look at the two most common looping structures: for and while.

Almost all computer languages have designed methods for looping, whether it's a goto statement for jumps or a common for and while loop. Recursion is a loop of another style. But the most popular should be for and while.

The first question, the first one is: Why?

Well, we'd like to repeat some actions. OK, quite simple.

Both for and while require an exit condition to complete. Typically these conditions are associated with logical true and false. Two different ways to write:

while (condition) do {action}

For (start, condition; increment) do {action}

Why? In the beginning, I think the logic of these loops is out of different consideration. However, Go developers see the similarities in the two structures and ask themselves the question: "Why?" ”

Why should there be two keywords, two reserved words to achieve an essentially the same thing? Replacing these two with a looping structure and a unique reserved word may be more complex at the time of analysis, but isn't it better for the end user?

The Go developer chooses the shorter one as the keyword. I also feel that this choice is more intuitive than theoretical support. "for (conditional) do {operation}" is intuitive. By a simple perception that we have been resigned to for a long time, our language becomes simple and clear in an instant. When one can be satisfied, who will use two of them?

Choice

There will always be a choice. Complex or simple. Speed or convenience.

The cost of a circular decision is slightly more complicated when it comes to parsing. The developer consciously chooses to make the For statement parsing more difficult to provide the programmer with significant productivity improvements.

Generics are a hot topic. Go does not provide any features about generics. Why?

Generics are just a trade-off, and I can't explain it to you. You'd better do some research on Golang's mailing list and look at the FAQ.

The end result is that you need to decide what you need. Do you want a simple and mundane language, or a complex language that can do anything? Why did you make such a choice?

A feature that also appears in other languages does not imply that it must exist. The while loop is a pretty good example.

In Go, switch is much more versatile than it does in languages like C. The basic idea is to provide powerful functionality without requiring programmers to add too much cognitive complexity.

Type System

Dynamic or static? Strong type or weak type? Straightforward or implicit?

Personally, I prefer strong type, static language. I want to be sure that I get what I want without any extra action.

Can a type be or should it be converted? Can a floating-point number be an integer? is a character rp a floating point? What is a string?

Do boundary checks on arrays? Where's slice?

Pointer or a variable with a desirable address? is a variable a reference pass or a value pass?

As I said, something that looks very simple can be very, very quickly complicated.

Summarize

I was suddenly filled with respect for many languages. Honestly speaking, I don't like Java. I know the power of it, but it feels like programming with a donkey to write code. That said, but I have to admire the designers. I admire what they have done and done. I have to admire that this may be the best, or the only way, that going back is always an idea. Java works well, and countless programmers are using it. You have to pay tribute to that.

You might make a bad design choice, no matter how smart you think you are. From the beginning of 2011, when I started to focus on the go language, I joined the Go mailing list and witnessed the evolution of the language until 1.0. There have been many debates around language design that will continue in the future. Language design is quite difficult, and your decision will not make everyone happy.

As I said before, language design is a huge topic. I think that many languages become victims of pleasing everyone. Their toolbox is full of overflow. Other languages have drawn an insurmountable line, even when faced with overwhelming evidence of its necessity. Both of these strategies kicked the user away.

You need to decide which faction to choose and why.

Related Article

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.