DEV Community

Cover image for #002 - Clean Code - Names

#002 - Clean Code - Names

Omar on August 29, 2020

Names Reveal your Intent Intent : Nawaya in Arabic Variables are all around the programm having good names will help read ...
Collapse
 
vlasales profile image
Vlastimil Pospichal

Hungarian notation is still alive:
class Logger implements ILogger
I hate the prefix "I".

Collapse
 
thinkverse profile image
Kim Hallberg

Have you tried the contract naming? Instead of I it would be LoggerContract.

Collapse
 
vlasales profile image
Vlastimil Pospichal

No, in my opinion it's bad just the same. I use adjectives derived from the names of the required methods. The interface tells the class what capabilities it must have. Contract tells word contract only, no ability.

Thread Thread
 
alainvanhout profile image
Alain Van Hout

Indeed. It's an odd dissimilarity between C# and Java, that in Java it's the interfaces that are typically/often seen as primary: you have a Car interface and a CarImpl class (or rather, a specific type of car). After that, the user of the Car instance should only care about the instance being a Car, not which specific kind of car, apart from what can be gleaned via the interface's methods.

Thread Thread
 
vlasales profile image
Vlastimil Pospichal

Interface first, implementation last.

Collapse
 
chadgauth profile image
Chad Gauthier

IPretend that the 'I' prefix in interface names acts as an indicator of the action or capability encapsulated by the interface. By adhering to this idea, we anthropomorphize our interfaces, making it easier to understand their roles.

Some examples:
ILog
IWriteToDatabase
IReadFromDatabase
IAuthenticateUsers
IPostComments

Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited

For anthropomorphize our interfaces use adjectives:

  • Logable
  • DatabaseReadable or Database/Readable
  • UsersAuthenticable or User/Authenticable
  • PostCommentable or Post/Commentable
Collapse
 
jojonarte profile image
Jojo Narte

i feel you

Collapse
 
hyftar profile image
Simon Landry

How would you name your interfaces for dependency injection?

Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited

It depends on what abilities will be required from the injected object. ILogger is not an ability.

Collapse
 
sandordargo profile image
Sandor Dargo

This is the misinterpretation (not by the author) of the Hungarian notation. If you want to learn more about it, read this article from Joel Spolsky. It was not about types as we mean them.