翻译进度
9
分块数量
6
参与人数

如何像程序员一样思考:以解决问题为导向的工程师思维

这是一篇协同翻译的文章,你可以点击『我来翻译』按钮来参与翻译。

终身编程者

如果你对编程感兴趣,你一定听到过下面的格言:

“每个人都应该学习编程,因为它教会你如何思考。” — 史蒂夫·乔布斯

你可能会好奇什么是"像程序员一样思考",并且如何才能做到?

本质上,它是关于 更有效率的解决问题

这篇文章中,我将教会你如何更有效率的解决问题。

读完本章时,你将学会如何一步一步更好的解决问题。

晓鹤 翻译于 1个月前

为什么重要?

因为解决问题的能力是一个人的元技能.

我们都会遇到大大小小的问题,但有时候我们处理问题的方法却是随机的。

除非您有一个系统,否则可能您"解决"问题的方法就会象我开始编码时这样:

  1. 尝试一个解决方案,
  2. 如果不奏效,再尝试另一个方案,
  3. 如果仍不奏效,重复第2步,直到解决。

看,有时候您运气好,通过这种方法是把问题解决了,但这是解决问题最糟糕的方法!是对时间巨大的浪费。

解决问题最好的方法应是:

  1. 有一个框架
  2. 实践它

「几乎所有的雇主都把解决问题的能力放在首位。他们认为员工解决问题的能力是最重要的任职资格,而不仅仅是编程语言的熟练程度、调试能力和系统设计。展示计算思维或分解大型复杂问题的能力与工作所需的基本技术技能一样有价值 ,甚至可以说是更多。」 — Hacker Rank (《2018 开发者技能报告》)

phpervip 翻译于 1个月前

使用框架

为了找到合适的框架,我采纳了 Tim Ferriss 在 “The 4-Hour Chef” 书中的建议.

这让我想起采访过两位令人印象深刻的人: C. Jordan Ball (他在拥有65,000+ 位用户的  Coderbyte 上排名1,2位),和  V. Anton Spraul (“Think Like a Programmer: An Introduction to Creative Problem Solving” 一书的作者).

我向他们提了相同的问题,然后他们的回答极其相似。

很快,你也会了解他们的。

注意:这并不意味着他们做事情的方式完全一样。每个人都是与众不同的,你也是与众不同的那一个。但是如果你从大家都认可的优秀的准则开始处理问题,那么你将会走的更远也会更有效率。

“我认为刚入门的程序员犯的最大错误是:他们关注学习语法而不是学习如何解决问题。” — V. Anton Spraul

那么,当你遇到一个新问题时该怎么做了?

以下是步骤:

未进化的类人猿 翻译于 1个月前

1. 理解

准确的理解问题。大部分艰难的问题之所以艰难是因为你不理解他们(因此,理解成为了第一步)。

那么你如何判断你已经明白了问题了?答案是当你能用自己的话去说明它的时候。

你是否想起遇到过的这种场景:你被一个难题困住了,然后你开始向别人说明这个问题,然后你很快发现之前没注意到的逻辑漏洞?

多数的程序员都了解这种感受。

所以,当你遇到问题时,你应该记录你的问题,针对问题画个草图,或者向别人描述这个问题(或者使用其他工具,比如有些人使用 rubber duck

“如果你无法使用简单词汇去向他人描述一件事情的时候,那么说明你还没理解它。” — Richard Feynman

未进化的类人猿 翻译于 1个月前

2. 计划

不要在没有计划的情况下一头扎进去解决问题,虽然可能会莫名其妙地解决它,但是还是请规划好你的解决方案。

如果你没法记录正确的的步骤,那么一切都将是毫无帮助。

对于编程来说,这意味着你不要马上开始工作。你需要时间去分析这个问题和处理相关信息。

为了得到一个优秀的计划,请回答下面的问题:

“对于给出的输入 X ,需要经历哪些必要步骤才能得到输出 Y 了?”

注意:程序员们拥有一个优秀的工具来帮助他们完成这个,那就是注释!

未进化的类人猿 翻译于 1个月前

3. 分治

请注意,这是最重要的一步。

不要去尝试直接解决一个复杂庞大的问题,这会让你疲惫不堪。

比较好的做法是,将一个大问题划分成若干个子问题,这些子问题比大问题更容易解决。

然后,一个接一个的去解决这些子问题,从最简单的子问题的开始。最简单的子问题就是那些你能直接得出答案或者更容易得出答案的问题。

最简单的意思是即将被解决的子问题不会依赖于其他子问题的解决情况。

一旦你解决了所有子问题,将他们串连起来。

串连起所有解决的子问题,这意味着你将得出起始问题的解决方案了。祝贺你!

这一步是解决问题的基础,请你牢记。(如果有必要,可以再读一遍这一步)。

“如果我可以教给每个初学者一个解决问题的技能,那么这一简化问题的方法成为我的不二选择。”

例如,假设你是个新手,你被要求写个程序,从输入10个数字中找出第三大的数字。对于一个完全新手来说,这将会是一个艰巨的任务,尽管这个问题只需要一些基本语法基础。

如果你卡住了,那么你应该想着把问题简化。比如我们的任务是找出第三大的数字,那么我们是不是先可以找出最大的数字了或者比较两个数字大小?

“你需要把问题简化到你可以解决的程度,并写出相应的解决方案。然后稍微拓展一下问题并且重新对问题写个解决方案。不断重复前面的操作直到你回到起始问题。” — V. Anton Spraul

未进化的类人猿 翻译于 1个月前
Gxpro 审阅

4. Stuck?

By now, you’re probably sitting there thinking “Hey Richard... That’s cool and all, but what if I’m stuck and can’t even solve a sub-problem??”

First off, take a deep breath. Second, that’s fair.

Don’t worry though, friend. This happens to everyone!

The difference is the best programmers/problem-solvers are more curious about bugs/errors than irritated.

In fact, here are three things to try when facing a whammy:

  • Debug: Go step by step through your solution trying to find where you went wrong. Programmers call this debugging (in fact, this is all a debugger does).

“The art of debugging is figuring out what you really told your program to do rather than what you thought you told it to do.”” — Andrew Singer

  • Reassess:Take a step back. Look at the problem from another perspective. Is there anything that can be abstracted to a more general approach?

“Sometimes we get so lost in the details of a problem that we overlook general principles that would solve the problem at a more general level. […]

The classic example of this, of course, is the summation of a long list of consecutive integers, 1 + 2 + 3 + … + n, which a very young Gauss quickly recognized was simply n(n+1)/2, thus avoiding the effort of having to do the addition.” — C. Jordan Ball

Sidenote: Another way of reassessing is starting anew. Delete everything and begin again with fresh eyes. I’m serious. You’ll be dumbfounded at how effective this is.

  • Research:Ahh, good ol’ Google. You read that right. No matter what problem you have, someone has probably solved it. Find that person/ solution. In fact, do this even if you solved the problem! (You can learn a lot from other people’s solutions).

Caveat: Don’t look for a solution to the big problem. Only look for solutions to sub-problems. Why? Because unless you struggle (even a little bit), you won’t learn anything. If you don’t learn anything, you wasted your time.

Practice

Don’t expect to be great after just one week. If you want to be a good problem-solver, solve a lot of problems!

Practice. Practice. Practice. It’ll only be a matter of time before you recognize that “this problem could easily be solved with <insert concept here>.”

How to practice? There are options out the wazoo!

Chess puzzles, math problems, Sudoku, Go, Monopoly, video-games, cryptokitties, bla… bla… bla….

In fact, a common pattern amongst successful people is their habit of practicing “micro problem-solving.” For example, Peter Thiel plays chess, and Elon Musk plays video-games.

“Byron Reeves said ‘If you want to see what business leadership may look like in three to five years, look at what’s happening in online games.’

Fast-forward to today. Elon [Musk], Reid [Hoffman], Mark Zuckerberg and many others say that games have been foundational to their success in building their companies.” — Mary Meeker (2017 internet trends report)

Does this mean you should just play video-games? Not at all.

But what are video-games all about? That’s right, problem-solving!

So, what you should do is find an outlet to practice. Something that allows you to solve many micro-problems (ideally, something you enjoy).

For example, I enjoy coding challenges. Every day, I try to solve at least one challenge (usually on Coderbyte).

Like I said, all problems share similar patterns.

Conclusion

That’s all folks!

Now, you know better what it means to “think like a programmer.”

You also know that problem-solving is an incredible skill to cultivate (the meta-skill).

As if that wasn’t enough, notice how you also know what to do to practice your problem-solving skills!

Phew… Pretty cool right?

Finally, I wish you encounter many problems.

You read that right. At least now you know how to solve them! (also, you’ll learn that with every solution, you improve).

“Just when you think you’ve successfully navigated one obstacle, another emerges. But that’s what keeps life interesting.[…]

Life is a process of breaking through these impediments — a series of fortified lines that we must break through.

Each time, you’ll learn something.

Each time, you’ll develop strength, wisdom, and perspective.

Each time, a little more of the competition falls away. Until all that is left is you: the best version of you.” — Ryan Holiday (The Obstacle is the Way)

Now, go solve some problems!

And best of luck 🙂

本文章首发在 LearnKu.com 网站上。
本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。

原文地址:https://medium.com/free-code-camp/how-to...

译文地址:https://learnku.com/lifecoder/t/32774

本帖已被设为精华帖!
参与译者:6
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!