Code Smell 113 — Data Naming

TL;DR: Don’t name your variables as Data.

Problems

  • Readability
  • Bad Naming

Solutions

1. Use role suggesting names.

2. Find names in the Bijection.

Context

We use ‘data’ a lot in our variables.

We are used to doing it.

Using this kind of name favors the anemic treatment of objects.

We should think about domain-specific and role-suggesting names.

Sample Code

Wrong

if (!dataExists()) {
return ‘<div>Loading Data…</div>’;
}

Right

if (!peopleFound()) {
return ‘<div>Loading People…</div>’;
}

Detection

[X] SemiAutomatic

We can check for this substring on our code and warn our developers.

Tags

  • Readability
  • Naming

Conclusion

Data is everywhere if you see the world as only data.

We can never see the data we manipulate.

We can only infer it through behaviour.

We do not know the current temperature. We observe our thermometer pointing at 35 degrees.

Our variables should reflect the domain and role they are fulfilling.

Naming them as ‘data’ is lazy and hinders readability.

Relations

More Info

Twenty percent of all input forms filled out by people contain bad data.

Dennis Ritchie

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to use a various database with Ruby on Rails

Connected cars 🏎 — what are they and how to get started developing connected car apps

An Introduction to Writing FP16 code for NVIDIA’s GPUs

How to handle uploading and parsing files in your frontend app tests

Uploading and parsing files in Mirage for the Qonto app

Welcome to Web 3.0 Web’s Adulthood

Parallel computing

CS373 Fall 2020: Michael Liu

Transitioning From SWE To DE

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maximiliano Contieri

Maximiliano Contieri

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

More from Medium

Code Smell 107 — Variables Reuse

Defensive Programming Techniques

SOLID Principles made easy

Effective Code Review