[英文版]Adit Bhargava:Illustrations break the spell on Algorithm(圖靈訪談)
訪談嘉賓:
(Adit自畫像)
Adit Bhargava, 軟體工程師,兼具電腦科學和美術方面的教育背景,在adit.io撰寫程式設計方面的部落格。
因為愛好,Adit踏入了程式設計殿堂。Visual Basic 6 for Dummies教會了他很多基礎知識,但始終對演算法沒搞明白。直到遇到一位優秀的演算法教授後,他才認識到這些概念是多麼地簡單且優雅。
幾年前,他開始在adit.io上撰寫圖解式博文,介紹函數語言程式設計、Git、機器學習和併發。圖解式寫作風趣幽默、化繁為簡、清晰明確,受到大量讀者的喜愛。
我們主要聊了些:
- 為什麼要寫這樣一本萌萌的演算法入門書
- 封面插畫背後的故事
- Adit神祕的演算法導師
- Adit最喜歡的演算法
- 評判演算法的重要指標
- 程式設計學習低齡化
Why would you like to write such an introductory book, which is full of fascinating scenarios and cute illustrations drawn by hand?
I usually take notes for myself when I learn something, because it helps me learn. For example here are the notes I'm taking as I read "A Book Of Abstract Algebra" (attached). So this was a technique I had used in the past, and I thought others might find it useful also. So I wrote this blog post. People liked it and it made me think that a book with the same style would probably do pretty well too.
(Let's enjoy Adit's explanation of Monad in pictures!)
學習 Monad的渠道:
- 取得電腦科學專業的博士學位。
- 壓根兒不學。這裡根本用不到那些條條框框!
Functor 將一個普通函式應用到被封裝的值上:
Applicative 將一個封裝的函式應用到封裝的值上:
Monad 將一個 “接受普通值並回傳一個被封裝值” 的函式應用到一個被封裝的值上,這一任務由函式
>>=
(讀作 bind)完成。聽起來似乎很拗口,讓我們來看個例子吧,還是熟悉的Maybe
:假設
half
是隻對偶數感興趣的函式:half x = if even x then Just (x `div` 2) else Nothing
如果扔給
half
一個封裝的值會怎樣?這時,我們需要用
>>=
把被封裝的值擠到half
中。猜猜>>=
的照片:再看看它的效果:
> Just 3 >>= half Nothing > Just 4 >>= half Just 2 > Nothing >>= half Nothing
這其中究竟發生了什麼?Monad 是另一種型別類,這是它定義的一部分:
class Monad m where (>>=) :: m a -> (a -> m b) -> m b
下圖展示了
>>=
各個引數的意義:下面的定義讓
Maybe
成了 Monad:instance Monad Maybe where Nothing >>= func = Nothing Just val >>= func = func val
來看看執行
Just 3
時發生了什麼:如果傳入
Nothing
就更容易了:你還可以把這些呼叫過程連起來,比如執行
Just 20 >>= half >>= half >>= half
會得到Nothing
:太棒啦!
(Taken from Adit's articleFunctors, Applicatives, And Monads In Pictures)
From the book cover, I thought it might be full of hand-drawn illustrations about mice. It seems not, for there’re other images like sheep, birds, rabbits, diagrams. Why would you put that picture in front of the book?
I wish I had a good answer for you! The people at Manning chose the picture on the cover. Manning was generally good about giving me a lot of control over the book, but for the cover, they really fell in love with this image and chose to use it.
A whole bunch of readers are really curious about your algorithmic teacher mentioned in author's introduction part who made tough concepts become simple but elegant. Could you share some of his/her teaching methods?
Sure! Her most effective teaching method was stepping through an algorithm line by line. When something is hard, it is easier skip over it. But in order to learn, it is important to slow down at the hard parts. So for each algorithm she taught, she would slow down and go through the code line by line and explain what each line did. I tried to do the same thing in my book. In the section on recursion, for example, I walk through each line and show how the stack changes. I think having that level of detail is really important.
What's your favorite algorithm? Why does it give you such a deep impression?
I've mentioned how much I love graph algorithms a few times in the book. Graphs are a really amazing structure that show up absolutely everywhere. I feel like I'm able to solve so many problems just using graph algorithms. I recently went to lunch with a friend and someone at the lunch said "I bet I can teach you Category Theory in 15 minutes". I didn't know anything about Category Theory, but I knew graphs and abstract algebra, so it actually took him less than five minutes to explain Category Theory to me. At work, I've been able to automate some tedious tasks, all because I know how topological sort and breadth-first search work.
Sometimes, short operational time does not necessarily mean good performances. Except time, are there any other dimensions to judge algorithm?
Yes! I think ease of use is a pretty important metric. For example, there are plenty of machine learning techniques more advanced than KNN, but if you are just starting out with a problem, you might want to start with KNN even if you are a machine learning expert. If an algorithm is easy to think about, there are fewer places for bugs to hide. Once you start getting into more complicated algorithms like neural networks, if you run into a bug, it will take more time to figure out the cause because there are so many more moving parts, so more places for the bug to hide. When picking an algorithm and considering performance time, it is important to think about the performance of the programmer also! Easy to understand code is more maintainable and more likely to be bug-free.
There are actually a few teenagers who are reading your book. What do you think of learning algorithm from very early ages, like primary school ages or even earlier?
I think that makes a lot of sense. Programming is a way to be creative, just like painting or music. I learned programming pretty early and made video games and animations. The earlier you learn, the sooner you can work on your own projects!
Will you keep this up with a "Grokking" series covering other CS/Dev topics? Because we all love it.
I hope so! I need to think hard about what else I can write about :)
更多精彩,加入圖靈訪談微信!
相關文章
- 《演算法圖解》作者Adit Bhargava訪談問題徵集(圖靈訪談)演算法圖解圖靈
- 《演算法圖解》作者Adit Bhargava:插圖筆記法解除演算法的魔咒(圖靈訪談)演算法圖解筆記圖靈
- 圖靈訪談圖靈
- 訪談嘉賓推薦(圖靈訪談)圖靈
- [英文版]《CSS揭祕》作者Lea Verou:I love the openness of our industry (圖靈訪談)CSS圖靈
- 紀念阿蘭·圖靈誕辰,評選“精彩·好訪談”(圖靈訪談)圖靈
- [英文版]專訪《AngularJS 2權威教程》作者Nate Murray: Code is More of A Graph Than A Document (圖靈訪談)AngularJS圖靈
- 阮一峰訪談問題有獎徵集(圖靈訪談)圖靈
- 2013,做你的圖靈訪談圖靈
- 《機器學習》作者Peter Flach訪談問題有獎徵集(圖靈訪談)機器學習圖靈
- [英文版]《機器學習》作者Peter Flach:Hollywood even makes headlines by high-profile AI (圖靈訪談)機器學習AI圖靈
- 韓冀中:淺談Hadoop實戰(圖靈訪談)Hadoop圖靈
- 樸靈:打破限制,從前端到全棧(圖靈訪談)前端全棧圖靈
- 《圖靈的祕密》作者Charles Petzold:我眼中的圖靈機和Windows(圖靈訪談)圖靈Windows
- 360前端月影(吳亮)訪談問題有獎徵集(圖靈訪談)前端圖靈
- Hulu(北京)周涵寧訪談話題有獎徵集(圖靈訪談)圖靈
- C++之父Bjarne Stroustrup訪談問題有獎徵集(圖靈訪談)C++JAR圖靈
- 《特斯拉》作者卡爾森教授訪談問題有獎徵集(圖靈訪談)圖靈
- 《釋出!》作者Michael Nygard訪談問題有獎徵集(圖靈訪談)圖靈
- Badass users are not fans of the company (圖靈訪談)圖靈
- “圖靈訪談”微信公共賬號開通了圖靈
- 我和圖靈訪談的2017圖靈
- 趙劼(@老趙):以“玩”之名(圖靈訪談)圖靈
- Johanna Rothman:專案管理之道(圖靈訪談)專案管理圖靈
- 鍾冠賢:iOS開發之路(圖靈訪談)iOS圖靈
- @程式設計師鄒欣 訪談問題有獎徵集(圖靈訪談)程式設計師圖靈
- 《CSS揭祕》作者Lea Verou訪談問題有獎徵集(圖靈訪談)CSS圖靈
- 知名著者結城浩,訪談問題有獎徵集(圖靈訪談)圖靈
- 《鳳凰專案》作者基恩·金訪談問題有獎徵集(圖靈訪談)圖靈
- 再訪Thomas Kyte,圖靈訪談問題有獎徵集圖靈
- 莊表偉:coding亦生活(圖靈訪談)圖靈
- Nutz 發起者:不亦樂乎(圖靈訪談)圖靈
- 田春:走在Lisp的岔路上(圖靈訪談)Lisp圖靈
- [視訊]圖靈訪談系列之四:松本行弘談Ruby圖靈
- 有獎 |《人工智慧簡史》作者尼克訪談話題徵集(圖靈訪談)人工智慧圖靈
- 《JavaScript Web應用開發》作者Nicolas Bevacqua訪談問題徵集(圖靈訪談)JavaScriptWeb圖靈
- 有獎 | 知名科普作家James Gleick訪談話題有獎徵集(圖靈訪談)圖靈
- 著名軟體大師Chris Richardson訪談問題有獎徵集(圖靈訪談)圖靈