多線程編程和單線程編程_生活與編程的平行線程

多線程編程和單線程編程

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/

多線程編程和單線程編程

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390449.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390449.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390449.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

劍指 Offer 67. 把字符串轉換成整數

寫一個函數 StrToInt,實現把字符串轉換成整數這個功能。不能使用 atoi 或者其他類似的庫函數。 首先,該函數會根據需要丟棄無用的開頭空格字符,直到尋找到第一個非空格的字符為止。 當我們尋找到的第一個非空字符為正或者負號時&#xff0c…

搭建MSSM框架(Maven+Spring+Spring MVC+MyBatis)

https://github.com/easonjim/ssm-framework 先欠著&#xff0c;后續再進行講解&#xff1a; 一、Spring內核集成 二、Spring MVC集成 三、MyBatis集成 四、代碼生成工具集成 >如有問題&#xff0c;請聯系我&#xff1a;easonjim#163.com&#xff0c;或者下方發表評論。<…

4.RabbitMQ Linux安裝

這里使用的Linux是CentOS6.2 將/etc/yum.repo.d/目錄下的所有repo文件刪除 先下載epel源 # wget -O /etc/yum.repos.d/epel-erlang.repo http://repos.fedorapeople.org/repos/peter/erlang/epel-erlang.repo 修改epel-erlang.repo文件&#xff0c;如下圖 添加CentOS 的下載源…

freecodecamp_如何對freeCodeCamp文章提供反饋

freecodecampWe at the freeCodeCamp editorial team do our best to ensure articles are as accurate as they can be.我們的freeCodeCamp編輯團隊竭盡所能&#xff0c;以確保文章盡可能準確。 Still, we occasionally miss factual inaccuracies, non-functioning code exa…

如何對接oracle 建立pdb

Oracle數據庫的結構是一個數據庫實例下有許多用戶&#xff0c;每一個用戶有自己的表空間&#xff0c;即每一個用戶相當于MySQL中的一個數據庫。不久前下了oracle 12c的數據庫&#xff0c;安裝之后建user時才知道oracle12c 有一個很大的變動就是引入了pdb可插入數據庫&#xff0…

二、數據庫設計與操作

一、 數據庫設計仿QQ數據庫一共包括5張數據表&#xff0c;每張數據表結構如下&#xff1a;1、 tb_User&#xff08;用戶信息表&#xff09;這張表主要用來存儲用戶的好友關系與信息字段名數據類型是否Null值默認值綁定描述IDint否用戶賬號PwdVarchar(50)否用戶密碼Frie…

hdu 過山車_從機械工程師到軟件開發人員–我的編碼過山車

hdu 過山車There arent many people out there who grew up dreaming of writing code. I definitely didnt. I wanted to design cars. But somehow I ended up building software.很少有人夢見編寫代碼。 我絕對沒有。 我想設計汽車。 但是我最終以某種方式開發了軟件。 I u…

mysql 兩列互換

mysql 如果想互換兩列的值&#xff0c;直接寫 update 表 set col1col2&#xff0c;col2col1 這樣的后果就是兩列都是 col2 的值 注意這和sql server 是不同的&#xff0c; 如果想實現上述功能&#xff0c;添加一個自增列作為標識&#xff08;必須的&#xff09;&#xff0c; u…

劍指 Offer 36. 二叉搜索樹與雙向鏈表

輸入一棵二叉搜索樹&#xff0c;將該二叉搜索樹轉換成一個排序的循環雙向鏈表。要求不能創建任何新的節點&#xff0c;只能調整樹中節點指針的指向。 為了讓您更好地理解問題&#xff0c;以下面的二叉搜索樹為例&#xff1a; 我們希望將這個二叉搜索樹轉化為雙向循環鏈表。鏈表…

游戲引擎開發和物理引擎_視頻游戲開發的最佳游戲引擎

游戲引擎開發和物理引擎In this article, well look at some of the most popular game engines for video game development. Youll get a brief overview of each engine so you can choose which to use for your project.在本文中&#xff0c;我們將介紹一些用于視頻游戲開…

TPS和QPS的區別和理解

TPS和QPS的區別和理解 原創 2016年04月26日 17:11:3114010QPS&#xff1a;Queries Per Second意思是“每秒查詢率”&#xff0c;是一臺服務器每秒能夠相應的查詢次數&#xff0c;是對一個特定的查詢服務器在規定時間內所處理流量多少的衡量標準。 TPS&#xff1a;是Transaction…

1893. 檢查是否區域內所有整數都被覆蓋

theme: healer-readable 給你一個二維整數數組 ranges 和兩個整數 left 和 right 。每個 ranges[i] [starti, endi] 表示一個從 starti 到 endi 的 閉區間 。 如果閉區間 [left, right] 內每個整數都被 ranges 中 至少一個 區間覆蓋&#xff0c;那么請你返回 true &#xff…

004-docker常用命令[二]-容器操作ps,top,attach,export

2.3、容器操作 2.3.1、docker ps docker ps : 列出容器 語法 docker ps [OPTIONS] OPTIONS說明&#xff1a; -a :顯示所有的容器&#xff0c;包括未運行的。 -f :根據條件過濾顯示的內容。 --format :指定返回值的模板文件。 -l :顯示最近創建的容器。 -n :列出最近創建的n…

【類】變量復用,函數復用

變量復用 變量復用&#xff0c;適用于以下場景&#xff1a;1&#xff0c;整個項目公用的部分&#xff08;比如errors&#xff09;&#xff1b;2&#xff0c;一組類要通信&#xff0c;或者同一個類的兩個函數之間要通信&#xff0c;通信數據可以用類來定義和約束&#xff1b; 場…

python練習_如何使用Logzero在Python中練習記錄

python練習Logzero is a Python package created by Chris Hager that simplifies logging with Python 2 and 3. Logzero makes it easier as a print statement to show information and debugging details.Logzero是Chris Hager創建的Python程序包&#xff0c;它簡化了Pytho…

1736. 替換隱藏數字得到的最晚時間

給你一個字符串 time &#xff0c;格式為 hh:mm&#xff08;小時&#xff1a;分鐘&#xff09;&#xff0c;其中某幾位數字被隱藏&#xff08;用 ? 表示&#xff09;。 有效的時間為 00:00 到 23:59 之間的所有時間&#xff0c;包括 00:00 和 23:59 。 替換 time 中隱藏的數…

電腦棒安裝linux_為什么要使用Linux? Linux很棒的11個理由

電腦棒安裝linuxIn this article, well look at some of the things developers love about Linux so you can decide if its right for you.在本文中&#xff0c;我們將研究開發人員對Linux的一些喜愛&#xff0c;以便您可以確定它是否適合您。 持續有效的改進。 (Constant a…

1743. 從相鄰元素對還原數組

存在一個由 n 個不同元素組成的整數數組 nums &#xff0c;但你已經記不清具體內容。好在你還記得 nums 中的每一對相鄰元素。 給你一個二維整數數組 adjacentPairs &#xff0c;大小為 n - 1 &#xff0c;其中每個 adjacentPairs[i] [ui, vi] 表示元素 ui 和 vi 在 nums 中相…

十 web爬蟲講解2—Scrapy框架爬蟲—Scrapy安裝—Scrapy指令

Scrapy框架安裝 1、首先&#xff0c;終端執行命令升級pip: python -m pip install --upgrade pip2、安裝&#xff0c;wheel(建議網絡安裝) pip install wheel3、安裝&#xff0c;lxml(建議下載安裝)4、安裝&#xff0c;Twisted(建議下載安裝)5、安裝&#xff0c;Scrapy(建議網絡…

阿里與珠海橫琴新區達成戰略合作,阿里云助力打造橫琴智能島

5月17日&#xff0c;阿里巴巴集團、螞蟻金服集團與珠海橫琴新區管理委員會簽署戰略合作協議&#xff0c;三方將圍繞云計算、政務民生服務、城市治理、電子商務等領域展開深入合作&#xff0c;推動橫琴產業發展&#xff0c;共同建設新型智慧城市。 &#xff08;阿里巴巴集團、螞…