Dev Genius

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

Follow publication

Code Smell 27 — Associative Arrays

Maximiliano Contieri
Dev Genius
Published in
Nov 18, 2020

Photo by Melissa Askew on Unsplash

Problems

  • Coupling
  • Information Hiding
  • Code Duplication
  • Fail Fast
  • Integrity

Solutions

  1. Reify objects
  2. Create cohesive small objects
  3. Don’t leave them anemic, find their cohesive relations.

Sample Code

Wrong

Anemic

Validated

Right

Degrees deserves reification

Many people suffer from primitive obsession and believe this is over design. Designing software is about making decisions and comparing trade-offs. The performance argument is not valid nowadays since modern virtual machines can efficiently deal with small short-lived objects.

Detection

We cannot forbid Associative Arrays since they are very good as a first approach.

They will be fine for exporting data, serialization, persistence and other accidental implementation issues.

We should avoid them on our systems.

Tags

  • Primitive

Conclusion

When creating objects we must not think of them as data. This is a common misconception.

We should stay loyal to our Bijection and discover real world objects.

Most associative arrays have cohesion and represent real world entities, and we must treat them as first class objects.

Relations

There’s nothing more permanent than a temporary hack.

Kyle Simpson

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