[英文版]專訪《AngularJS 2權威教程》作者Nate Murray: Code is More of A Graph Than A Document (圖靈訪談)
Guest:
Nate Murray 歡迎到Nate個人網頁瞭解更多內容! |
>
除了程式設計開發之外,生活中玩音樂、養蜜蜂。
參與開發了一款專為“喵星人”設計的遊戲,該遊戲被《紐約時報》《洛杉磯時報》《ABC 新聞》等多家報社報導並評選入圍“前100款熱門iPad娛樂類應用軟體”。
此外,在Github上有很多的開源專案:
- cascading-simhash
- Smoker
- Similarity
- Chordjerl
- ...
《AngularJS 2權威教程》堪稱AngularJS 2領域的里程碑式著作,涵蓋了關於AngularJS 2的幾乎所有內容。
即使沒有任何經驗,本書平實、通俗的講解,遞進、嚴密的組織,也可以讓你毫無壓力地登堂入室,迅速領悟新一代Web應用開發的精髓。如果你有相關的經驗,本書對AngularJS 2概念和技術細節的全面剖析,以及引人入勝、切中肯綮的講解,將幫助你徹底掌握這個框架,在自己職業技術修煉之路上更進一步。
Interview transcript
Turing: Recently, Turing Book Company is translating your co-authored book ng-book 2. Turing Interview feels obliged and honored to have a talk with Nate. What does Angular mean to you so that you want to write a book for it? Or what are the advantages of Angular impressing you, authors, overwhelmingly?
Nate: Angular provides a fantastic framework for writing and organizing your web apps. Component-based web development has shown itself to be a scalable, comprehensible way to write large, maintainable apps. In the past we would manually read and mutate the DOM using a library such as jQuery, and that kind of code, as many of us know, can become very unwieldy. On the other hand, breaking your code down into components breaks the system down so that each component is concerned with a particular part of the view and so the whole app is easier to reason about.
Turing: Is ng-book 2 an upgrade to ng-book 1?
Nate: No - it's a completely new book. Angular 2 and Angular 1 share a common thought-ancestry but the frameworks are pretty different. The Angular 2 book takes not only the new library, but everything we've learned over the years about web development into a completely new book.
Turing: How is the collaboration between your four authors when writing ng-book 2 ? Which parts are in your charge?
Nate: I've mainly been in charge of outlining, researching, editing and coordinating the whole project and I ended up writing a little less than half of the chapters. Felipe Coury also contributed a huge amount of the content and he's done a fantastic job. The main challenge when working with so many authors is unifying the voice, but thankfully we all share a common vision and so that hasn't been much of an issue in practice.
Turing: What do you think of the relation between code and literature?
Nate: Ideally your code is clear enough that it wouldn't need any supporting documentation. Even though we say that code should be written for humans to understand before machines, in practice technological constraints often dictate ordering of code (and mixing of concerns) that aren't optimal for someone learning a codebase for the first time.
There have been lots of takes on addressing this issue, particularly in the area of "literate programming". I think IPython/Jupyter is one of the most mature tools in this space. However, I think literate programming tools often require all code to be present and presented in a linear order. This often means that the examples you can use with them end up being trivial apps and you can't really learn large structures from them. Code is more of a graph than a document and so you need a way to hop around.
One of my latest attempts on this problem is a tool we call cq
. The idea is that you can extract snippets of code using CSS-style selectors to pull them into your documentation. We use this for all of our books and find that it really helps cut down on typos and maintenance (because we always load our code blocks from runnable code on disk). Because the selectors are aware of the code structure it has the advantage of being robust in the face of line number changes.
It's certainly not the last word in mixing writing and code, but it's helped us a lot.
Turing: According to your profile, we know that you've been working with large-scale data since 2009. In this sense, you could give some valuable advice on data problems proposed by readers.
There are situations where we will work with data within its parent scope. Then how to implement the communication between a scope and its parent scope? Is $broadcast/$emit/$on
the best way?
Nate: When you mention $broadcast/$emit/$on, I assume you're referring to Angular 1 apps. ng-book 2 is primarily about Angular 2 which doesn't have these directly, but the concepts below still apply.
In "classic" Angular $broadcast/$emit
was definitely the first tool of choice when passing data between scopes, but my thinking and the tools have evolved a lot since then. This problem is really a specific case of deciding the data-architecture of your app generally. Three other options come to mind:
Instead of using $broadcast/$emit use a service which has an EventEmitter and manage your state through that service
If you like Observables, instead of EventEmitter, have your service hold RxJS streams and let your components subscribe to changes on those streams
Get rid of $scope altogether and use Redux.
Redux is one of the most interesting data architecture patterns to emerge this year. The idea is that you have all of your data in a central data structure which is never mutated directly. Instead you dispatch "actions" and then you pass your old state and the action to a function which returns a new state (the term for this function is a reducer). I'd recommend ditching $emit/$broadcast and $scope altogether and using a Redux store for state for any brand-new Angular projects.
Turing: When dealing with large-scale data, ng-repeat
gets stuck somewhere occasionally. What's your advice on its better performance?
Nate: A good idea here is to show only a limited number and then recycle DOM elements (instead of showing the whole list and creating new elements for each one).
Say you're repeating a list of div
s that are in a scrollable container. You can limit the maximum number of div
s in the DOM to, say, a pool of 100 divs. Then listen to the scrolling on the container element and populate the div
s as appropriate. It takes a bit more work to set this up, but you'll get much better performance.
Turing: Now, let's forecsat the future of AngularJS. Is it possible for AngularJS to cover back-end development and become a back-end solution like Django in the future?
Nate: To my knowledge, becoming a backend framework like Django or Rails isn't a stated goal of the Angular project. Angular is a strong front-end framework that works in the browser on the DOM and is able to make HTTP requests to any APIs it needs to populate data.
That said, Angular 2 has been built such that it will support multiple platforms, most notably mobile development. Being able to create mobile clients in Angular 2 with NativeScript or Ionic is really exciting.
On the server-side, Patrick Stapleton and a group of contributors have done some great work on Angular Universal which is a way to have your server run and ‘boot up’ your app which, in theory, should result in better performance for the client.
Turing: Do you think that AngularJS will be encapsulated into Browsers one day?
It's hard to say but probably not as such. If anything it would be the other way around: the browser's functionalities will grow to make some of the parts of Angular unnecessary. Web Components is a good example of something browsers may eventually support more broadly that could make @Component
unnecessary.
Another part browsers might provide are change detection like Zones - we almost saw browser implementations of Object.observe, which was a lot like Angular's $watch
. But this didn't end up becoming part of the ECMA standard, which is probably fine.
But Angular 2 has a lot of other functionality beyond components like routing, dependency injection, testing frameworks, etc. These frameworks are great, but like any framework they have opinions that may not fit every situation and so I don't know that they will ever be integrated into the browser.
Turing: AngularJS is powerful but complex. Could you give some learning suggestions for beginners?
Nate: The best way to learn any programming framework is to build something with it. So my first learning suggestion to beginners is to go to the official documentation website and try to follow the walkthrough. Both Angular 1 and Angular 2 have walkthrough tutorials on their site.
The next thing I'd recommend to beginners is a resource that walks through step-by-step with lots of sample code. I'm biased, but I think ng-book 1 and ng-book 2 are the best places to get that. Egghead.io also has some great video courses.
更多精彩,加入圖靈訪談微信!
相關文章
- 《AngularJS 2 權威指南》作者Nate Murray訪談問題徵集(圖靈訪談)AngularJS圖靈
- 專訪《AngularJS 2權威教程》作者Nate Murray:程式碼更像圖表,需要多維度把握(圖靈訪談)AngularJS圖靈
- 《AngularJS權威教程》作者Ari Lerner有獎問題徵集(圖靈訪談)AngularJS圖靈
- 《鳳凰專案》作者基恩·金訪談問題有獎徵集(圖靈訪談)圖靈
- 《HTTP權威指南》作者Anshu Aggarwal:用大資料來節能(圖靈訪談)HTTP大資料圖靈
- 《Swift基礎教程》作者Boisy Pitre訪談問題有獎徵集(圖靈訪談)Swift圖靈
- 《SQL基礎教程(第2版)》作者MICK(ミック)訪談話題有獎徵集(圖靈訪談)SQL圖靈
- [英文版]《CSS揭祕》作者Lea Verou:I love the openness of our industry (圖靈訪談)CSS圖靈
- [英]《HTTP權威指南》作者Anshu Aggarwal:用計算機來節能(圖靈訪談)HTTP計算機圖靈
- 《機器學習》作者Peter Flach訪談問題有獎徵集(圖靈訪談)機器學習圖靈
- 有獎 |《Lua設計與實現》作者codedump訪談話題徵集(圖靈訪談)圖靈
- 《特斯拉》作者卡爾森教授訪談問題有獎徵集(圖靈訪談)圖靈
- 《釋出!》作者Michael Nygard訪談問題有獎徵集(圖靈訪談)圖靈
- 《演算法圖解》作者Adit Bhargava訪談問題徵集(圖靈訪談)演算法圖解圖靈
- [英]專訪《寫給大家看的設計書》作者Robin Williams(圖靈訪談)圖靈
- 圖靈訪談圖靈
- 《Erlang程式設計(第2版)》作者Joe Armstrong訪談問題有獎徵集(圖靈訪談)程式設計圖靈
- 《CSS揭祕》作者Lea Verou訪談問題有獎徵集(圖靈訪談)CSS圖靈
- 《SQL基礎教程(第2版)》作者MICK:上帝存在於細節之中(圖靈訪談)SQL圖靈
- 《決勝UX》作者Jaime Levy:More important to me is my brain makes really cool stuffs(圖靈訪談)UXAIImport圖靈
- 有獎 |《人工智慧簡史》作者尼克訪談話題徵集(圖靈訪談)人工智慧圖靈
- 《JavaScript Web應用開發》作者Nicolas Bevacqua訪談問題徵集(圖靈訪談)JavaScriptWeb圖靈
- 《跟阿銘學Linux》作者阿銘訪談話題有獎徵集(圖靈訪談)Linux圖靈
- 《禽獸心理學》作者Anna Salter訪談問題有獎徵集(圖靈訪談)圖靈
- [英文版]Adit Bhargava:Illustrations break the spell on Algorithm(圖靈訪談)Go圖靈
- 專訪小書作者劉傳君:練太極的“讀書機器”(圖靈訪談)圖靈
- 一位匠人的中州韻——專訪Rime輸入法作者佛振(圖靈訪談)圖靈
- 《演算法(第4版·英文)》作者羅伯特·塞奇威克訪談問題有獎徵集(圖靈訪談)演算法圖靈
- 訪談嘉賓推薦(圖靈訪談)圖靈
- 《R包開發》作者Hadley Wickham訪談問題有獎徵集(圖靈訪談)圖靈
- 《用資料講故事》作者Cole Knaflic訪談話題有獎徵集(圖靈訪談)圖靈
- 《使用者思維+》作者Kathy Sierra訪談問題有獎徵集(圖靈訪談)圖靈
- 《Flask Web開發》作者Miguel Grinberg訪談問題有獎徵集(圖靈訪談)FlaskWeb圖靈
- Jolt大獎獲獎作者Venkat Subramaniam訪談問題有獎徵集(圖靈訪談)圖靈
- 譯後訪談《Scratch少兒趣味程式設計》作者阿部和廣(圖靈訪談)程式設計圖靈
- 《圖靈的祕密》作者Charles Petzold訪談問題徵集圖靈
- 《演算法新解》作者劉新宇訪談問題有獎徵集(圖靈訪談)演算法圖靈
- 《精益資料分析》作者Alistair Croll訪談問題有獎徵集(圖靈訪談)AI圖靈