DEV Community

Discussion on: Readable Code

Collapse
 
vlasales profile image
Vlastimil Pospichal

What is "Thoughtful naming"? Short and simple or long and complex? My base of naming is one word, sometime two words. No longer.

Collapse
 
ghost profile image
Ghost

To me "Short and simple or long and complex" is like asking how long should a program be, depends, the main purpose of a name is clearly indicate what it is/does, second is how long; the name should be as short as possible without losing it's main goal. Restrict oneself with artificial rules seems useless to me, the amount of chars or words are not the purpose of a name.

I usually make a stupid long name and then ask myself, and start iterating, can I shorten it while keeping understandable? when the answer is no, that's what I keep. If the end result is inconvenient (too long and used too often) maybe there is a deeper problem in my code.

Collapse
 
gergelyorosz profile image
Gergely Orosz

Good question. In my opinion, the easier to understand the purpose, the better. For the most part, this would mean simple & short.

But it depends on the codebase and domain. E.g. in a large codebase following agreed on architecture principles on using e.g. viewcontrollers and the concept of interactors, the name RootViewControllerInteractor could count as a good name. Or in an accounting domain, EndOfYearCalculationController could also be a thoughtful name.

My point is to put thought to come up with clear names that make sense to you and other devs who will work on the same codebase.

Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited

I use namespaces for split words, Interactor\Controller\View\Root, Calculator\Controller\EndOfYear etc. Nouns for things, verbs for methods, adjectives for interfaces.

Two words in a method name shows violation SRP.