techsir 登陆 |注册|TS首页
  首页 快活林 猿氏悟语 程序代码

为什么Asana 正在切换到TypeScript?

By: 冰客 · 5022次点击   回复:1   
单页应用是一种构建浏览器富应用的强大方式,但是随着应用的成长,代码变得过于臃肿。Asana 有数万行的javascript代码,正在变得难以工作和维护。试过很多科技手段来解决这个问题,最后决定还是需要一个不同的语言,一个能够编写干净、可预见的javascript,并且只支持选项强类型。我们决定这个语言就是Typescript。



干净的 JavaScript

无关我们的语言,我们总是需要很多javascript,无论自己写,还是开源。如果我们用生产干净、简单的语言,那么集成代码就更容易一些。. 例如,如果我们想写一个符合语言习惯定义的类,那么, 我们可以使用子类。

懂JavaScript得人 能够很容易学会新的和 JavaScript相近的语言. 相似语言的相近路径会让编辑javascript更容易,并容易纠正错误. 同时,也能减少对新语言的放弃和编写原生javascript代码。

TypeScript 提供所有这些特性。 它来编写不让人吃惊的 JavaScript.可以轻松调用压缩JavaScript和手写JavaScript. 明白TypeScript生产出的javascript不是一个问题。

社区支持

JavaScript有庞大的社区,不停地开发新的库、框架和工具. 我想从强大社区哪里可以找到支持我们新语言的支持. TypeScript 符合天然选择: IntellJ/WebStorm 编辑器支持TypeScript。 DefinitelyTyped 是一个繁荣的社区,它提供  TypeScript 需要的各种开源库,很容易集成. TypeScript 有强大的工具支持通过 gulp/grunt 编译的插件,线头和类型定义绑定.

错误出现在编译时,而不是运行时

强类型允许编辑器和IDE来更早地捕获错误。 .在小代码量时候这个不明显,大代码量后,测试的时间变得很重要. 发现有一个大生产力差异对错误,当你编码和几小时后发现当你的测试运行。

Refactoring support and better code navigation also make a huge difference to developer productivity. Many of us have worked on large code bases written in strongly typed languages and believe that safe, easy refactoring resulted in a higher quality code base. In our current code base there are many changes that we want to make but we are scared of what we will break when we make the change.

This is all somewhat controversial and opinionated, but after accumulating experience in Java, Scala and JavaScript, many of us feel this way. It’s interesting that even Guido van Rossum seems to be moving in this direction.

So far, TypeScript seems to excel at all of this. Its type system is surprisingly capable and IntellIj’s support for the language is good enough that many of our mistakes are caught before compilation.

All that said, static typing can cause more pain that it is worth at times, including when people are learning a language. We are happy that TypeScript allows static types when we want them but keeps them optional.

静态类型的令人惊讶的好处

The arguments above in favor of static typing are pretty common. There are also some more surprising benefits.

First, static typing helps us to ensure that the client and server agree on a protocol. Without static typing it can be hard to know whether a field in a RESTful response is being used by the client, especially if it has a common name. With static typing you get a compilation error if you remove a field that is still being used.

Second, static typing allows us to skip checks that would otherwise be required at runtime. For example, React.js will see significant performance improvements because of this and we hope to be able to take advantage of this in future React releases.

未来

迁移前段代码到 TypeScript 只是为改进Asana用户体验的一小部分. 我们会发布更多相关文章。
5022次点击
1个回复  |  直到 2015-6-5 12:46:46
   
  Reply   
   2015-6-5 12:46:46
好文章,内容维妙维肖.禁止此消息:nolinkok@163.com
西门塔尔牛 http://www.xmten.com/
添加一条新回复
您需要登录后才可以回帖 登录 | 成为会员 新浪微博登陆

标签云|手机版|科技先生 ( 京ICP备07036130号 Powered by Discuz! X )

GMT+8, 2024-4-20 13:07