DEV Community

Cover image for Code Smell 141 - IEngine , AVehicle, ImplCar
Maxi Contieri
Maxi Contieri

Posted on • Edited on • Originally published at maximilianocontieri.com

8 3

Code Smell 141 - IEngine , AVehicle, ImplCar

Have you ever seen an IEngine in the wild?

TL;DR: Don't prefix or suffix your classes

Problems

  • Readability

  • Bijection Fault

  • Implementative Names

Solutions

  1. Remove prefixes and suffixes

  2. Name your objects after what they do

Context

Some languages have cultural conventions related to data types, Abstract classes, or Interfaces.

These names load our models with cognitive translations hard to follow.

We must KISS.

Sample Code

Wrong

public interface IEngine
{
    void Start();
}

public class ACar 
{

}

public class ImplCar 
{

}

public class CarImpl
{

}
Enter fullscreen mode Exit fullscreen mode

Right

public interface Engine
{
    void Start();
}

public class Vehicle 
{

}

public class Car 
{

}
Enter fullscreen mode Exit fullscreen mode

Exceptions

In C# it's a common practice to put "I" in the name of an interface because without it, you can't tell whether it is an interface or a class.

This is a language smell.

Detection

[X] Automatic

If we have a Thesaurus we can point to awkward names.

Tags

  • Naming

Conclusion

Use real names for your models.

Relations

More Info

Credits

Photo by Tim Mossholder on Unsplash


Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.

Jamie Zawinski


This article is part of the CodeSmell Series.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay