I'm curious if there is/are tool/s that check (at least with warning) for too long variables names. What could be even better is another check (simple regex on variables would be sufficient) for "clue" words that author pointed in article. So did any one found tool that is able to do that?
For Java, PMD or Checkstyle will help: - http://pmd.sourceforge.net/pmd-4.3.0/rules/naming.html - http://checkstyle.sourceforge.net/config_naming.html#Content
The former has a rule that reports long names, the latter might require to specify your rule as a regular expression.
It's a good approach to omit types in variable names, but don't you think that the example with Date and generally Date suffix is a special case ?
Date is a natural part of English and as an example when we talk about a book we say "publish date". Would be strange to have a class Book with getPublish method instead of getPublishDate. And it seems the case is the same for holiday dates.
I would expand the first rule to "avoid duplicating information from type/access declaration". E.g. `abstract class AbstractSomething {}` is better to be just named `class Something{}` and there is o need to rename it once you realize it cannot be abstract anymore.
An example of making names longer to make better code: the video game League of Legends has an internal API method named GetElapsedFrameTimeSecs(). It replaced GetTime(), which wasn't precise, because there is no information scent on: - whether the unit is seconds, or milliseconds; - whether the time flows during simulation, or is quantized to simulation ticks; - and whether the time is relative to last simulation tick, or some epoch like process start.
Hi,
ReplyDeleteI'm curious if there is/are tool/s that check (at least with warning) for too long variables names. What could be even better is another check (simple regex on variables would be sufficient) for "clue" words that author pointed in article. So did any one found tool that is able to do that?
Bests,
Alex
For Java, PMD or Checkstyle will help:
Delete- http://pmd.sourceforge.net/pmd-4.3.0/rules/naming.html
- http://checkstyle.sourceforge.net/config_naming.html#Content
The former has a rule that reports long names, the latter might require to specify your rule as a regular expression.
It's a good approach to omit types in variable names, but don't you think that the example with Date and generally Date suffix is a special case ?
ReplyDeleteDate is a natural part of English and as an example when we talk about a book we say "publish date". Would be strange to have a class Book with getPublish method instead of getPublishDate. And it seems the case is the same for holiday dates.
I would expand the first rule to "avoid duplicating information from type/access declaration". E.g. `abstract class AbstractSomething {}` is better to be just named `class Something{}` and there is o need to rename it once you realize it cannot be abstract anymore.
ReplyDeleteAn example of making names longer to make better code: the video game League of Legends has an internal API method named GetElapsedFrameTimeSecs(). It replaced GetTime(), which wasn't precise, because there is no information scent on:
ReplyDelete- whether the unit is seconds, or milliseconds;
- whether the time flows during simulation, or is quantized to simulation ticks;
- and whether the time is relative to last simulation tick, or some epoch like process start.
https://engineering.riotgames.com/news/determinism-league-legends-unified-clock
See also https://testing.googleblog.com/2017/11/obsessed-with-primitives.html
DeleteUsing wrapping types like Duration/TimeDelta/TimeTicks can represent this information, and make correct usage statically checkable.
https://codesearch.chromium.org/chromium/src/base/time/time.h
https://github.com/abseil/abseil-cpp/blob/master/absl/time/time.h