Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Code Smell 20 — Premature Optimization

Planning ahead of time needs a crystal ball no developer has.

Photo by Markus Spiske on Unsplash

Problems

  • Coupling
  • Testability
  • Readability
  • YAGNI

Solutions

  1. Create great models and bijections first.
  2. Create a conclusive benchmark once the model is working.
  3. Programmers waste enormous amounts of time worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. Donald Knuth
  4. Design for Performance.
  5. Use Test Driven Development technique. It always favors the simplest solution.

Examples

  • Weird data structures
  • Caches
  • Singletons

Sample Code

Wrong

Right

Detection

This is a design smell so it can not be detected by mechanical tools (yet).

Tags

  • Premature Optimization
  • Antipattern

Conclusion

Defer performance decisions until functional models are mature enough.

Donald Knuth created/compiled the best/fastest algorithms and data structures. With great wisdom he warned us of abuse. Why do we think we are smarter than him?

Relations

More info

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Maximiliano Contieri

I’m a senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan. Maximilianocontieri.com

No responses yet

Write a response