2. Start unit testing your code, there are plenty of libraries available for this.
3. It comes with experience.