I wasted 3 years writing bad code. Here’s how I finally improved.