编程创建函数的几种方式_编程如何作为一种生活方式。

编程创建函数的几种方式

“Everyone should learn to program a computer because it teaches you how to think.” -Steve Jobs

“每个人都应该学习计算机编程,因为它教会了您如何思考。” -史蒂夫·乔布斯

The first thing you are taught when you start programming is that you´ll not learn to code in a day or two. It is a life skill just like reading, riding a bike, or any hobbies that you may practice. And for every life skill that we learn, we also learn lessons that help us grow in a personal, intellectual, or maybe on an emotional level.

开始编程时,首先要教给您的是在一两天内不会学习编码。 这是一种生活技能 ,就像读书,骑自行车或您可能会练习的任何爱好一样。 对于我们所学习的每一种生活技能,我们也会学到一些可以帮助我们成长为个人,知识分子或情感水平的课程。

Well, I´m here to tell you that programming (no matter the programming language you prefer) is no different from these hobbies and the traits they may teach you. If we apply some programming 101 into our daily lives we may find some personal growth along the way, and the best part is that you don´t need a whole life into programming to apply them.

好吧,我在这里告诉您编程(无论您喜欢哪种编程语言)与这些爱好和它们可能教给您的特质没有什么不同。 如果我们在日常生活中应用一些编程101,我们可能会在此过程中找到一些个人成长的地方,最好的部分是,您不需要一生都可以进行编程来应用它们。

These are only a few principles that you can use either to solve any problem or to just take as a life philosophy and use it in your daily habits. I will also address Python´s Zen, which also translates very well as a solution or answer to any problem you may encounter.

这些仅是您可以用来解决任何问题或仅作为生活哲学并用于您的日常习惯的几条原则。 我还将介绍Python的Zen ,它也可以很好地翻译为您可能遇到的任何问题的解决方案或答案。

Image for post
Photo by Florian Olivo on Unsplash
Florian OlivoUnsplash拍摄的照片

代码” (The “Code")

The main points are in a particular order, but feel free to use them whenever you find it convenient.

要点是按特定顺序排列的,但是只要您觉得方便就可以随意使用它们。

1. Identify the problem

1.找出问题

This point may be a little bit obvious, but important none the less. As a programmer, you have to analyze what problem you will solve, and establish an order in which to solve them. Maybe in this step, you may realize that you can breakdown the problem into multiple ones, and organize them in terms of complexity or types of solutions. This step appears explicitly in the Zen of Python like this:

这一点可能很明显,但仍然很重要。 作为程序员,您必须分析要解决的问题,并确定解决问题的顺序。 也许在这一步中,您可能意识到可以将问题分解为多个问题,并按照复杂性或解决方案类型来组织它们。 此步骤明确显示在Python的Zen中,如下所示:

“If the implementation is hard to explain, it’s a bad idea.”

“如果实施难以解释,那是个坏主意。”

“If the implementation is easy to explain, it may be a good idea.”

“如果实现易于解释,那可能是个好主意。”

The keyword in this few sentences of the Zen of Python is implementation. We have to identify and if possible, simplify the problem for us to find the simplest solution to it.

Python Zen的这几句话中的关键字是实现。 我们必须找出并尽可能简化问题,以便我们找到最简单的解决方案。

2.Define variables

2,定义变量

Now that you have the problem defined, we now need to analyze possible ways to solve that problem. To do that, we need to identify the variables that affect the problem, and consequently the solution directly. We can start by asking questions such as:

现在您已经定义了问题,我们现在需要分析解决该问题的可能方法。 为此,我们需要确定影响问题的变量,并因此直接确定解决方案。 我们可以从以下问题开始:

  • Who plays a role in the solution of the problem?

    谁在解决问题中发挥作用?
  • What factor or factors I don´t have control over?

    我无法控制哪些因素?
  • Who will I affect by choosing this solution?

    选择此解决方案会影响谁?

These are only a few examples of the questions you may come up with for you to know the outputs (or outcomes) of the solution you decide to use. This is a crucial step for you to avoid any surprises or variables that you don´t have control over when solving the problem. In Python’s Zen, we can find this step in the part that says:

这些只是您可能会提出的问题的几个示例,以便您了解决定使用的解决方案的输出(或结果)。 这是至关重要的一步,可以避免在解决问题时无法控制的任何意外情况或变量。 在Python的Zen中,我们可以在以下部分找到这一步:

“Errors should never pass silently, unless explicitly silenced.”

“除非明确地将错误消除,否则错误绝不能默默传递。”

In the face of ambiguity, refuse the temptation to guess.

面对模棱两可的想法,拒绝猜测的诱惑。

3. Specify Restrictions

3.指定限制

At this point, you have a clear idea of a solution to the problem, however, a lot of ideas don´t translate well to the practice. it doesn’t matter how well it was planned. For this, programmers apply restrictions, a pathway to avoid complications in the program they´re writing. As a way to apply it in our daily lives, we can start by identifying the things that are beyond our control. This is crucial for us to know what we can do and what we can´t from the solutions we came up with until now. We will establish a path or a flux diagram that will lead us to the solution.

在这一点上,您已经对解决问题有了一个清晰的想法,但是,很多想法并不能很好地转化为实践。 计划的好坏并不重要。 为此,程序员施加了限制,这是一种避免他们编写的程序复杂的途径。 作为将其应用到日常生活中的一种方法,我们可以从识别我们无法控制的事物开始。 这对于我们从到目前为止提出的解决方案中知道我们可以做什么和不可以做什么至关重要。 我们将建立一个路径或通量图,将我们引向解决方案。

“Special cases aren’t special enough to break the rules.”

“特殊情况还不足以打破规则。”

4. Run and test

4.运行并测试

Now is the time to test the solution you came up with after all of these steps. In this step I want to highlight one of Python’s Zen lines:

现在是时候在所有这些步骤之后测试您提出的解决方案了。 在这一步中,我要突出显示Python的Zen线之一:

“Now is better than never.”

“现在总比没有好。”

You have to trust in your way of solving these problems, the more you analyze the problems, the better you´ll become at coming up with innovative solutions and new ideas. This method will get more effective the more you use it, just like any other hobby or habit that you practice, which will also help you in making your way through problems that need programming to be solved.

您必须信任您解决这些问题的方式,对问题的分析越多,就越能提出创新的解决方案和新想法。 就像您练习的任何其他爱好或习惯一样,使用这种方法越有效,它就会越有效。这也将帮助您解决需要编程解决的问题。

Image for post
Photo by Alvaro Reyes on Unsplash
Alvaro ReyesUnsplash上的 照片

这个过程的目标 (The goals of this process)

While you are practicing this way of living life, try to visualize the goals that you are trying to achieve while doing so, visualize the problem and the process you are taking to solve it, and when you find the way with fewer errors, that is the way to go. You may find problems that will need similar solutions that you may already have come up with, so a ctrl + v might help in those situations.

在实践这种生活方式时,尝试形象化实现目标 ,想象问题和解决问题的过程,发现错误少的方法时,要走的路。 您可能会发现一些问题,这些问题将需要您可能已经提出的类似解决方案,因此在这些情况下使用ctrl + v可能会有所帮助。

On a personal level, I´ve found the following benefits by using this technique in my daily life:

在个人层面上,通过在日常生活中使用此技术,我发现了以下好处:

  1. To have the ability to identify the main problem without overthinking.

    有能力识别主要问题而无需考虑过多。
  2. To eliminate any solution that is way too complex for me to try (to pick the more accessible ways to solve the problem).

    消除所有我无法尝试的解决方案(选择更易用的方法来解决问题)。
  3. To better learn from my mistakes and apply those teachings to solve more problems.

    为了更好地从我的错误中学习并运用这些教义来解决更多的问题。
  4. To optimize my time and resources towards more useful habits in my daily life.

    优化我的时间和资源,朝着日常生活中更有用的习惯迈进。
  5. To understand problems from different points of view than mine.

    从不同于我的角度来理解问题。

You will slowly but surely find your way through most problems that might arise in your daily life, and you will solve them in the most optimized way possible, like a true Silicon Valley Programmer.

您将缓慢而确定地找到解决日常生活中可能出现的大多数问题的途径,并以最优化的方式解决这些问题,例如真正的硅谷程序员。

翻译自: https://medium.com/a-club/how-programming-works-as-a-way-of-life-1a9fc2baabca

编程创建函数的几种方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值