多线程编程和单线程编程_生活与编程的平行线程

多线程编程和单线程编程

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/

多线程编程和单线程编程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值