Why Writing Terrible Code Can Be a Good Thing

Why Writing Terrible Code Can Be a Good Thing

Howdy!

As a beginner or junior developer, you might feel immense pressure to write perfect code from the get-go (especially when you have tight deadlines and things need to go quick). However, this mindset can be counterproductive.

Writing terrible code initially is not only acceptable but can be a crucial part of the development process. In this article, we’ll explore why starting with messy code is beneficial and how you can refine it into something great over time!

✏️The Importance of Prototyping✏️

When you begin a new project, your primary goal should be to get something working quickly. This is known as prototyping. Prototyping allows you to:

  • Validate ideas and concepts.
  • Identify potential problems early.
  • Receive early feedback from stakeholders or users.

Think of your initial code like planting a garden. At first, it looks like a mess of dirt and seeds with no apparent order. The key is to get a basic version of your project up and running.

😱Embracing the Ugly😱

It’s easy to get bogged down by trying to make your code perfect from the start. Here’s why embracing the ugly phase is important:

  • Focus on functionality: Prioritize making your code work correctly first. Worry about optimization and cleanliness later.
  • Encourage experimentation: When you’re not worried about perfection, you’re more likely to try new things and learn from mistakes.
  • Reduce procrastination: Perfectionism can lead to procrastination. Accepting that your code doesn’t need to be perfect can help you move forward faster.

In fact, I’ve had my share of projects that suffered from over-engineering/perfectionism. One that comes to mind was a script that would consume an API from a vendor. I developed this in such a way that it could handle multiple types of vendor data. That doesn’t sound too bad, right? Sounds like future-proofing. But if we are being honest, it was actually solving a problem we didn’t have. Yes, it did handle our requirement for the vendor we had, however, it was unnecessarily complex to the point that it not only took longer for me to develop it, but it also slowed down the other developers that I was building it for.

Remember we are embracing the ugly when we start, this doesn’t mean we won’t tend our code into a better version of itself, we must first keep our focus on coding something that actually works!

Normally we want to discourage certain things such as:

  • Multiple Nested loops?
  • Hardcoded variables?
  • Code duplication?

But for the sake of getting a working solution, allow yourself to introduce these in your first version, once we get it working we will want to refine the code and remove these from your final version. Again -we want to focus on solving the problem.

🔬Refining the Code🔬

Once you have a working prototype, it’s time to refine it. This process is similar to tending your messy garden. As you tend to it, water it, and pull out the weeds, it gradually grows into a beautiful, organized garden:

  1. Identify pain points: Look for areas of the code that are particularly messy or inefficient.
  2. Optimize gradually: Tackle one issue at a time, improving the code step-by-step. (Commit often)
  3. Refactor regularly: Refactoring involves restructuring existing code without changing its behavior. This improves readability, maintainability and performance.
  4. Test thoroughly: Ensure that each change doesn’t introduce new bugs. Writing tests can help automate this process.

Thanks to our initial acceptance of the messiness, we don’t have to think about solving the problem anymore. Our focus here is to keep our code working while transforming it into a maintainable project.

Speaking of maintainability..

🛠️The Beauty of Iteration🛠️

After our refinement we will move on to Iterative development. This is the process of marking small, incremental improvements over time. This approach has several benefits:

  • Flexibility: You can adapt to changes more easily as your project evolves.
  • Continuous learning: Each iteration provides an opportunity to learn and apply new techniques.
  • Progress Tracking: Regular updates help you track progress and maintain momentum.

Remember earlier how we talked about avoiding perfectionism? Well If we tried to build out our idea of our perfect code from the beginning, we might be pulling our hair out when the project’s requirement changes or we have to refactor a large chunk of our code. Kind of like stomping all over your garden, and having to start over (Maybe that’s a bit over the top, but I think you get the idea).

We might still need to rewrite parts of our code, but it will be less burdensome if we didn’t over-engineer from the start.

So to summarize

Writing terrible code initially is not only acceptable but beneficial. By focusing on getting your code to work first, you can create a solid foundation to build upon. Remember, just like a garden needs time to grow and flourish, your code needs time and iterations to become clean and efficient. Embrace the process and enjoy the journey of continuous improvement. Let’s stop the perfectionism and level up our coding! 😄

What do you think about these ideas? Share your experiences and challenges with writing code in the comments below. Let’s learn and grow together!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *