DEV Community

Samuel Lubliner
Samuel Lubliner

Posted on

1

Tips for programming and debugging code

Rubber Duck Debugging

  • Try talking through the problem as if you're explaining it to someone else.

Pseudocode

  • Write out the steps in comments.

Make the Invisible Visible

  • Print to verify what each step did
puts "My var here: #{my_var}"
Enter fullscreen mode Exit fullscreen mode
  • Make instance variables and embed them in the view.
<%= @my_variable.inspect %>
Enter fullscreen mode Exit fullscreen mode
  • Use the interactive console to display the contents of params, variables, and experiment to find solutions for the error.

  • Read the server log. (Clear with ⌘+k)

Try debugger

Add debugger to stop execution and inspect variables
c continue
n execute next line

Restart / Refresh

  • Restart server
  • Hard refresh the page

How to Solve It

  1. Understand the problem
  2. Make a plan
  3. Carry out the plan
  4. Reflect how could it be better

Understand the problem

  • What am I trying to accomplish?
  • Restate the problem.
  • Use a picture or a diagram.
  • Gather information to find a solution.
  • Understand all the words used in stating the problem.
  • Ask questions.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay