This article is reproduced from Wang Gen blog, source address: HTTP://WWW.YINWANG.ORG/BLOG-CN/2017/07/06/MASTER-PL, although Wang Gen is a controversial person, this article some places also write some arrogant, However, this article is very good, I am the same view of programming, language is only second, learning to solve the problem of the thinking and language characteristics is the most important.
Right, what I'm going to talk about here is not how to master a programming language, but all the ...
Many programmers are still writing to me to consult, ask me what program language to learn, how to learn. Because I know how to master the "all" of the program language, always feel this kind of learning "a" what the language of the problem is relatively low, so have not had time to reply to their:P but gradually, I found that the original is not only small white people have this problem, even the United States a large number of senior engineers, actually did not understand.
Today I have the motivation, want to unified answer this long-held "primary problem". A similar topic seems to have been written, but now I want to write it again. Because after interacting with a lot of people, I have a more precise expression of my thoughts in my head.
If you have any of the following puzzles, this article might help you:
你是编程初学者,不知道该选择什么程序语言来入门。你是资深的程序员或者团队领导,对新出现的种种语言感到困惑,不知道该“投资”哪种语言。你的团队为使用哪种程序语言争论不休,发生各种宗教斗争。你追逐潮流采用了某种时髦的语言,结果两个月之后发现深陷泥潭,痛苦不堪……
Although I am no longer involved in these things, the reality is that procedural language is still a very important topic, and this situation will not change in a short time. Programmers ' positions often require familiarity with certain languages, and even some exotic companies require you to "delve into OOP or FP design patterns." For working programmers, the language of the program is still a hotly-heated religious topic. It's so religious that when I criticize and ridicule certain languages (such as the Go language), some people instinctively think I'm a fan of another language (like Java).
Obviously I can't be a fan of any language, I'm not even a fan of the Yin language;) For any language I've never seen before, I use it directly, without having to go through the process of learning. Read this article, maybe you will understand why I can achieve this effect. Understanding what's inside, every programmer should be able to do it. Well, let's hope so.
Focus on language characteristics, not language
Many people care about themselves or others whether "will" a language, the "invention" of a language of the people to worship, for a variety of languages, the pros and cons of the red. These questions don't exist for me. Although I have written articles criticizing a lot of language flaws, I seldom argue with people in practical work. If there were other people arguing with me, I would even wear headphones and not listen to what they were saying;) Why is it? I find that the bottom line is that I value the "language trait" rather than the whole "language". I can write good code in any language, even if the bad language is not much worse.
Any "language" is a combination of various "language features". For example, a programming language is like a computer. Its brand may be called "Lenovo", or "IBM", or "Dell", or "apple". So, can you say that Apple must be better than IBM? You can't. You have to see what type of processor it contains, how many cores it has, how much it is, how many L1 cache,l2 cache ..., how much memory and hard drives, how big the display resolution, what GPU, Nic speed, etc. "Configuration". Sometimes you have to look at the compatibility between the various components.
These configurations correspond to the language of the program, which is called "language features". Cite some examples of language features:
变量定义算术运算for 循环语句,while 循环语句函数定义,函数调用递归静态类型系统类型推导lambda 函数面向对象垃圾回收指针算术goto 语句
These language features, like when you're choosing a computer, look at what's in it. When choosing a computer, no one would say that Dell must be the best, they will only say that this model is installed in the Intel i7 processor, this is better than i5, DDR3 memory is faster than DDR2, SSD much faster than disk, ATI graphics card is garbage ... And so on
The same is true of programming languages. For beginners, there is no need to dwell on which language to learn first, and what to learn. I was sent a letter to ask this question, tangled for several weeks, the result of a language has not yet begun to learn. With this tangled time, in fact, all of his tangled language can be mastered.
Beginners often do not understand that each language must have a "universal" characteristics. such as variables, functions, integers and floating-point arithmetic, and so on. These are all common programming languages must have, one can not be less. You can apply this knowledge to any other language at any time by learning these traits through "a language" and mastering the underlying concepts of these features. The time you spend on it is basically not wasted. So beginners struggle to "learn what kind of language first", this time spent is not worth, it is better to pick a language, jump in.
If you can't write good code with the basic features of a language, it doesn't help if you switch to another language. You'll write the same bad code. I often see some people Java code is quite messy, rather bad, but scold Java bad, ambitious to switch to the Go language. These people do not understand that the ability to write good code is human, not language. If you don't have a clear, simple thinking model in your mind, you can express it in any language as a bunch of mess. If your Java code is poorly written, it will be as bad or worse for you to write the Go language code.
Many beginners do not understand that if a smart programmer begins to use a new programming language, he is often not going to see a large manual or book in the language, but rather a problem that needs to be solved first. With a problem at hand, he could take a two-minute look at the language handbook and see what the language looks like. Then he picks up an example code to start tinkering with the idea of changing the code to the problem he's trying to solve. In this brief process, he quickly mastered the language and used it to express his mind.
In the process, as the need arises, he may ask questions such as:
这个语言的“变量定义”是什么语法,需要“声明类型”吗,还是可以用“类型推导”?它的“类型”是什么语法?是否支持“泛型”?泛型的 “variance” 如何表达?这个语言的“函数”是什么语法,“函数调用”是什么语法,可否使用“缺省参数”?……
Have you noticed? The contents of each quotation mark above are a linguistic feature (or concept). These concepts can exist in any language, and although the syntax may be different, they are essentially the same. For example, some language parameter types are written in front of variables, some are written later, some are separated by a colon, and some are not.
These practical problems are the actual code, to solve the problem at hand, naturally brought out, rather than the beginning to hold the language manual to see carefully. Because people who have mastered the characteristics of language know that they need the characteristics, in any language there must be a corresponding way of expression. If there is no direct way to express, then there must be some kind of "bypass way". If there is a direct expression, then it is only a slightly different syntax. So, he was looking for a character with a problem, just like a dictionary, rather than being drowned in a voluminous handbook, and was sleepy for one months before he began to write code.
Mastering the Universal language features, the rest is only some of the language "unique" features. People who study language know that it is very difficult to design new, good, harmless properties. So generally speaking, a good language, its unique new features, after all, no more than one or two kinds. If there is a language claiming to have more than 5 new features, then you have to be careful because they bring and may not be an advantage, but a disaster!
In the same way, the best language researchers are often not the designers of a language, but rather the designers (or supporters) of some key language features. For example, Dijkstra, a well-known computer scientist, is a strong supporter of "recursion". There are recursion in the language now, but you may not know that the early programming language does not support recursion. The situation changed until Dijkstra strongly demanded that the Algol 60 committee join the support for recursion. Tony Hoare is also a language feature designer. He has designed several important language features, but has not designed any language. And let's not forget that there is a language expert named Wang Yin, who is a supporter and a checked of the early union type, and a supporter of the exception feature, who in his own it points out the relationship between the checked exception and the union type: P
Many people blindly worship language designers, as long as they hear someone design (or the United States their people said "invented") a language, the blood boiling, admire the pleasantly surprised. They did not understand that, in fact, all the programming language, just like Dell, Lenovo's "Assembly machine." The designer of language features is the creator of the core technology like Intel,amd,arm,qualcomm.
A reasonable introductory language
So if beginners want to do more with less, they should start with a kind of "reasonable", no obvious serious problem language, grasp the most critical language characteristics, and then apply these concepts to other languages. What are the reasonable introductory languages? I personally think these languages can be used to get started:
SchemeCJavaPythonJavaScript
So in contrast, what languages do I not recommend to get started?
ShellPowerShellAWKPerlPHPBasicGoRust
In general, you should not use the so-called "scripting language" as a starting language, especially for scripting language tools that originate from early Unix systems. Although PowerShell has progressed more than the Unix Shell, it still does not get rid of the fundamental problem of scripting languages-their designers don't know what they're doing:P
In scripting language programming, a very serious problem is to make learners unable to grasp the key. Scripting languages tend to add things like regular expressions and Web concepts to the syntax of some system tools, causing beginners to waste too much time on them, without understanding the most critical concepts of programming: variables, Functions, recursion, types ...
The reason why the go language is not recommended is similar, although the go language is not a scripting language, but his designers obviously do not understand what they are doing. So using the Go language to learn programming, you can't focus on the most critical, best language features. You can refer to this article for a variety of problems with the Go language.
Similarly, I don't think Rust fits as an introductory language. Rust has spent too much time bragging about its "new features", which are not the most critical ones, and many are problematic. Beginners ' early attention to these features will not only learn the most critical programming ideas, but may also go astray. You can refer to this article for a few questions about Rust.
Mastering key language features, ignoring minor features
To achieve the follow effect that I mentioned earlier, beginners should focus on the most critical features of the language, rather than being distracted by secondary features.
Give an example of exaggeration. I have found many programming courses and the introduction of the Pheasant College programming classes, often to teach students how to use printf to print "Hello world! In turn, they want to remember the meaning of the various "format characters" of printf, to enable them to print out a variety of complex formats, even to print to a text file, and then read it ...
But as everyone knows, this output input operation is not really part of the language, and for mastering the core concept of programming, are secondary. Some people have been working on the Java course for several weeks and are still laying out various printf assignments. Students write hundreds of lines of printf, but do not understand what variables and functions are, even arithmetic statements and loop statements do not know how to use! This is why many beginners feel that programming is difficult, I even%d,%f,%.2f the meaning of can't remember, how to learn programming!
However, these pheasant University "Professor" title is so brainwashed, so that they taught students (such as my girlfriend) to my here to consult, actually scold me to teach some useless things, learned that even printf's homework can not be completed:P you don't tell me about the For loop, function or something ... Can wait a few months, and so I learned the usage of printf to learn those ah?
So you'll find that once you've been taught by a lousy teacher, the programmer is basically ruined. Even if you meet a good teacher, they will be hard to correct.
This is, of course, an exaggeration, because printf is not a language feature at all, but this example illustrates the problem of secondary superficial linguistic features from the same perspective.
Here are some examples of minor language features:
C 语言的语句块,如果里面只有一条语句,可以不打花括号。Go 语言的函数参数类型如果一样可以合并在一起写,比如 func foo(s string, x, y, z int, c bool) { ... }Perl 把正则表达式作为语言的一种特殊语法JavaScript 语句可以在某些时候省略句尾的分号Haskell 和 ML 等语言的 currying
Implement your own language features with your own hands
After the basic learning of various language features, which can be used to write code, the next step is to implement them. Only by implementing a variety of language features can you fully own them and become masters of them. Otherwise you are just their users, and you will be led by the language designer to take the nose.
A master said well, the best way to fully understand a language is to do it yourself, that is, to write an interpreter to implement its semantics. But I think this sentence should be slightly modified: the best way to fully understand a "language feature" is to implement it yourself.
Note that I have changed "language" to "language feature" here. You don't need to implement the whole language to do this, because we end up using language features. As long as you implement a language feature yourself, you can understand how and how this feature is implemented in any language.
For example, when learning SICP, everyone will personally use Scheme to implement an object-oriented system. The object-oriented system implemented with Scheme is a far cry from language syntax such as Java,c++,python, but it can help you understand the concept of "object-oriented" in any of these OOP languages, and it can even help you understand the differences in the various object-oriented implementations.
This effect is that you directly learn the OOP language can not get, because in learning Java,c++,python language, you are only a user, and use Scheme to implement the OO system yourself, you become a creator.
Similar features include type derivation, type checking, lazy evaluation, and so on. I have achieved almost all of the language features, so any language in front of me, can be arbitrarily disassembled assembly of toys, and no longer is above me the sacred.
Summarize
Write so many, important words repeat three times: language features, language features, language features, language features! Both beginners and senior programmers should focus on language features rather than on the entire "language brand". Only in this way can we achieve mastery, pick up any language almost immediately will be used, and write high-quality code.
The most tangled thing for beginners. What is the best language to learn? What language has a future (or Qiantu)?