r/learnprogramming • u/Total-Subject2763 • Mar 07 '23
Is it normal as a junior programmer..
To spend hours looking over the same block of code, trying to sort out ‘why the f*ck isn’t this working!?’, only to realize the error you made is so monumentally, and stupidly obvious that it leaves you feeling like a completely useless moron? Lol
1.6k
Upvotes
118
u/dmazzoni Mar 07 '23
Yes, it's normal!
However, with experience you can reduce the time.
I think the biggest mistake I see a lot of junior programmers making is not checking their assumptions.
You added a new line of code, and you ran your program again. Now it doesn't work. You assume the problem is with that new line of code so you spend an hour studying that line of code.
Actually, it turns out the problem wasn't there. You accidentally typed an extra character at the top of the file while saving, and that was the problem all along.
How can you discover that faster?
By using version control, and testing your assumptions. Here's my exact thought process:
I believe the problem is with the line of code I just added, so if I comment it out the program should work again.
Wait, it's still broken! Now I know my assumption was wrong.
Thankfully I'm using Git, so I can do a "diff" to see what I've changed since the last time I did a "git commit".
Hmmm, I still don't see the issue, so let me stash my changes or save them in a branch called "broken" and go back to the last commit.
Hooray, the last commit worked!
Now my working assumption is that something that changed between my last commit, and the "broken" branch is the problem.
But, test that assumption. Go back to the broken branch. Is it still broken?
Yes, it's still broken. Now I'm confident the problem is in the changes on that branch.
Now I can approach this methodically. Look at every change, one line at a time. If I don't see the problem, I can still try reverting every individual change until I find the one that broke it.
It sounds tedious, but approaching it methodically like that will likely lead to finding the issue in a few minutes, rather than hours.
Oh, and notice that it's absolutely key that you use Git and commit frequently.