cssmagic/Learn-AI-Assisted-Python-Programming

[译] [800] 第八章 调试代码并且更深入地理解代码

cssmagic opened this issue · 1 comments

8 Debugging and Better Understanding Your Code

第八章 调试代码并且更深入地理解代码

This chapter covers

本章内容概要

  • Determining the source of a bug

  • Fixing errors with Copilot techniques

  • Debugging code with Copilot

  • Using VS Code debugger to see how code is functioning

  • 查明 bug 的根源

  • 通过 Copilot 技巧修正错误

  • 借助 Copilot 对代码进行调试

  • 使用 VS Code 的调试器观察代码如何运作

There will be a point in every programmer’s career when their code isn’t doing what they want it to do. This has likely happened to you already, and, rest assured, it is a normal part of learning to program. How do we fix the code? Sometimes, changing the prompt or better decomposing the problem like you learned in earlier chapters is sufficient to fix the problem. But what do you do when you just can’t get Copilot to give you different or better code, and you can’t seem to figure out why the code you’ve been given doesn’t work properly?

在每位程序员的职业道路上,都会遇到代码不按他们所愿执行的时刻。这很可能已经发生在你身上,而且,请放心,这是学习编程过程中的一部分。我们如何修正代码?有时,改变提示词或者如前几章所学,更精确地分解问题就足以解决问题。但是,当你无法让 Copilot 提供不同或更好的代码,又或者无法搞清楚为什么你得到的代码不能正常工作时,你应该怎么办?

This chapter serves two purposes. The primary goal is to learn how to find errors (called bugs) in the code and fix them. To find those bugs, you’ll need to fulfill the second goal, which is gaining a deeper understanding of how your code works while you are running it.

本章节的目标有二。首要任务是学习如何发现代码中的错误(俗称 bug)并予以修复。而为了找到这些错误,你还需实现第二个目标,那就是在代码执行时深入理解其运作原理。

The good news is that having an error in your code is such a common occurrence for programmers that programming environments, like Visual Studio Code (VS Code), have tools to help us uncover what is going wrong. We’ll learn how to use that tool, called a debugger, in this chapter as well.

值得庆幸的是,代码出现错误对编程人员来说极为常见,以至于像 Visual Studio Code(VS Code)这种编程环境都配备了工具来帮助我们找出问题所在。本章我们将学习如何使用这种称为调试器的工具。

...

...


本章目录

  • 8.1 What causes errors (bugs)?
  • 8.2 How to find the bug
    • 8.2.1 Using print statements to learn about the code behavior
    • 8.2.2 Using VS Code’s debugger to learn about the code behavior
  • 8.3 How to fix a bug (once found)
    • 8.3.1 Asking Copilot to fix your bug via chat
    • 8.3.2 Giving Copilot a new prompt for the whole function
    • 8.3.3 Giving Copilot a targeted prompt for part of a function
    • 8.3.4 Modifying the code to fix the bug yourself
  • 8.4 Modifying our workflow in light of our new skills
  • 8.5 Applying our debugging skills to a new problem
  • 8.6 Using the debugger to better understand code
  • 8.7 A caution about debugging
  • 8.1 导致错误(bug)的原因是什么?
  • 8.2 如何定位 bug
    • 8.2.1 使用 print 语句来了解代码的行为
    • 8.2.2 使用 VS Code 的调试工具来了解代码的行为
  • 8.3 找到 bug 后如何修复
    • 8.3.1 通过对话让 Copilot 帮你修复 bug
    • 8.3.2 为整个函数给 Copilot 一个新的提示
    • 8.3.3 为函数的一部分给 Copilot 一个具体的提示
    • 8.3.4 自己修改代码修复 bug
  • 8.4 根据新技能调整我们的工作流
  • 8.5 将调试技巧应用到新问题上
  • 8.6 使用调试器更深入地理解代码
  • 8.7 调试的注意事项

本章正文略。如需阅读,请购买正版。


👉 想要更多译稿预览,请前往 总目录 中按章节阅读。