Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Cattle Drive and the fly likes Intention-revealing names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Intention-revealing names" Watch "Intention-revealing names" New topic
Author

Intention-revealing names

Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1362
    
  17
As a nitpicker on the Cattle Drive, I find myself returning to the concept of naming things well.

It's one of the most difficult things in computer science.


There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton


And of course, a popular variant: "there are two hard things in computer science: cache invalidation, naming things, and off-by-one errors".

Today I came across a blog post about this subject that speaks to the difference between explaining implementation (a name that explains what it does) and purpose (a name that explains why it is important)

It's a great read, highly recommended: Code That Says Why It Does
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

I love the variant. I don't remember hearing that before. Naming things is hard because it's soft ... that is, a soft skill. For hard core programers, it may be the only soft skill they're required to have, because the only way they ever communicate is via source code. I think that kind of developer is fading away as projects become more complex and therefore more collaborative. Still, communication via source code remains vitally important, and good naming is arguably a much bigger part of that than even good comments are.
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1362
    
  17
Interesting, I never thought of naming as a soft skill. I always thought of soft skills as things like knowing how to read body language and how to say 'How was your weekend?' and such.

Naming things has so much to do with precision and accuracy.


Q. How many geeks does it take to ruin a joke?
A. You mean nerd, not geek. And not joke, but riddle. Proceed.
- https://twitter.com/saucypickles/status/235102004966481920
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1731
    
  14

Katrina Owen wrote:Interesting, I never thought of naming as a soft skill. I always thought of soft skills as things like knowing how to read body language and how to say 'How was your weekend?' and such.

Spelling is pretty useful too e.g. if you're searching for likely keywords in an undocumented morass of code or having to code to a badly spelled interface written by somebody else. I did a liberal arts degree, so I was expected to be able to spell, but my pals who studied engineering were atrocious at spelling. Which might explain why all that C code written by engineers is always so hard to read: they weren't being cryptic, they just couldn't spell properly....


No more Blub for me, thank you, Vicar.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4477
    
    6

Greg Charles wrote:For hard core programers, it may be the only soft skill they're required to have, because the only way they ever communicate is via source code. I think that kind of developer is fading away as projects become more complex and therefore more collaborative. Still, communication via source code remains vitally important, and good naming is arguably a much bigger part of that than even good comments are.


Yes, it's a soft skill and yes, it seems like many developers have a hard time with giving good names. I think a lot of it has to do with being so focused on implementation rather than intent. I find myself mentioning "leaky abstractions" a lot when I'm helping other developers improve the clarity of their code.

Regarding communication, my experience is quite the opposite: The more collaborative the development effort, the more important it is to have developers who can not only give good names but who are constantly looking for opportunities to give better ones. During our daily code reviews, I find myself spending a lot of time with the other developers trying to find better names for things. They will often start with one name then neglect to rename things as they refactor. So we have to go over their design decisions and discuss their motivations and the intent of the code to figure out better names for things.

Uncle Bob's "Clean Code" book has a whole chapter devoted to the topic of names.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

Oh, hmm. I guess I didn't communicate that clearly, which shows my soft skills could use some polish. I didn't mean that naming things becomes less important as projects become more collaborative, which is clearly not true. I meant that with more collaborative projects, it's not the only way developers share their ideas.

I see Katrina's point, but I still think of naming things as a soft-ish skill, because it deals with communication. The compiler doesn't care if you name things well, and the program will run just as well whether you do or not. Good communication always relies on precision and accuracy, unless it's being done by a politician or executive.

 
GeeCON Prague 2014
 
subject: Intention-revealing names