There are two types of software development—brownfield development and greenfield development. The majority of the code we work on throughout our careers will be brownfield development, which is the maintenance and extension of existing software, while greenfield development is the development, maintenance, and extension of new software. With greenfield software development, you are afforded the opportunity to write clean code from the start, and I encourage you to do just that.
Make sure that projects are properly planned before you work on them. Then, employ the tools available to you to develop clean code with confidence. When it comes to brownfield development, you are best off spending time getting to know the system inside out before you maintain or extend it. Unfortunately, you may not always be in a situation where time affords you such luxury. So, there may be times when you will set about writing the code you need, not realizing that code...