Avoid These Naming Anti-Patterns...

DZone 's Guide to

Avoid These Naming Anti-Patterns...

...and tell us how often you encounter them. (Then mash your keyboard in rage.)

· Java Zone ·
Free Resource

Truism: Source code is for people, not machines. So... minds with a rather different (and legit-globally state-dependent) cognitive architecture than a von Neumann machine. That includes all your current and future colleagues, your future self, anyone who might conceivably use your library in the future... and if your code is open-source, everyone from now until the heat/cold death of the universe.

So naming things in a human-readable ("self-documenting") way is important. And it's not easy (1, 2, 345, 6...). Getting it right can feel like a semi-unpleasant responsibility, like anything else that takes you out of that creative coding flow; but we've all scratched our heads (or gritted our teeth, or glared viciously) at someone else's opaque, idiosyncratic, or just confusing naming conventions ("Is this the same as that except that this has an underscore and that doesn't?? But the code looks different!... I think?")

Confession and example:Once, in a fit of indulgent caffeine-induced buzz, I named a series of message-routing subclasses after political philosophers... in a way that totally made sense at the time ("different political philosophies are different approaches to information flow!") and that I was totally going to change... but of course didn't. Then, two years after I had moved on from that job, my ex-boss messaged me to ask... well, you know what...

So I glee-ed out a bit when I ran across some (relatively) recent work by a few Italian and Canadian researchers: "Linguistic antipatterns: what they are and how developers perceive them" (Jan 2015).

The authors came up with 17 different kinds of linguistic antipatterns, divided into six subtypes. To construct each type they worked on a small number (14) of fairly deep interviews, combining free-flowing conversations with careful reading and interpretation of source samples.

What are the 17 antipatterns in code naming? Well, before we tell you, let's put some n>14 meat on those n=14 bones. Here's the list of annoying code naming issues. That's a survey link: let us know how often you encounter each.

We'll share the results with toolmakers (and here, of course), with the aim of improving more-clever-than-IntelliSense hinting systems and static analysis tools... and evil coding badges (see "Don't Try This At Home")...

antipatterns, best practices, code quality, naming

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}