There are two kinds of things you write, when you write a program:
- Things you're absolutely sure about
- The rest
Point 1 is things you write 10 times a day. You definitely know how to declare a string variable. You definitely know how to write a for loop. There's a bunch of other things you're firmly sure about. Point 2 is things you don't do every day. Or even things you never did before.
I'm pretty sure, there are only two points. There's no point 1.5 where you "well... sure" - it's always either you're sure or not.
Point 2 is when you feel uncertainty.
The worst thing one can do in this case is get some coffee, turn the brain off and try to do whatever needed. In most cases, it won't work. You write some code, you run your program and see it doesn't do what you expect. You make changes, you rerun it, same story. 10 minutes later you start thinking if it's not your issue, but some other code, you spend 20 minutes more to check it and so on.
There's a trick. If there's at least a minimal uncertainty, the best thing to do is just start a new project aimed to increase your confidence. Think out the simplest task possible and get it done. Make it more and more complex unless it becomes what you really need. One can think it requires much more time, but the funny thing is - it always takes less than approach I described before.
Discover the power of "Hello World"
Whenever you start learning something new (or just about to do something you don't do every day), the best thing to do first is write a "Hello World". It's not because there's a tradition. It's because you need to test your adequacy first. You make sure you understand what you do. You make sure your environment is ready.
The power of "Hello World" is in its simplicity. The key point here is to take a task you're absolutely sure about and then get it done. If your confidence was reasonable, you'll get it confirmed. Otherwise, you'll realize that even a simplest program doesn't do what you expect it to do and this means that something is wrong.
Let's say you've never tried unit testing before and so one day you decide to check what JUnit is. It's a tool that runs pieces of code and every piece of code either fails or succeeds. It's that simple. So, the good "Hello World" is to write 2 tests: the empty one (to make sure it will never fail) and the failing one (to make sure it always fails). When you run these tests, you know what to expect. If your expectations were right, you'll make sure everything is fine. Otherwise, you'll have a great small illustration of how to make it not work.
Another good example is ORMs. You decided to learn Entity Framework. ORM is basically a tool to make your database interactions look like there are no database interactions at all. What you normally do to database is CRUD operations. So just take NUnit and write a test where you create something, read it, update it and then delete it. It's 20 lines of code and at most 1 hour of your time including googling, but you're now confident you know how to do it.
As long as you write Hello Worlds before making changes to the real code, there are just no complicated tasks for you. Don't be a hero. Just simplify the way you do it.