IonicaBizau / ama

:speech_balloon: Ask me anything!
18 stars 3 forks source link

How to debug code? #5

Closed MaraAlexa closed 8 years ago

MaraAlexa commented 8 years ago

Cand ceva e gresit in codul pe care il scrii cum gasesti greseala? Ce pasi mentali faci sa ajungi la ce nu e bun? Ce tools folosesti ca sa faci debugging mai rapid/eficient. Cum minimizezi erorile din cod (ce strategie ai ca sa minimizezi erori?)

When something in your code is wrong how do you find the problem? What mental steps do you follow? What tools do you use to make debugging more efficient/fast? How do you minimize the errors when you write code?

Thanks

IonicaBizau commented 8 years ago

Well, that's simple: I just open the debugger (the browser developer tools if I want to debug client side code, or the Node.js debugger—node debug foo.js).

I debug the things from the highest level to the lowest one.

Simple example:

let foo = () => false;
let bar = () => foo();
console.log(bar());

I want this to output true, not false. So, I know that console.log receives false so I have to go inside of bar. bar is calling foo and foo returns false. I changed it to true and the problem is solved.

How do you minimize the errors when you write code?

I don't. Errors are simple to solve because you know why and where they appear. I usually just write the code and run it when I'm done. :sparkle: