主菜。没错,日常挂GvR。
```
那么,王垠的见解「深刻」么?我记得王垠曾经在一篇 blog 中《程序语言的常见设计错误(2)》用没有头和多长手批评 Python 语言设计允许每个对象随意添加删除属性。他说「然而你没有想到的是,由于 Python 提供的这种“描述世界的能力”,其它写代码的人制造出各种你想都没想到的怪人。」但是,这真的是程序语言的设计者没有想到的么?恐怕不是,比如这个:Strong versus Weak Typing。Guido 已经解释过,隐式的接口是 Python 的设计目标之一。而王垠批评这个特性最直接的动因,则是他自己说的:「在设计这个静态分析的时候,我发现 Python 的设计让静态分析异常的困难,Python 的程序出了问题很难找到错误的所在,Python 程序的执行速度比大部分程序语言都要慢,这其实是源自 Python 本身的设计问题。」换言之,这个特性让他不满,是因为这个特性让他很难设计静态分析器,虽然他马上将理由引到语言的所谓「设计问题」上。
```
回答里的链接:
http://www.artima.com/intv/strongweak.html不知怎么来着,每次一引用GvR的by design论点,都会让我觉得他是偏执狂+外行(这里除了王垠应该也有很多人黑),都快和James Gosling并列了。
首当其中,GvR作为标榜“通用”语言的设计者,如果真内行,就该明白所谓Strong/Weak根本就是伪命题——因为这两个修饰type system性质的词早在数十年前(反正我记得比这篇引文的时间还要早很多)就因为理解混乱臭掉了,而且比“脚本语言”这种概念混乱程度还严重得多——内行之间背景稍微不同就可能总是鸡同鸭讲——而不只是外行理解正不正确的问题。
对历史名词原意的曲解先不论,总之概念混乱已经是既定事实并且有人明确指出根本没法指望搞清楚是什么意思(仍然详见英文喂鸡)。所以在访谈中放任莫名其妙的概念忽悠大众,就有理由扣外行充内行+装的帽子。
然后,看看引文吧。
```
Bill Venners: I once asked James Gosling about programmer productivity. His answer, which I consider to be the strong-typers view of weak typing, was, "There's a folk theorem out there that systems with very loose typing are very easy to build prototypes with. That may be true. But the leap from a prototype built that way to a real industrial-strength system is pretty vast."
real industrial-strength呵呵呵呵呵……然而暂时懒得挂JG……忍了不跑题。
Bill Venners: Gosling also said, "Anything that tells you about a mistake earlier not only makes things more reliable because you find the bugs, but the time you don't spend hunting bugs is time you can spend doing something else." When I asked Josh Bloch about strong and weak typing, he said, "It's always beneficial to detect programming errors as quickly as possible."
Guido van Rossum: Of course. I'm not arguing with that.
```
GvR在这里似乎萎了(不知是不学无术还是单纯懒得说)。这里提问者的说法不管在PLT还是工程上都明显是有问题的:
1.It's always beneficial to detect programming errors as quickly as possible.和这里所说的strong/weak typeing没有直接联系:不管是strong还是weak,和type checking的时机完全两码事。
2.还真不可能是always。要fail fast算是常见现实需求之一,但是在所谓programming errors的外延都容易鸡同鸭讲(许多语言的用户往往对什么错误改谁负责没概念,再加上该用什么错误处理方式也很混乱)的情况下,一股脑尽量早发现问题不可能是理想状况。即便没有这种逗比现状,难道只管发现不管分散解决造成复用困难和花费的额外成本?更别说可行性了。
```
Bill Venners: Josh Bloch continued, "There's no doubt that you can prototype more quickly in an environment that lets you get away with murder at compile time, but I do think the resulting programs are less robust. I think that to get the most robust programs, you want to do as much static type checking as possible."
That all sounds fine to me in theory. It makes sense that the sooner I find programming errors the better. Strong typing helps me find errors at compile time. Weak typing makes me wait until a runtime exception is thrown. The trouble is that I use Mailman, a mailing list manager written completely in Python. Mailman works fine. It isn't a prototype. It's an application, and it seems quite robust to me. So where does theory miss practice?
Guido van Rossum: That attitude sounds like the classic thing I've always heard from strong-typing proponents. The one thing that troubles me is that all the focus is on the strong typing, as if once your program is type correct, it has no bugs left. Strong typing catches many bugs, but it also makes you focus too much on getting the types right and not enough on getting the rest of the program correct.
```
提问的观点其实大致上没错(虽然实际上需要取舍),而GvR却致命地把static typing和explicit/manifest typing混为一谈了。
这里的错误就像Java厨因为打字少看着不安心或者Rob Pike觉得“类型就是分类”之类的理由拒绝引入type inference一样可笑。虽然Java厨是有意无视而且GvR和Java厨在打字多少的问题上针锋相对,然而无知程度是共通的。
```
All that attention to getting the types right doesn't necessarily mean you don't have other bugs in your program. A type is a narrow piece of information about your data. When you look at large programs that deal with a lot of strong typing, you see that many words are spent working around strong typing.
```
理论上其实有不符合“narrow piece”的情况。只不过这种字面上的这种系统的实用拙计连王垠都看不下去……
不过以现在的角度来看,还是有些新的进展,比如unisonweb.org。照顾某些人可怜的想象力不展开了。
```
The container problem is one issue. It's difficult in a language without generics to write a container implementation that isn't limited to a particular type. And all the strong typing goes out the door the moment you say, "Well, we're just going to write a container of Objects, and you'll have to cast them back to whatever type they really are once you start using them." That means you have even more finger typing, because of all those casts. And you don't have the helpful support of the type system while you're inside your container implementation.
Python doesn't require you to write the cast, and its containers are completely generic. So it has the plus side of generic containers without the downside. It doesn't have the plus side that the C++ folks claim to get with their templates and other generics. But in practice that mechanism turns out to be very cumbersome. Even compiler writers have difficulty getting templates to work correctly and efficiently, and the programmers certainly seem to have a lot of trouble learning how to use it correctly. Templates are a whole new language that has enormous complexity.
```
这里充分暴露了GvR对当时存在的类型系统的理解存在很大欠缺。generics只是避免显式转型的做法之一。(话说Java那时候有伪劣泛型了么……)不管怎么说,C++无视泛型的残废协变是98年就有的事。
(这里要是顺势黑C艹我倒可能还会支持,然而既然没黑那就算了……)