C
C
Copperfield2015-04-13 15:39:53
Java
Copperfield, 2015-04-13 15:39:53

How to come up with meaningful names for classes?

How to give meaningful names to classes? In my vocabulary there are only controller, manager, helper, receiver, adapter and a couple more.
I feel that often the names for classes do not correspond to their purpose.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
T
Timur Shemsedinov, 2015-04-13
@Copperfield

What a cool confession, it's really unique that you realize there's something wrong with it. Most developers do not do anything, they all call it a controller. I think that we need to read more and develop vocabulary, horizons and consciousness, not even necessarily English-language literature, scientific and technical vocabulary is mostly international. Of course, you can read articles in popular science magazines and fiction, but I’m closer and I advise scientists, programmers and philosophers: Donald Knuth, Grady Booch, Descartes, Kant, Marcus Aurelius, Lao Tzu, Spinoza, Pascal, Plato, Aristotle, Mamardashvili, Pyatigorsky, Shantideva, Russell, Chomsky, Norbert Wiener, Glushkov, Kantorovich, Lebedev, von Bertalanffy, William Ashby, Dijkstra, sorry if I didn’t remember anyone, who was the first to suddenly come to mind.

A
Alexey Nikolaev, 2015-04-13
@Heian

Use Google Translate and translate the meaningful Russian name into English.

D
Dmitry, 2015-04-13
@ubuntuman

Recently, for variable names, I use a description of the content (example: pages, currentIndex, countSteps, lastColor),
for functions, an action description (example: createNewPicture, saveToFile, removeLastPage, getCountElements),
and for classes, either a short description or words with a prefix - er (example: BlockSplitter, PagesStore, ColorsManager, TextFormatter). Of course, words are often repeated. If this is for storage, then here is Store, if for management, then manager, controller, if for separation / filtering, then Sepatator, Splitter, etc. If I can’t find anything familiar, I climb into the translator, drive in the word and look for the simplest and most “beautiful” translation option, and I use it.
I don't know if this is normal, but I like it so far...

L
lam0x86, 2015-04-13
@lam0x86

1) Study popular projects on github, regardless of the programming language.
2) Use a dictionary (Lingvo helps me a lot).
My opinion - the more unusual the name of the entity (within reasonable limits), the easier it is to remember the structure of the project. When you have to deal with other people's projects, where half of the classes are called ControllerBase, ControllerImpl, AbstractControllerFactory, etc., you want to hang yourself.

M
Max Sysoev, 2015-04-23
@ColCh

If the vocabulary contains only controller, manager, helper, receiver, adapter, then this is the problem.
The secret of naming entities is in a brief description of their purpose.
You wouldn't call the Button class MouseClickReceiver, would you?

O
Odissey Nemo, 2016-02-07
@odissey_nemo

Name it in Russian (or in the language in which you think), and then translate into English. So that it is clear to you, first of all. Sometimes Google or Yandex give good translations, and sometimes they are disgusting. For speed, you can use them, but be sure to carefully check the meaning of what they have done.
And try to be shorter, using generally accepted abbreviations, in English, of course. Button == Btn, Rectangle == Rect, Point = Pnt, Control == Ctrl|Cntrl etc. RectangularButton == RectBtn, EscapeButton == EscBtn etc etc etc.

Y
Yuri, 2016-10-31
@YuryBorodkin

Read this chapter from Clean Code.
In general, it is a very serious matter, to accompany software that does not comply with naming conventions is a hell of a hell.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question