[转载] 如何掌握所有的程序语言 —— 王垠([reprint] how to master all programming languages — Wang Yin)

最近在学习 Java,因为有了 C++ 的基础,学起来很快,不到一周时间就能熟练使用 Java 面向对象、泛型(模板)、反射、异常、集合、多线程,突然想起王垠的这篇文章。

最近在学习 Java,因为有了 C++ 的基础,学起来很快,不到一周时间就能熟练使用 Java 面向对象、泛型(模板)、反射、异常、集合、多线程,突然想起王垠的这篇文章。

对的,我这里要讲的不是如何掌握一种程序语言,而是所有的……

很多编程初学者至今还在给我写信请教,问我该学习什么程序语言,怎么学习。由于我知道如何掌握“所有”的程序语言,总是感觉这种该学“一种”什么语言的问题比较低级,所以一直没来得及回复他们 可是逐渐的,我发现原来不只是小白们有这个问题,就连美国大公司的很多资深工程师,其实也没搞明白。

今天我有动力了,想来统一回答一下这个搁置已久的“初级问题”。类似的话题貌似曾经写过,然而现在我想把它重新写一遍。因为在跟很多人交流之后,我对自己头脑中的(未转化为语言的)想法,有了更精准的表达。

如果你存在以下的种种困惑,那么这篇文章也许会对你有所帮助:

  • 你是编程初学者,不知道该选择什么程序语言来入门。
  • 你是资深的程序员或者团队领导,对新出现的种种语言感到困惑,不知道该“投资”哪种语言。
  • 你的团队为使用哪种程序语言争论不休,发生各种宗教斗争。
  • 你追逐潮流采用了某种时髦的语言,结果两个月之后发现深陷泥潭,痛苦不堪……

虽然我已经不再过问这些世事,然而无可置疑的现实是,程序语言仍然是很重要的话题,这个情况短时间内不会改变。程序员的岗位往往会要求熟悉某些语言,甚至某些奇葩的公司要求你“深入理解 OOP 或者 FP 设计模式”。对于在职的程序员,程序语言至今仍然是可以争得面红耳赤的宗教话题。它的宗教性之强,以至于我在批评和调侃某些语言(比如 Go 语言)的时候,有些人会本能地以为我是另外一种语言(比如 Java)的粉丝。

显然我不可能是任何一种语言的粉丝,我甚至不是 Yin 语言的粉丝 对于任何从没见过的语言,我都是直接拿起来就用,而不需要经过学习的过程。看了这篇文章,也许你会明白我为什么可以达到这个效果。理解了这里面的东西,每个程序员都应该可以做到这一点。嗯,但愿吧。

重视语言特性,而不是语言

很多人在乎自己或者别人是否“会”某种语言,对“发明”了某种语言的人倍加崇拜,为各种语言的孰优孰劣争得面红耳赤。这些问题对于我来说都是不存在的。虽然我写文章批评过不少语言的缺陷,在实际工作中我却很少跟人争论这些。如果有其它人在我身边争论,我甚至会戴上耳机,都懒得听他们说什么 为什么呢?我发现归根结底的原因,是因为我重视的是“语言特性”,而不是整个的“语言”。我能用任何语言写出不错的代码,就算再糟糕的语言也差不了多少。

任何一种“语言”,都是各种“语言特性”的组合。打个比方吧,一个程序语言就像一台电脑。它的牌子可能叫“联想”,或者“IBM”,或者“Dell”,或者“苹果”。那么,你可以说苹果一定比 IBM 好吗?你不能。你得看看它里面装的是什么型号的处理器,有多少个核,主频多少,有多少 L1 cache,L2 cache……,有多少内存和硬盘,显示器分辨率有多大,显卡是什么 GPU,网卡速度,等等各种“配置”。有时候你还得看各个组件之间的兼容性。

这些配置对应到程序语言里面,就是所谓“语言特性”。举一些语言特性的例子:

  • 变量定义
  • 算术运算
  • for 循环语句,while 循环语句
  • 函数定义,函数调用
  • 递归
  • 静态类型系统
  • 类型推导
  • lambda 函数
  • 面向对象
  • 垃圾回收
  • 指针算术
  • goto 语句

这些语言特性,就像你在选择一台电脑的时候,看它里面是什么配置。选电脑的时候,没有人会说 Dell 一定是最好的,他们只会说这个型号里面装的是 Intel 的 i7 处理器,这个比 i5 的好,DDR3 的内存 比 DDR2 的快这么多,SSD 比磁盘快很多,ATI 的显卡是垃圾…… 如此等等。

程序语言也是一样的道理。对于初学者来说,其实没必要纠结到底要先学哪一种语言,再学哪一种。曾经有人给我发信问这种问题,纠结了好几个星期,结果一个语言都还没开始学。有这纠结的时间,其实都可以把他纠结过的语言全部掌握了。

初学者往往不理解,每一种语言里面必然有一套“通用”的特性。比如变量,函数,整数和浮点数运算,等等。这些是每个通用程序语言里面都必须有的,一个都不能少。你只要通过“某种语言”学会了这些特性,掌握这些特性的根本概念,就能随时把这些知识应用到任何其它语言。你为此投入的时间基本不会浪费。所以初学者纠结要“先学哪种语言”,这种时间花的很不值得,还不如随便挑一个语言,跳进去。

如果你不能用一种语言里面的基本特性写出好的代码,那你换成另外一种语言也无济于事。你会写出一样差的代码。我经常看到有些人 Java 代码写得相当乱,相当糟糕,却骂 Java 不好,雄心勃勃要换用 Go 语言。这些人没有明白,是否能写出好的代码在于人,而不在于语言。如果你的心中没有清晰简单的思维模型,你用任何语言表述出来都是一堆乱麻。如果你 Java 代码写得很糟糕,那么你写 Go 语言代码也会一样糟糕,甚至更差。

很多初学者不了解,一个高明的程序员如果开始用一种新的程序语言,他往往不是去看这个语言的大部头手册或者书籍,而是先有一个需要解决的问题。手头有了问题,他可以用两分钟浏览一下这语言的手册,看看这语言大概长什么样。然后,他直接拿起一段例子代码来开始修改捣鼓,想法把这代码改成自己正想解决的问题。在这个简短的过程中,他很快的掌握了这个语言,并用它表达出心里的想法。

在这个过程中,随着需求的出现,他可能会问这样的问题:

  • 这个语言的“变量定义”是什么语法,需要“声明类型”吗,还是可以用“类型推导”?
  • 它的“类型”是什么语法?是否支持“泛型”?泛型的 “variance” 如何表达?
  • 这个语言的“函数”是什么语法,“函数调用”是什么语法,可否使用“缺省参数”?
  • ……

注意到了吗?上面每一个引号里面的内容,都是一种语言特性(或者叫概念)。这些概念可以存在于任何的语言里面,虽然语法可能不一样,它们的本质都是一样的。比如,有些语言的参数类型写在变量前面,有些写在后面,有些中间隔了一个冒号,有些没有。

这些实际问题都是随着写实际的代码,解决手头的问题,自然而然带出来的,而不是一开头就抱着语言手册看得仔仔细细。因为掌握了语言特性的人都知道,自己需要的特性,在任何语言里面一定有对应的表达方式。如果没有直接的方式表达,那么一定有某种“绕过方式”。如果有直接的表达方式,那么它只是语法稍微有所不同而已。所以,他是带着问题找特性,就像查字典一样,而不是被淹没于大部头的手册里面,昏昏欲睡一个月才开始写代码。

掌握了通用的语言特性,剩下的就只剩某些语言“特有”的特性了。研究语言的人都知道,要设计出新的,好的,无害的特性,是非常困难的。所以一般说来,一种好的语言,它所特有的新特性,终究不会超过一两种。如果有个语言号称自己有超过 5 种新特性,那你就得小心了,因为它们带来的和可能不是优势,而是灾难!

同样的道理,最好的语言研究者,往往不是某种语言的设计者,而是某种关键语言特性的设计者(或者支持者)。举个例子,著名的计算机科学家 Dijkstra 就是“递归”的强烈支持者。现在的语言里面都有递归,然而你可能不知道,早期的程序语言是不支持递归的。直到 Dijkstra 强烈要求 Algol 60 委员会加入对递归的支持,这个局面才改变了。Tony Hoare 也是语言特性设计者。他设计了几个重要的语言特性,却没有设计过任何语言。另外大家不要忘了,有个语言专家叫王垠,他是早期 union type 的支持者和实现者,也是 checked exception 特性的支持者,他在自己的博文里指出了 checked exception 和 union type 之间的关系

很多人盲目的崇拜语言设计者,只要听到有人设计(或者美其民曰“发明”)了一个语言,就热血沸腾,佩服的五体投地。他们却没有理解,其实所有的程序语言,不过是像 Dell,联想一样的“组装机”。语言特性的设计者,才是像 Intel,AMD,ARM,Qualcomm 那样核心技术的创造者。

合理的入门语言

所以初学者要想事半功倍,就应该从一种“合理”的,没有明显严重问题的语言出发,掌握最关键的语言特性,然后由此把这些概念应用到其它语言。哪些是合理的入门语言呢?我个人觉得这些语言都可以用来入门:

  • Scheme
  • C
  • Java
  • Python
  • JavaScript

那么相比之下,我不推荐用哪些语言入门呢?

  • Shell
  • PowerShell
  • AWK
  • Perl
  • PHP
  • Basic
  • Go
  • Rust

总的说来,你不应该使用所谓“脚本语言”作为入门语言,特别是那些源于早期 Unix 系统的脚本语言工具。PowerShell 虽然比 Unix 的 Shell 有所进步,然而它仍然没有摆脱脚本语言的根本问题——他们的设计者不知道他们自己在干什么

采用脚本语言学编程,一个很严重的问题就是使得学习者抓不住关键。脚本语言往往把一些系统工具性质的东西(比如正则表达式,Web 概念)加入到语法里面,导致初学者为它们浪费太多时间,却没有理解编程最关键的概念:变量,函数,递归,类型……

不推荐 Go 语言的原因类似,虽然 Go 语言不算脚本语言,然而他的设计者显然不明白自己在干什么。所以使用 Go 语言来学编程,你不能专注于最关键,最好的语言特性。关于 Go 语言的各种毛病,你可以参考这篇文章。

同样的,我不觉得 Rust 适合作为入门语言。Rust 花了太大精力来夸耀它的“新特性”,而这些新特性不但不是最关键的部分,而且很多是有问题的。初学者过早的关注这些特性,不仅学不会最关键的编程思想,而且可能误入歧途。关于 Rust 的一些问题,你可以参考这篇文章。

掌握关键语言特性,忽略次要特性

为了达到我之前提到的融会贯通,一通百通的效果,初学者应该专注于语言里面最关键的特性,而不是被次要的特性分心。

举个夸张点的例子。我发现很多编程培训班和野鸡大学的编程入门课,往往一来就教学生如何使用 printf 打印“Hello World!”,进而要他们记忆 printf 的各种“格式字符”的意义,要他们实现各种复杂格式的打印输出,甚至要求打印到文本文件里,然后再读出来……

可是殊不知,这种输出输入操作其实根本不算是语言的一部分,而且对于掌握编程的核心概念来说,都是次要的。有些人的 Java 课程进行了好几个星期,居然还在布置各种 printf 的作业。学生写出几百行的 printf,却不理解变量和函数是什么,甚至连算术语句和循环语句都不知道怎么用!这就是为什么很多初学者感觉编程很难,我连 ,, 的含义都记不住,还怎么学编程!

%d
%f
%.2f

然而这些野鸡大学的“教授”头衔是如此的洗脑,以至于被他们教过的学生(比如我女朋友)到我这里请教,居然骂我净教一些没用的东西,学了连 printf 的作业都没法完成 你别跟我讲 for 循环,函数什么的了…… 可不可以等几个月,等我背熟了 printf 的用法再学那些啊?

所以你就发现一旦被差劲的老师教过,这个程序员基本就毁了。就算遇到好的老师,他们也很难纠正过来。

当然这是一个夸张的例子,因为 printf 根本不算是语言特性,但这个例子从同样的角度说明了次要肤浅的语言特性带来的问题。

这里举一些次要语言特性的例子:

  • C 语言的语句块,如果里面只有一条语句,可以不打花括号。
  • Go 语言的函数参数类型如果一样可以合并在一起写,比如 func foo(s string, x, y, z int, c bool) { … }
  • Perl 把正则表达式作为语言的一种特殊语法
  • JavaScript 语句可以在某些时候省略句尾的分号
  • Haskell 和 ML 等语言的 currying

自己动手实现语言特性

在基本学会了各种语言特性,能用它们来写代码之后,下一步的进阶就是去实现它们。只有实现了各种语言特性,你才能完全地拥有它们,成为它们的主人。否则你就只是它们的使用者,你会被语言的设计者牵着鼻子走。

有个大师说得好,完全理解一种语言最好的方法就是自己动手实现它,也就是自己写一个解释器来实现它的语义。但我觉得这句话应该稍微修改一下:完全理解一种“语言特性”最好的方法就是自己亲自实现它。

注意我在这里把“语言”改为了“语言特性”。你并不需要实现整个语言来达到这个目的,因为我们最终使用的是语言特性。只要你自己实现了一种语言特性,你就能理解这个特性在任何语言里的实现方式和用法。

举个例子,学习 SICP 的时候,大家都会亲自用 Scheme 实现一个面向对象系统。用 Scheme 实现的面向对象系统,跟 Java,C++,Python 之类的语言语法相去甚远,然而它却能帮助你理解任何这些 OOP 语言里面的“面向对象”这一概念,它甚至能帮助你理解各种面向对象实现的差异。

这种效果是你直接学习 OOP 语言得不到的,因为在学习 Java,C++,Python 之类语言的时候,你只是一个用户,而用 Scheme 自己动手实现了 OO 系统之后,你成为了一个创造者。

类似的特性还包括类型推导,类型检查,惰性求值,如此等等。我实现过几乎所有的语言特性,所以任何语言在我的面前,都是可以被任意拆卸组装的玩具,而不再是凌驾于我之上的神圣。

总结

写了这么多,重要的话重复三遍:语言特性,语言特性,语言特性,语言特性!不管是初学者还是资深程序员,应该专注于语言特性,而不是纠结于整个的“语言品牌”。只有这样才能达到融会贯通,拿起任何语言几乎立即就会用,并且写出高质量的代码。

原文地址:http://www.yinwang.org/blog-cn/2017/07/06/master-pl

————————

Recently, I was learning Java. Because I had the foundation of C + +, I learned it quickly. I could skillfully use java object-oriented, generic (template), reflection, exception, collection and multithreading in less than a week. I suddenly remembered this article by Wang Yin.

Recently, I was learning Java. Because I had the foundation of C + +, I learned it quickly. I could skillfully use java object-oriented, generic (template), reflection, exception, collection and multithreading in less than a week. I suddenly remembered this article by Wang Yin.

Yes, what I want to talk about here is not how to master a programming language, but all

Many programming beginners are still writing to me for advice, asking me what programming language to learn and how to learn. Because I know how to master “all” programming languages, I always feel that the problem of what language to learn is relatively low, so I haven’t had time to reply to them, but gradually, I found that not only Xiaobai have this problem, but also many senior engineers of large American companies don’t understand it.

Today, I have the motivation to answer this “primary question” that has been shelved for a long time. A similar topic seems to have been written before, but now I want to write it again. Because after communicating with many people, I have a more accurate expression of the ideas in my mind (not translated into language).

If you have the following puzzles, this article may help you:

  • You are a beginner in programming. You don’t know what programming language to choose to get started.
  • As a senior programmer or team leader, you are confused about the emerging languages and don’t know which language to “invest”.
  • Your team is arguing about which programming language to use, and there are various religious struggles.
  • You follow the trend and use some fashionable language. Two months later, you find yourself in a deep quagmire and miserable

Although I have stopped asking about these things, there is no doubt that the reality is that programming language is still a very important topic, which will not change in a short time. Programmers often require familiarity with some languages, and even some wonderful companies require you to “deeply understand OOP or FP design patterns”. For on-the-job programmers, programming language is still a religious topic that can win a red face. It is so religious that when I criticize and ridicule some languages (such as go language), some people instinctively think I am a fan of another language (such as Java).

Obviously, I can’t be a fan of any language. I’m not even a fan of Yin language. For any language I’ve never seen, I just pick it up and use it without learning. After reading this article, you may understand why I can achieve this effect. Understanding what’s inside, every programmer should be able to do this. Well, I hope so.

Pay attention to language characteristics, not language

Many people care about whether they or others “can” a language, worship the people who “invented” a language, and fight for the advantages and disadvantages of various languages. These problems do not exist for me. Although I have written articles criticizing many language defects, I seldom argue with people in practical work. If others argue around me, I even wear headphones and don’t bother to listen to them. Why? In the final analysis, I find that the reason is that I pay attention to “language characteristics” rather than the whole “language”. I can write good code in any language, no matter how bad the language is.

Any “language” is a combination of various “language characteristics”. For example, a programming language is like a computer. Its brand may be “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 is installed in it, how many cores, how many dominant frequencies, how many L1 cache, L2 cache… How many memory and hard disk are there, how large the resolution of the display is, what the graphics card is, GPU, network card speed, and so on. Sometimes you have to look at the compatibility between components.

These configurations correspond to the program language, which is the so-called “language features”. Give some examples of language features:

  • Variable definition
  • Arithmetic operation
  • For loop statement, while loop statement
  • Function definition
  • recursion
  • Static type system
  • Type derivation
  • lambda 函数
  • object-oriented
  • garbage collection
  • pointer arithmetic
  • goto 语句

These language features are like looking at the configuration of a computer when you choose it. When choosing a computer, no one will say that Dell must be the best. They will only say that this model is equipped with Intel’s i7 processor, which is better than i5, DDR3’s memory is so much faster than DDR2, SSD is much faster than disk, ATI’s graphics card is garbage… And so on.

The same is true for programming languages. For beginners, there is no need to struggle with which language to learn first and then which. Someone once sent me a letter asking this question. I struggled for several weeks. As a result, I haven’t started learning any language. With this tangled time, he can actually master all the tangled languages.

Beginners often don’t understand. Every language must have a set of “universal” features. Such as variables, functions, integer and floating-point operations, and so on. These are necessary in every general programming language, and none of them can be missing. As long as you learn these characteristics through “a language” and master the basic concepts of these characteristics, you can apply this knowledge to any other language at any time. The time you invest in this will hardly be wasted. So beginners struggle to “learn which language first”. This time is not worth it. It’s better to choose a language and jump in.

If you can’t write good code with the basic features of one language, it won’t help you to change to another language. You can write the same bad code. I often see some people who write java code in a mess and terrible way, but scold Java for being bad and ambitious to change to go language. These people don’t understand that whether they can write good code depends on people, not language. If you don’t have a clear and simple thinking model in your heart, you will be a mess in any language. If you write java code badly, you write go code just as badly, or even worse.

Many beginners don’t understand that if a good programmer starts to use a new programming language, he often doesn’t read most manuals or books of the language, but has a problem to be solved first. If he has a problem at hand, he can browse the manual of the language in two minutes to see what the language looks like. Then, he directly picked up a piece of example code and began to modify it, trying to change the code into the problem he was trying to solve. In this short process, he quickly mastered the language and expressed his thoughts with it.

In this process, with the emergence of requirements, he may ask such questions:

  • What is the syntax of “variable definition” in this language, does it need to “declare type”, or can it use “type derivation”?
  • What is its “type” syntax? Do you support generics? How to express the “variance” of a generic type?
  • What is the syntax of “function” and “function call” in this language? Can I use “default parameters”?
  • ……

Did you notice? The content in each quotation mark above is a language feature (or concept). These concepts can exist in any language. Although the grammar may be different, their essence is the same. For example, the parameter types of some languages are written in front of variables, some in the back, some with a colon in the middle, and some without.

These practical problems are brought out naturally as you write actual code and solve the problem at hand, rather than reading carefully with the language manual at the beginning. Because people who have mastered the characteristics of language know that the characteristics they need must have corresponding expressions in any language. If there is no direct way of expression, there must be some “bypass way”. If there is a direct expression, it is only slightly different in grammar. Therefore, he looked for features with problems, just like looking up a dictionary, rather than being submerged in most manuals and sleepy for a month before he began to write code.

After mastering the common language features, there are only some “unique” features of the language. People who study language know that it is very difficult to design new, good and harmless features. Therefore, generally speaking, a good language will not have more than one or two unique new features after all. If a language claims to have more than five new features, you have to be careful, because they may not bring advantages, but disasters!

Similarly, the best language researchers are often not the designers of a language, but the designers (or supporters) of key language features. For example, the famous computer scientist Dijkstra is a strong supporter of “recursion”. Today’s languages have recursion, but you may not know that early programming languages did not support recursion. This situation did not change until Dijkstra strongly asked the Algol 60 committee to support recursion. Tony Hoare is also a language feature designer. He designed several important language features, but he never designed any language. In addition, let’s not forget that there is a language expert named Wang Yin. He is a supporter and implementer of early union type and a supporter of checked exception feature. He pointed out the relationship between checked exception and union type in his blog post

Many people blindly worship language designers. As long as they hear that someone has designed (or American people say “invented”) a language, they will be excited and admire. They didn’t understand that in fact, all the programming languages are just “assembly machines” like Dell and Lenovo. The designer of language features is the creator of core technologies such as Intel, AMD, arm and Qualcomm.

Reasonable entry language

Therefore, if beginners want to get twice the result with half the effort, they should start from a “reasonable” language without obvious serious problems, master the most key language characteristics, and then apply these concepts to other languages. What are reasonable entry languages? I personally think these languages can be used to get started:

  • Scheme
  • C
  • Java
  • Python
  • JavaScript

In contrast, which languages do I not recommend for getting started?

  • Shell
  • PowerShell
  • AWK
  • Perl
  • PHP
  • Basic
  • Go
  • Rust

Generally speaking, you should not use the so-called “scripting language” as an entry language, especially those scripting language tools derived from early UNIX systems. Although PowerShell is better than UNIX shell, it still doesn’t get rid of the fundamental problem of scripting language – their designers don’t know what they are doing

A very serious problem in using script linguistics programming is that learners can’t grasp the key. Scripting languages often add some things of the nature of system tools (such as regular expressions and web concepts) to the grammar, resulting in beginners wasting too much time for them, but they do not understand the key concepts of programming: variables, functions, recursion, types

The reason why go language is not recommended is similar. Although go language is not a scripting language, its designers obviously don’t understand what they are doing. So when you use go to learn programming, you can’t focus on the most critical and best language features. You can refer to this article about the problems of go language.

Similarly, I don’t think rust is suitable as an entry language. Rust has spent too much energy bragging about its “new features”, and these new features are not the most critical part, but many of them are problematic. If beginners pay attention to these features too early, they will not only fail to learn the most critical programming ideas, but may go astray. For some questions about rust, you can refer to this article.

Master key language features and ignore secondary features

In order to achieve the comprehensive and versatile effect I mentioned earlier, beginners should focus on the most critical features of the language rather than being distracted by secondary features.

Take an exaggerated example. I found that many programming training courses and introductory programming courses at pheasant university often teach students how to print “Hello world!” using printf, Then they are asked to remember the meaning of various “format characters” of printf, to realize the printout of various complex formats, and even to print into a text file, and then read it again

However, as everyone knows, this output and input operation is not a part of the language at all, and it is secondary to mastering the core concepts of programming. Some people’s Java courses have been going on for weeks, and they are still arranging various printf assignments. Students write hundreds of lines of printf, but they don’t understand what variables and functions are. They don’t even know how to use arithmetic statements and loop statements! This is why many beginners feel that programming is difficult. I can’t even remember the meaning of,, and how to learn programming!

%d
%f
%.2f

However, the “Professor” titles of these pheasant universities are so brainwashed that the students they have taught (such as my girlfriend) come to me for advice and accuse me of teaching useless things and learning printf homework. Don’t tell me about the for cycle and the number of functions… Can you wait a few months, I’ll learn that when I memorize the usage of printf?

So you find that once taught by a bad teacher, the programmer is basically destroyed. Even if they meet good teachers, it is difficult for them to correct them.

Of course, this is an exaggerated example, because printf is not a language feature at all, but this example illustrates the problems caused by the secondary superficial language feature from the same perspective.

Here are some examples of secondary language features:

  • For the statement block of C language, if there is only one statement in it, curly braces can be omitted.
  • If the function parameter types of go language are the same, they can be combined and written together, such as func foo (s string, x, y, Z, int, C bool) {…}
  • Perl takes regular expressions as a special syntax of the language
  • JavaScript statements can omit semicolons at the end of sentences at certain times
  • Haskell 和 ML 等语言的 currying

Do it yourself language features

After basically learning various language features and being able to write code with them, the next step is to implement them. Only by realizing various language features can you fully own them and become their master. Otherwise, you are just their user, and you will be led by the designer of the language.

A master said well that the best way to fully understand a language is to implement it yourself, that is, to write an interpreter to realize 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 change “language” to “language characteristics” here. You don’t need to implement the whole language to achieve this, because we end up using language features. As long as you implement a language feature yourself, you can understand how it is implemented and used in any language.

For example, when learning SiCp, everyone will personally implement an object-oriented system with scheme. The object-oriented system implemented with scheme is far from the syntax of languages such as Java, C + +, python. However, it can help you understand the concept of “Object-Oriented” in any OOP language, and it can even help you understand the differences of various object-oriented implementations.

You can’t get this effect by directly learning OOP language, because when you learn languages such as Java, C + +, python, you are just a user, and after you implement the OO system yourself with scheme, you become a creator.

Similar features include type derivation, type checking, lazy evaluation, and so on. I have realized almost all the language features, so any language in front of me is a toy that can be disassembled and assembled at will, and is no longer sacred above me.

summary

After writing so many important words, repeat them three times: language characteristics, language characteristics, language characteristics, language characteristics! Whether beginners or senior programmers, they should focus on language features rather than the whole “language brand”. Only in this way can we achieve mastery, pick up any language almost immediately, and write high-quality code.

原文地址:http://www.yinwang.org/blog-cn/2017/07/06/master-pl