How to design a programming language (11) to subtract the function of a language

Source: Internet
Author: User
Tags abstract anonymous expression

Everyone sees this headline will certainly cheer up, thought the language which the function is few is easy to learn. In fact, this is not the case at all. If there is a wide range of functional languages, all the concepts must be orthogonal and eventually become mathematical. The concept of mathematics is very orthogonal, the orthogonal things are particularly abstract, not intuitive. Don't believe it? Go out and turn left to see Haskell, and abstract algebra. Therefore, the deletion of the language of the function of the need for superb skills, this and everyone think, and go with the people think, can be judged completely different.

First, we need to know why the deletion function is needed. Here we first have to reach a consensus-people are very cheap. On the one hand, the smooth and stately expression of the speech, to change the demand and maintainability of the center, on the other hand, write the code on the other side of the "later defenders pay the price" to lazy. There are times when people are spoiled by language, therefore, the need to cut the function at the same time, but not to reduce the ability to express the language, so that doing bad things become more difficult (completely do not let others do bad things is impossible), so that everyone will tend to write a good structure of the program.

So, the grammatical sugar in the end is not to be deleted object? Obviously not. A good language, using the concept is orthogonal. Although the concept of orthogonal can be used to splice the concept we need to maintain the maintainability and decoupling, but often this is not so comfortable to do, so the need for syntactic sugar. If it is not a grammatical sugar, what exactly should be cut?

In this episode we'll talk about object-oriented language and see what can be removed.

When the object-oriented was just in vogue, everyone is talking about building blocks programming Ah, is-a, has-a These concepts ah, interface-oriented programming Ah, why the hardware is so easy to plug into each other, and then began to engage in COM ah, SOA ah these really make interpolation easier, But it's a very troublesome thing to deploy. What causes OO not to be as useful as it might be?

The reason I think about this is because we recently had a camera tripod on the work station of our institute, which was used to fix a cell phone to do some evil things, so everyone started talking about it-for example, why the phone and the tripod are orthogonal, In the middle, as long as a convex concave after the use of small iron block can be done, and the software is not?

So I was thinking, this is not the same as the so-called interface-oriented programming, as long as you have all the things with the interface, the software is very easy to combine. So even if not right, just write a adaptor, it can be done. In fact, this approach is still very common to us now. For example, there are times when we need Visual C + + 2013, the world's most bunker C + + IDE, to develop the world's best complex software, but the cl.exe is not the best. So what can I do to give up this IDE for a better compiler? Obviously not. The right solution is to buy Intel's ICC, then replace Cl.exe, and then do everything as usual.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/

In fact, the interface-oriented programming is a bit of this meaning. There are times when a system is mostly what you need, and others are not satisfied, but just as an important part of the system you have a better part to replace. Do you choose a better part, or do you choose most of the peripheral tools you need? Why do you have to choose one or two? If everyone is interface-oriented programming, then you just need to change to ICC with Cl.exe, write a adaptor can be on.

Okay, what's the interface? In fact, this is not a profound understanding of the interface refers to the Java and C # inside the interface, is very straightforward. Do not know why later preach this suggestion with some package together, and then a variety of non-object-oriented language to their own parts of the misinterpreted as interface, successfully "interface-oriented programming" into a nonsense.

But before saying interface, there is a simpler but analogous example of a function and a lambda expression. If a language has both a function and a lambda expression, then actually one is redundant-that is, the function. A function can always be defined as initialization when it gives a lambda-expression read-only variable. There is no performance problem here, because the typical notation, the compiler can often identify, and ultimately optimize it into a function. When we use a function name as an expression and get a function pointer, there is no difference between this type and the lambda expression. A function has only two uses, so it actually removes the function, leaving the lambda expression, and the entire language has not changed at all. So the function in this case belongs to the function that can be deleted.

What about class and interface? Similar to the above discussion, I argue that class is also one of the functions that can be cut off, and that programmers will write better code for human nature because of the deletion. There is no difference between the class and the only difference I can think of is that class itself is no longer a type, but a function. Does it matter? Not at all, you can use interface.

The typical difference between class and interface is that all functions in interface are virtual and do not have local variables. Class is not all the functions are virtual--java the default virtual but can be changed, C + + and C # are default but can be changed. Even if you change all the class functions to virtual, you will leave some state variables. What's wrong with that? Suppose the C + + compiler is an interface, and Visual C + + and peripheral tools depend on what this class creates. If you want to replace cl.exe with ICC, you can actually just have a new ICC. And if the C + + compiler is a class, you can't replace it--even if all of the class functions are virtual, you can't give a different icc--because you've been declared by class with constructors, Destructors and some of the written state variables (member variables) have been kidnapped!

So what we can think of is a process that forces everyone to write a program that tends to be more integrated than before, so how can we change the language? In fact, it is very simple, only need not to think of class name as a type, and consider him a function on it. Class itself has multiple constructors, which is actually the meaning. In that case, all the things that were meant to use class, we would define an interface. And this interface tends to be minimized, because there is absolutely no need to declare some functions that are not used.

So, like removing the function and leaving the anonymous function (that is, lambda expression), we can also remove the class and leave the anonymous class. Java has anonymous classes, so we do not feel that this concept is very unfamiliar. So we can check it out and it won't let us lose any expression.

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.