博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
中学编程_如何知道何时从编程问题中学到了一切
阅读量:2520 次
发布时间:2019-05-11

本文共 11772 字,大约阅读时间需要 39 分钟。

中学编程

The answer may seem obvious: you’re done with a problem once you’ve solved it.

答案似乎很明显:解决问题后,您就可以解决问题。

That’s how I approached problem-solving when I began learning to code. I was on a problem-solving treadmill: solving as many as quickly as possible.

这就是我开始学习编码时解决问题的方式。 我当时正在解决问题的跑步机上:尽快解决许多 。

And why not? There’s no shortage of problems to solve. Besides, don’t you get better by solving more problems? More to the point: what else can you do once you have the answer? As it turns out, quite a bit. The fallacy of my approach soon surfaced.

那么为何不? 不乏要解决的问题。 此外,您是否通过解决更多问题而变得更好? 更重要的是:一旦找到答案,您还能做什么? 事实证明,有很多。 我的方法的谬误很快浮出水面。

Although I solved the problem, I didn’t learn much from it. That’s because a few days or weeks later when I tried to re-solve the problem or when I came across a related one, I got really . Mistakes were made. Concepts were confused. Progress was stalled.

尽管我解决了这个问题,但是我并没有从中学到很多。 那是因为几天或几周后,当我试图重新解决问题时,或者遇到一个相关问题时,我真的 。 犯了错误。 概念感到困惑。 进展停滞了。

I now realize that getting the solution is only part of the problem-solving process. Then, in the words of a mathematician named George Pólya, it’s time to “look back.”

我现在意识到,获得解决方案只是解决问题过程的一部分。 然后,用一位名叫乔治·波利亚(GeorgePólya)的数学家的话来说,是时候“回头看”了。

回头看 (Looking Back)

Pólya writes about the problem-solving process in his book, How to Solve It, through the lens of mathematical problem-solving. But his ideas are applicable to programming. What’s particularly interesting to me is his fourth phase: looking back.

鲍利亚(Pólya)通过数学解决问题的视角,在他的《 如何解决问题》一书中谈到了解决问题的过程。 但是他的想法适用于编程。 对我来说特别有趣的是他的第四阶段:回顾过去。

“By looking back at the completed solution, by reconsidering and reexamining the result and the path that led to it, [students] could consolidate their knowledge and develop their ability to solve problems,” Pólya writes.

“通过重新考虑并重新审查结果以及导致结果的途径,回头看完整的解决方案,[学生]可以巩固他们的知识并发展他们解决问题的能力,”Pólya写道。

In some ways, solving a problem is like creating a piece of art. There’s always something more we could do. “We could improve any solution, and, in any case, we can always improve our understanding of the solution,” explains Pólya.

在某些方面,解决问题就像创造一件艺术品。 总有更多事情我们可以做。 “我们可以改善任何解决方案,在任何情况下,我们始终可以提高对解决方案的了解,”Pólya解释说。

For me, “looking back” is a practice of self-improvement and . The aim is to:

对我来说,“回头看”是一种自我完善和的习惯。 目的是:

  • Learn from my successes: understand what you wrote and why.

    从我的成功中学习:了解您写的内容和原因。
  • Solidify my learning of new concepts.

    巩固我对新概念的学习。
  • See patterns and understand the context for using a particular data structure or algorithm.

    查看模式并了解使用特定数据结构或算法的上下文。

Consider a basketball player who takes 1,000 shots each day. That sounds admirable. But as he rushes to get the 1,000 shots in, his form gets sloppy. He uses the wrong technique.

考虑一个每天要拍摄1000次球的篮球运动员。 听起来很棒。 但是,当他急于获得1,000张相片时,他的状态变得草率。 他使用了错误的技术。

He’d benefit more from taking a few hundred shots, then evaluating his performance: watching a video recording of his form, seeing the flaws, and correcting them. Then, he'd hit the court again.

通过拍摄几百张照片,然后评估他的表现,他会从中受益更多:观看自己形式的视频记录,查看缺陷并进行纠正。 然后,他又去了球场。

Now he’ll be more informed, since he looked back and evaluated his performance. He’ll practice better.

现在,他会更加了解情况,因为他回头评估了自己的表现。 他会练习得更好。

The same is true with solving problems. The idea isn’t to check a box so you can claim you solved “x” number of problems. Instead it’s doing your best work each time and learning as much as possible along the way.

解决问题也是如此。 这个想法不是要选中一个框,因此您可以声称自己解决了“ x”个问题。 相反,它每次都尽力而为,并在此过程中尽可能多地学习。

There are three reasons why looking back matters.

回顾问题有三个原因。

原因1:查看模式并了解上下文 (Reason 1: See the Patterns and Understand the Context)

You’ll see similar patterns over and over again in the problems you solve.

在解决的问题中,您将一遍又一遍地看到类似的模式。

Understand how to use a particular algorithm, like binary search. Train your eye so you know when and how to apply it. So when you encounter a related problem in the future, you’ll be ready. Doing so will save time (and frustration) in the long run.

了解如何使用特定算法,例如二进制搜索。 训练您的眼睛,以便您知道何时以及如何使用它。 因此,将来遇到相关问题时,您就可以准备就绪。 从长远来看,这样做可以节省时间(和挫败感)。

原因2:巩固您的学习 (Reason 2: Solidify Your Learning)

Say you used something that’s new to you to solve a problem, like a stack or queue.

假设您使用了新的东西来解决问题,例如堆栈或队列。

Do you really know how to use it again? Do you feel comfortable using a stack in a related problem? Take the time to understand anything new you used so you can use it again in the future.

您真的知道如何再次使用它吗? 在相关问题中使用堆栈是否感到舒适? 花时间了解您使用过的所有新内容,以便将来再次使用。

原因3:从成功中吸取教训 (Reason 3: Learn from Your Successes)

Mathematician Richard Hamming gets to the heart of the matter with this quote from his book, The Art of Doing Science and Engineering.

数学家理查德·汉明(Richard Hamming)从他的著作《科学与工程的艺术》中引述了这一问题

“I regard the study of successes as being basically more important than the study of failures...there are so many ways of being wrong and so few of being right, studying successes is more efficient.”

“我认为对成功的研究基本上比对失败的研究更为重要...错误的方法太多,正确的方法很少,成功的研究更加有效。”

As programmers, we deal with our fair share of errors. And then (many tries later) we run the program and it works. Now is a great time to put Hamming’s words to practice and study your success.

作为程序员,我们应对我们应有的错误。 然后(很多以后再试),我们运行该程序,它开始工作。 现在是时候练习汉明的话来练习和学习您的成功了。

Do you understand how your program works? Do you understand what you wrote and why you wrote it?

您了解您的程序如何工作吗? 你明白你写的, 为什么你写的?

By looking back⁠—when the information is still fresh in your mind⁠—you’re preparing your future self. It’ll help you bridge your understanding and solidify your mental models. It’ll help you improve and prevent repeating the same mistakes over again. In short, it’ll help you get better.

回顾过去(当您仍然想起信息时)⁠,您正在准备自己的未来。 它可以帮助您架起理解并巩固您的思维模式。 它可以帮助您改善并防止重复相同的错误。 简而言之,它将帮助您变得更好。

回顾的四种方式 (Four Ways to Look Back)

There are a few ways that I “look back” at problems. Give them a try.

我可以通过几种方式“回顾”问题。 试试看。

自学 (Teach Yourself)

A fantastic way to help solidify your mental models is to teach yourself. After you complete a program or problem, go through your code and explain it line by line. It’s one of the best ways of “looking back” when you’re learning something new.

巩固自己的思维模式的一种绝妙方法是教自己。 完成程序或问题后,遍历代码并逐行说明。 这是学习新事物时“回头看”的最佳方法之一。

I’ve found this process invaluable while learning web development. After I complete a project, I copy my code into a Google Doc. Starting at the top, I make comments throughout to teach myself about important concepts.

我发现学习Web开发时这一过程非常宝贵。 完成项目后,我将代码复制到Google文档中。 从顶部开始,我会发表评论,以自学重要的概念。

Here’s an example of some code and some of the comments I wrote.

这是一些代码和我写的一些注释的示例。

export default function ManageTeamMembersPage(props) {     const [teammate, setTeammate] = useState({       name:"",       email: "",       role: "",   })      ...
  • Use props to access data passed down from the parent component.

    使用道具访问从父组件向下传递的数据。
  • Add state hook. The hook takes a default, which is an object that contains everything I need for the form: name, email, role.

    添加状态挂钩。 挂钩采用默认值,它是一个对象,其中包含我需要的形式:名称,电子邮件,角色。

This method of “looking back” is about understanding. In this example, I was learning about state, props, and forms in React.

这种“回头看”的方法就是了解。 在这个示例中,我正在学习React中的状态,道具和形式。

Writing out comments to explain your code will help you solidify concepts in your mind. If you can’t type a short explanation of it on the spot, then revisit the topic.

写出注释来解释您的代码将帮助您巩固思想。 如果您不能在现场输入简短的说明,请重新访问该主题。

This method is equally useful for future problems and projects. I regularly pull up old problems and programs I’ve notated. I use them as a reference when writing related programs or solving related problems. Doing so reinforces key ideas, and to Hamming’s point, it helps me remember my successes: what to keep doing.

该方法对于将来的问题和项目同样有用。 我会定期提出我提到的旧问题和程序。 在编写相关程序或解决相关问题时,我将它们作为参考。 这样做可以加强关键思想,汉明(Hamming)指出,这可以帮助我记住自己的成功:继续做什么。

优秀程序员的学习解决方案 (Study Solutions of Great Programmers)

It’s not only useful to study your own code, but also the code of others who have solved the same problem. There are a lot of out there and we can learn from them.

学习自己的代码不仅有用,而且对解决相同问题的其他人的代码也很有用。 有很多 ,我们可以向他们学习。

After I solve a problem, I apply to become a better writer. His process involved trying to reproduce an article from a publication he admired after he’d forgotten the details of it.

解决问题后,我运用成为更好的作家 。 他的过程包括尝试从他遗忘的细节之后复制他欣赏的出版物的文章。

I follow a similar process to become a better programmer.

我遵循类似的过程来成为更好的程序员。

Here’s how it works:

运作方式如下:

  • Solve a problem.

    解决问题

  • Find a programmer who’s better than you and who’s solved the same problem.

    寻找一个比您强并且可以解决相同问题的程序员。

  • Study their solution: read each line of code and type a comment in your editor to explain it.

    研究他们的解决方案 :阅读每一行代码,然后在编辑器中输入注释以对其进行解释。

  • Re-solve the program after some time has passed. Use the comments you typed out as hints to guide you along the way.

    经过一段时间后,请重新解决程序 。 使用您键入的注释作为提示,以指导您进行操作。

  • Compare your program to the one you studied.

    将您的程序与您所学习的程序进行比较

To be clear, this practice isn’t about memorizing or copying someone else’s code—far from it. Rather, it’s about learning: get practice code; see another way to solve the same problem; experiment with new parts of a language; and get practice teaching yourself. It’s also about applying what you’ve learned by putting it into your own style.

需要明确的是,这种做法不是要记住或复制别人的代码,而是远离它。 而是关于学习:获得练习代码的机会; 看到解决相同问题的另一种方法; 试验语言的新部分; 并练习教自己。 这也与将您学到的知识运用到自己的风格中有关。

添加约束 (Add a Constraint)

See how different techniques apply to the same problem when you add a constraint. For example, you solved the problem using a hash table. Now try solving it using an array.

添加约束时,请查看不同的技术如何应用​​于相同的问题。 例如,您使用哈希表解决了该问题。 现在尝试使用数组解决它。

The idea is to gain another perspective, and adding a constraint can do just that. It’ll get you out of your comfort zone, forcing you to think creatively.

这个想法是获得另一个观点,而添加约束可以做到这一点。 它会让您脱离舒适区,迫使您进行创造性思考。

As a result, you may find a slicker approach and cut the length of your program in half. Or may realize what data structure not to use, which is equally important.

如此一来,您可能会发现一种更流畅的方法,并将程序长度减少了一半。 或者可以意识到使用什么数据结构,这同样重要。

Here’s the point: you’ll have another approach at your ready when you’re faced with a related problem in the future.

重点是:将来遇到相关问题时,您将准备好另一种方法。

The programming website LeetCode is great for many reasons. One is providing similar questions for problems that you solve.

编程网站LeetCode的出色表现有很多原因。 一种是针对您要解决的问题提供类似的问题。

In one problem on LeetCode you are given an array of integers and a target number. The aim is to find two numbers that add up to the target and return their indices.

在LeetCode的一个问题中,将为您提供一个整数数组和一个目标数字。 目的是找到两个与目标加起来并返回其索引的数字。

You solve the problem.

您解决了问题。

Now solve a related one, which LeetCode provides. This time you’re given an array of integers that’s sorted in ascending order, along with a few additional constraints to differentiate this problem from the previous one.

现在解决一个由LeetCode提供的相关问题。 这次,您将获得一个按升序排序的整数数组,以及一些其他限制,可以将这个问题与上一个问题区分开。

Solving a related problem is a great way to get practice using a similar technique, data structure, or algorithm in a different context.

解决相关问题是在不同环境中使用相似的技术,数据结构或算法进行练习的好方法。

Looking back focuses on the process, instead of the end result. And revisiting the process matters. It’s getting out of your comfort zone, trying something new whether that’s a data structure or algorithm. It’s realizing there are different ways to solve the same problem. It’s understanding how to write better code. It’s about learning.  

回顾着眼于过程 ,而不是最终结果。 并重新访问该过程很重要。 它正在走出您的舒适区,尝试新的东西,无论是数据结构还是算法。 它意识到解决相同问题的方法有多种。 了解如何编写更好的代码。 这是关于学习。

Yes, it takes some time to look back. But it’s time well spent: it’s how we get better.

是的,需要一些时间来回顾。 但是时间花在了身上:这就是我们变得更好的方式。

I write about the programming skills you need to master and the concepts you need to learn, and the best ways to learn them ().

我写了有关您需要掌握的编程技能和需要学习的概念以及学习它们的最佳方法( )。

翻译自:

中学编程

转载地址:http://evzzd.baihongyu.com/

你可能感兴趣的文章
几道面试题
查看>>
【转】使用 WebGL 进行 3D 开发,第 1 部分: WebGL 简介
查看>>
js用正则表达式控制价格输入
查看>>
chromium浏览器开发系列第三篇:chromium源码目录结构
查看>>
java开发操作系统内核:由实模式进入保护模式之32位寻址
查看>>
第五讲:单例模式
查看>>
Python编程语言的起源
查看>>
Azure ARMTemplate模板,VM扩展命令
查看>>
(转)arguments.callee移除AS3匿名函数的侦听
查看>>
onNewIntent调用时机
查看>>
MYSQL GTID使用运维介绍(转)
查看>>
04代理,迭代器
查看>>
解决Nginx+PHP-FPM出现502(Bad Gateway)错误问题
查看>>
Java 虚拟机:互斥同步、锁优化及synchronized和volatile
查看>>
2.python的基本数据类型
查看>>
python学习笔记-day10-01-【 类的扩展: 重写父类,新式类与经典的区别】
查看>>
查看端口被占用情况
查看>>
浅谈css(块级元素、行级元素、盒子模型)
查看>>
Ubuntu菜鸟入门(五)—— 一些编程相关工具
查看>>
PHP开源搜索引擎
查看>>