Skip to content

How to Debug

Kawin Nikomborirak edited this page Jul 2, 2024 · 23 revisions
  1. Use Perplexity Pro with the prompt "I am trying to build x using y framework. This is my code: and this is my error message: . How can I fix this?". I have seen people copy paste a part of the program output that does not actually contain the error, so make sure to give Perplexity as much of the program output as possible. Note that the free version of Perplexity often gives incorrect answers, so you will need to validate its outputs with your own googling. If you use Perplexity Pro, make sure to go to your settings and set your AI model to Sonnet 3.5, which is the best model as of July 1, 2024. The default model will often have incorrect responses. Feel free to use my referral code to purchase Perplexity Pro.

  2. Use GitHub to find solutions that google usually does not find. If you suspect your usage of a library is incorrect, look in GitHub for example code. If you are running into other issues, see if there is a related GitHub issue.

  3. If your error happens at runtime, your project has unit tests, and you have not written unit tests for your code yet, write a unit test and use a debugger to inspect the values of each variable at the problematic line. Refer to the existing tests in your code project for guidance on how to write your tests. Use the PyCharm or equivalent IDE debugger to run your unit test. As someone who used to print debug, it is worth learning to use your IDE's debugger because you can stop program execution at any line and evaluate any line that you want there. Some debuggers even let you preview array data as pictures, which you cannot do with print debugging. Using your debugger is as easy as right-clicking the run test button next to your unit test and clicking the debug button in most IDEs. You can create breakpoints to stop execution by clicking to the left of the line of code.

  4. Look at the stack trace in your error message and figure out the line in your code that is causing the issue. Follow the stack trace to figure out what you expect the values of each variable to be at that line. Usually that helps me understand what could have happened. While this step is hard, it is worth doing. Without being able to create your own insights about how code works, you will rely on your team to give you insight about the code. If your insights are the the same as your team's, your insights won't be useful to them.

  5. If there is no risk of leaking intellectual property, create a question on the appropriate question-answer site such as StackOverflow, AWS Support, or Apple Developer.

  6. If you must reach out to your team, tell them what you tried and your best guess for what the solution is. You can share your Perplexity thread to give them even more context on what you tried and what else you can try.

  7. If you have a choice, use JetBrains IDEs over other alternatives to write your code. There are multiple times I have used VSCode for Python or Java projects with the appropriate plugins where I spent hours debugging an issue just to find that PyCharm or IntelliJ would have detected those issues and warned me about them as I was writing the code. As someone who exclusively used Vim for two years before exclusively using Emacs for four years with a three-thousand line custom configuration, it is worth using IDEs configured by professionals to help you detect issues.

Clone this wiki locally