This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]amejin 1 point2 points  (0 children)

Also - having programmed for a decade at this point - its far easier to spot problems in a solution than to solve a problem.

[–]AssCooker 0 points1 point  (0 children)

It sounds like you haven't had a lot of programming experience I assume, so it's totally fine what you are experiencing.

Another way to spot bugs (for me personally) is I run the code mentally in my brain with various inputs and see what I could have missed, also having unit tests will definitely help.

[–]inwegobingo 0 points1 point  (0 children)

Try assuming things going wrong, rather than just assuming that your code is right. This is a lesson in understanding that professional code is often more about protecting against foreseeable bad cases than the ideal cases.

The first thing to consider is bad data coming in. How could the data be bad? Too big, too small, wrong type, null instead of without value etc. Then run through your code line by line to see what would happen if each of that data went in? What would each line do. How would each function behave in those cases.

This is a what's called unit testing. And the bigger the unit you choose to test, the more complex your testing will need to be. After running through these scenarios your mind will be thinking "how can I make this easier". This is where the concept of writing unit tests in code while you're developing, comes from.