多線程編程和單線程編程
I’m convinced our deepest desire is, by paying the cost of time, to be shown a glimmer of some fundamental truth about the universe. To hear it whisper its lessons and point towards its purpose.
我堅信,我們最深切的愿望是通過花費時間來向人們展示有關宇宙的一些基本真理。 聽聽它的耳語,并指出它的目的。
And, if you look hard enough for these lessons, you will find them. Whether they are a manifestation of your mind or can be held in your hand, once you see them, they remain yours forever.
而且,如果您對這些課程足夠認真,就會找到它們。 無論它們是您的思想的體現還是可以握在手中,一旦您看到它們,它們就永遠屬于您。
Programming offers significant parallels to life. We are tasked with creating something–something whose sum feels more significant than the parts. Like life, it is a test of bounded creativity. There are rules we must follow, some we should follow, and others we are free to ignore. Programming offers us a glimpse, however ephemeral it may be, into some fundamental truths about the world in which we reside.
編程為生活提供了重要的相似之處。 我們的任務是創造一些出頭其總和感覺比部分更顯著。 就像生活一樣,它是對創造力的考驗。 有規則,我們必須遵守,一些我們應該遵循,以及其他一些我們可以隨意忽略。 編程讓我們瞥見了關于我們所居住的世界的一些基本事實,無論它是多么短暫。
編程與生活之間的四個平行 (The Four Parallels Between Programming and Life)
迭代就是進步。 (Iteration is progress.)
Did you know, if you started the month with a single penny and it doubled every day, you would have $163 on the 15th of the month? Surely, you think, there must be a better way to make $163 in 15 days. But, if you wait another 15 days, you would have more than 5 million dollars.
您是否知道,如果您以一個便士開始一個月,并且每天都翻一番,那么您在該月的15號會有163美元? 當然,您認為,肯定有更好的方法可以在15天內賺到163美元。 但是,如果再等15天,您的收入將超過500萬美元。
Go ahead, I’ll wait while you do the math.
繼續,我會等你做數學的。
In programming, we use the term iterate to indicate repeating something. In a more formal definition, it is repeatedly applying a procedure to the previous result of that procedure. For example, adding the numbers 1 and 1 to get 2, then adding 1 and 2 to get 3, and so forth.
在編程中,我們使用術語“ 迭代”來表示重復某件事。 在更正式的定義中,它將重復地將一個過程應用于該過程的先前結果。 例如,將數字1和1相加得到2,然后將數字1和2相加得到3,依此類推。
When we iterate, we look for feedback. We wait for some condition to be met so we can either stop iterating or adjust how we are iterating. If we fail to listen for that feedback, we can get stuck in an infinite loop.
進行迭代時,我們會尋找反饋。 我們等待要滿足一些條件,使我們可以停止迭代或調整我們如何迭代。 如果我們聽不到這些反饋,就會陷入無限循環。
Life is no different. We often expect we can jump from point A to point B without ever defining what point A or point B is. And, even when we identify those points, we expect an immediate move from start to finish. Instead, what is often the truth, is we must incrementally make our way from beginning to end. We must listen for feedback that tells us where we are so we can make adjustments.
生活沒有什么不同。 我們經常期望我們可以從A點跳到B點,而無需定義A點或B點是什么。 而且,即使我們確定了這些要點,我們也希望從頭到尾立即采取行動。 相反,通常是事實,那就是我們必須從頭到尾逐步發展自己的道路。 我們必須聽取反饋,告訴我們我們在哪里,以便我們進行調整。
When we have goals, progress can often feel–for the first few days, weeks, or even months–non-existent. We’re often enticed to start over or start fresh. But in doing so, we fail to realize, while we might not have reached our destination, we are somewhere far past where we started. A complete restart isn’t necessary, we just need to make some minor adjustments.
當我們有了目標時,在最初的幾天,幾周甚至幾個月內,通常都感覺不到進步。 我們常常被引誘重新開始或重新開始。 但是這樣做時,我們未能意識到,雖然我們可能尚未到達目的地,但我們已經遠遠超出了開始的地方。 無需完全重啟,我們只需要進行一些小的調整即可。
Stop starting over. Let iteration be the force the creates progress.
停止重新開始。 讓迭代成為創造進度的力量。
最復雜的問題是已經解決的較小問題的集合。 (Most complex problems are collections of smaller problems that have already been solved.)
Even the most fascinating apps are a series of mostly mundane solutions to mundane problems. In fact, most of the solutions implemented within a program are nothing unique. It is the combination of those ordinary solutions that creates an extraordinary product.
即使是最引人入勝的應用程序,也可以使用一系列平凡的解決方案來解決平凡的問題。 實際上,程序中實現的大多數解決方案都不是唯一的。 那些普通解決方案的結合才創造出了非凡的產品。
In programming, there are different ways to use these quite-ordinary solutions. One way is through a term called abstraction. To abstract something is to move something away from something else.
在編程中,有多種方法可以使用這些非常普通的解決方案。 一種方法是通過稱為抽象的術語。 抽象某物就是將某物從另一物移開。
In computer programming, when we abstract something, we are often building higher-level technology on top of lower-level technology. This makes it easier to work with lower-level technologies.
在計算機編程中,當我們抽象某些東西時,我們通常會在較低級別的技術之上構建較高級別的技術。 這使得使用低級技術更容易。
For example, most programming languages are abstractions of the enigmatic binary language (0s and 1s). They put a layer between us and some more fundamental, but cumbersome, level of interaction with the computer. These higher-level languages allow us to focus on higher-level problems.
例如,大多數編程語言都是神秘的二進制語言(0和1)的抽象 。 它們在我們之間以及與計算機進行一些更基本但又麻煩的交互級別之間建立了一層。 這些高級語言使我們可以專注于高級問題。
Another way we can more efficiently solve problems is by using someone else’s solutions. You may have also heard the term library. And, while I am not speaking of a poorly lit, dusty, and quiet location where books live, it isn’t far off.
我們可以更有效地解決問題的另一種方法是使用其他人的解決方案。 您可能還聽說過庫一詞。 而且,雖然我不是在談論光線不足,灰塵多且安靜的地方,但書并不遙遠。
A library, in programming terms, is code that someone else wrote that solves routine problems. It also abstracts away those things which aren’t absolutely fundamental to solving whatever problem you have.
用編程的術語來說, 庫是別人寫的解決常規問題的代碼。 它還抽象了那些對于解決您所遇到的問題并非絕對重要的事情。
For example, if you are writing a program that requires someone to log in to use your application, you could write the code to encrypt and decrypt passwords yourself, or, you could use code written by someone else to do that for you. With the latter option, we free up time to focus on more significant problems our application is trying to solve.
例如,如果您正在編寫一個程序,要求某人登錄才能使用您的應用程序,則可以編寫代碼自己對密碼進行加密和解密, 或者可以使用其他人編寫的代碼為您執行此操作。 使用后一種選擇,我們可以騰出時間專注于我們的應用程序試圖解決的更重要的問題。
All of us use abstractions and libraries in some shape or form. For example, the grocery store is an abstraction of producing our own food. A car is an abstraction of traveling on foot. An oven is an abstraction of building a fire. These are layers we place in front of us that allows us to allocate time to higher-level problems.
我們所有人都以某種形狀或形式使用抽象和庫。 例如,雜貨店是我們自己生產食物的抽象。 汽車是徒步旅行的抽象概念。 烤箱是生火的抽象概念。 這些是我們擺在我們面前的層次,可讓我們將時間分配給更高級別的問題。
Reinvent the wheel only to learn how to make a wheel, not to drive to the store.
重新發明輪子只是為了學習如何制造輪子,而不是開車去商店。
如何定義問題就是解決問題的方式。 (How you define a problem is how you will solve it.)
Recall the story of a truck that drove under a bridge and got stuck. Engineers spent hours trying to figure out how to move the bridge. A small child came up, face to face with the tires of the truck, and said, “what if you let the air out of the tires?”
回想一下卡車在橋下行駛并被卡住的故事。 工程師花費了數小時試圖弄清楚如何移動橋梁。 一個小孩子站起來,與卡車的輪胎面對面,說道:“如果不讓輪胎中的空氣出來,那該怎么辦?”
From the child’s vantage point, the problem wasn’t the bridge was too short, but rather the truck was too tall.
從孩子的角度出發,問題不是橋太短,而是卡車太高了。
Most people can solve any problem. In fact, most problems state the solution. For example, if the bridge is causing the issue, the answer is to do something with the bridge. If, however, the problem is that the truck is too tall, then the solution–almost glaringly obvious–is to make the truck shorter.
大多數人可以解決任何問題。 實際上,大多數問題都指出了解決方案。 例如,如果網橋是引起問題的原因,那么答案就是對網橋做些什么。 但是,如果問題是卡車太高,則解決方案(幾乎顯而易見)是使卡車縮短。
零件的布置比零件本身重要得多。 (The arrangement of parts is much more important than the parts themselves.)
What does the Google Maps codebase, the Declaration of Independence, Martin Luther King Jr.’s I have a dream speech, Steve Jobs’s 2005 commencement address, and my first app, Hello, World have in common?
什么是谷歌地圖的代碼庫,獨立宣言,馬丁·路德·金是我有一個夢想演講中,史蒂夫·喬布斯2005年畢業典禮上的演講,我的第一個應用程序, 你好,世界有什么共同點?
The access to the same 26 letters of the English alphabet.
訪問相同的26個英文字母。
There is very little that is more fascinating to me than the written word. The written word is one of the most powerful technologies that emerged from humans.
沒有什么比書面文字更讓我著迷了。 書面文字是人類出現的最強大的技術之一。
Yes, I use the term technology because–even carved into the wall of a cave–it fundamentally changed how we persist information. No longer was data constrained within the boundaries of our minds.
是的,我使用技術一詞,是因為它甚至刻在洞穴的墻壁上,從根本上改變了我們保持信息的方式。 數據不再局限于我們的思維范圍內。
While the purpose of the written word was initially linked to record-keeping, it quickly became a way to spread ideas. Some of these ideas would anger, and others inspire.
盡管最初將書面文字的目的與保存記錄聯系在一起,但它很快成為傳播思想的一種方式。 其中一些想法會激怒,另一些則會激發靈感。
Every language (including computer language) has subtleties when transmitting information through writing or speech. The words and their constituent parts may be slightly different. Still, however, a language is a set of symbols that can be arranged into what seems to be an infinite number of ideas.
通過書寫或語音傳輸信息時,每種語言(包括計算機語言)都具有微妙之處。 單詞及其組成部分可能略有不同。 但是,語言仍然是一組符號,可以將這些符號排列成無數種思想。
For example, in the English language, there are roughly 29 symbols that I can use to represent nearly my entire universe. I’ve mentioned the 26 letters, but it is also helpful to have access to periods, commas, and question marks.
例如,在英語中,大約有29個符號可用來代表幾乎整個宇宙。 我已經提到了26個字母,但是使用句點,逗號和問號也很有幫助。
Those 29 characters are available to you, me, and were available to Steve Jobs. Yet, each of us, throughout our lives, will follow different trajectories based on the combination of letters we chose to believe and speak into existence.
我和您都可以使用這29個字符,史蒂夫·喬布斯也可以使用。 然而,基于我們選擇相信并說出存在的字母的組合,我們每個人一生都會遵循不同的軌跡。
Interestingly, while we often add words to the dictionary, we don’t usually add letters. This means, at the most fundamental level, that all the ideas that can exist, already do, with their constituent parts quietly waiting for us to shuffle them into existence.
有趣的是,盡管我們經常在字典中添加單詞,但通常不添加字母。 這意味著,從最根本的層面上講,所有可能存在的想法已經存在,它們的組成部分靜靜地等待著我們將它們改組為現實。
Les Brown sums it up well with this thought experiment:
Les Brown通過這個思想實驗很好地總結了這一點:
Imagine if you will, being on your death bed. And standing around your bed–the ghosts of the ideas, the dreams, the abilities, the talents given to you by life.
想象一下,如果您愿意的話,就躺在死亡床上。 站在床旁–生活中賦予您的思想,夢想,能力和才華的幽靈。
And that you, for whatever reason, never acted on those ideas. You never pursued that dream. You never used those talents. We never saw your leadership. You never used your voice. You never wrote that book.
而且無論出于何種原因,您都從未對這些想法采取任何行動。 您從未追求過那個夢想。 您從未使用過這些才華。 我們從未見過您的領導。 你從來沒有用過你的聲音。 你從未寫過那本書。
And there they are, standing around your bed, looking at you with large angry eyes saying: “We came to you. And only you could have given us life! Now we must die with you forever.”
他們在那里,站在你的床周圍,用憤怒的大眼睛看著你,說:“我們來找你。 只有你能給我們生命! 現在我們必須永遠與你同死。”
The question is — if you die today–what ideas, what dreams, what abilities, what talents, what gifts, would die with you?
問題是-如果您今天死了-您會死什么想法,什么夢想,什么能力,什么才能,什么禮物?
Thank you for reading!
感謝您的閱讀!
woz
沃茲
Follow me on Twitter
在推特上關注我
翻譯自: https://www.freecodecamp.org/news/the-parallel-threads-of-life-and-programming-2/
多線程編程和單線程編程