When I first started coding, I grossly underestimated the value of displaying information to the screen. I had the notion of "if it works, it works, and if it doesn't, it doesn't." Anyone who's been coding for a bit will probably laugh at that. I started with Python, and
Let's say you're just starting out, and you've got a simple for loop doing some math for you, but you're not getting the results you expected. You're probably wondering why, and how to find the problem. With production code, you want to be concise and efficient, but when you're learning, it's okay to be verbose. Do it. Look at the formula you're using, and put more variables in for testing purposes. Once you find the problem, you can edit your code to make it better (however you define "better").
In my recent attempt at solving Part 1, Day 1 of Advent of Code, I wasn't getting the sum as expected. I was keeping track of the running total(sum) in
total (original, right?), so I started sticking
console.log("current total is "+total); after every single line that did something. Hey, look at that! It's broken on line [whichever one it was]. I made adjustments, ran it again, got it right on the second try. I went back and took out all those
console.log statements, and it was nice and readable again.
console.log a lot of things, but couldn't figure out how to stick it in at certain points. A mentor introduced me yesterday to the concept of breakpoints. Super helpful! I was having difficulty visualizing what
$scope was holding at key points, and this solved it and let me see on my screen what it was and wasn't doing.
I cannot emphasize enough how helpful it is to literally see what your program is doing. Learn how to display things. It makes everything else you learn easier.