• Skip to main content
  • Skip to primary sidebar

Phelela

  • Phelela
  • Engineer Path
  • My Project
  • Home Office
  • Day Off
  • My GitHub

10 Most Common Mistakes in Code Optimization and How to Avoid Them

11. December 2024

I’m a fan of optimization. My coding process consists of three parts: designing new features, testing, and optimizing. In my previous article, I focused on how optimization can reduce energy costs. After receiving several messages about optimization, I decided to describe the most common mistakes that occur during optimization. Let’s take a look at them today.

1. Optimizing before testing

  • Testing should precede optimization. Before diving into optimizing your code, ensure that everything works correctly according to the design and requirements. There’s no point in optimizing a broken feature.

2. Relying solely on intuition

  • If you don’t have profiling tools like cProfile in your toolkit, add them. Optimizing based on intuition is not a good idea because you end up optimizing assumptions instead of actual performance.

3. DRY vs. WET

  • Two popular programming paradigms, DRY (Don’t Repeat Yourself) and WET (Write Everything Twice), require consistency. Choose one and stick to it. Personally, I prefer WET, so if something appears in the code more than twice, I focus on optimization.

4. Inefficient algorithms

  • Inefficient algorithms can lead to trouble. Many developers today lack a strong foundation in algorithm design, but the truth is that algorithms make tasks easier. If you know only one sorting algorithm, invest more time in learning new approaches.

5. Overlooking readability

  • This often happens with excessive optimization. Too much of a good thing can be harmful, and optimization is no exception. I’ve frequently seen comments disappear or code blocks become less readable than the original. This should never happen—optimization should improve, not degrade, the code.

6. Ignoring memory usage

  • Faster code isn’t enough if it’s at the expense of memory. Optimization that sacrifices memory efficiency is not done correctly.

7. Neglecting tests

  • Tests often face skepticism. I’m not an advocate for 100% code coverage. Personally, I think it’s not feasible. However, after refactoring, updating or writing new tests should follow.

8. Focusing on minor details

  • This is my least favorite issue, which I’ve encountered many times in practice. Optimizing minor details while neglecting the system as a whole.

9. Forgetting about caching

  • Caching is one of my favorite strategies—perhaps because it’s where my love for optimization began. If you’re repeatedly performing the same computation, it’s time to embrace caching strategies.

10. Missing documentation

  • Sometimes, documentation feels like a mythical creature in programming. Everyone talks about it, everyone knows about it, but almost no one has seen it. Please, love documentation. Document your changes. It helps not only your colleagues understand the system but also juniors who appreciate every bit of guidance. Lastly, it will help you when you revisit your work after a long time.

Conclusion

Optimization is, to some extent, an art of balancing performance, sustainability, and code readability. Avoiding the most common mistakes will make optimization your best friend, as it has become mine. The great thing about optimization is that you can never be a champion—you always have the opportunity to learn something new about it.

in Engineer Path

Reader Interactions

you may also like
I’ll Remember This – Or Not: The Power of Documentation
How to Organize and Manage Issues Efficiently in Software Development
Mastering the Development Cycle: A Guide to Writing Better Code
GreenTech: How Developers Contribute to Sustainability

Leave a Reply Cancel reply

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

Primary Sidebar

Katarína Kováčová

Hi, I’m Katarina. I'm a backend software engineer. My specialization is Python backend development, and I like the Kotlin programming language. I started this blog as a space to share my journey in tech. It also serves as a portfolio of my work and a place for exciting topics.

When I’m not coding, I get lost in the fascinating world of sudoku. Welcome to my corner of the internet.

Archive

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024

My life in pictures

This year will be mine. I belive I will beat my obesity.
My first work with GCP – I was on a Cloud 9.
I really adore old cars. They are elegant and beautiful.
Need some rest and a good book in Spanish. Maybe Harry Potter?
I started with regular running and I feel incredible.
2025 © Phelela
theme by soleilflare