Naming Things
Is Hard

Eli Schutze

@elibelly

"There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors."

Very real and not at all made up serious scientific rules for naming things

  • The Shakespeare Postulate
  • The Heron-Samuels Axiom
  • The Goldilocks Principle
  • The For-Loop Exception
  • The Contextual Healing Manifesto
  • The Change is Scary Paradox

or 'What's in a name?'

  • We name variables, functions, CSS classes, filenames
  • Names don't matter

That which we call a rose by any other variable name would still compile

The Shakespeare Postulate

People are good at words, computers are not

Human

Computer

  • Programming is a shared activity
  • Names should be written to ease human readability
    1. Pronounceable
    2. Descriptive and Meaningful
    3. Contextual

The Heron-Samuels Axiom

"The hardest thing about choosing good names is that it requires good descriptive skills and a shared cultural background."

-Tim Ottinger , Clean Code

The Goldilocks Principle

or 'Everything in Moderation'

Make names descriptive and meaningful in a concise way

// number of puppies per YouTube video 
let p; 
let numberOfBabyDogsSeenOnYouTubeVideo;
let puppiesPerVideo;
let puppiesPerVid;
let avgPuppiesPerVideo;
  1. Use abbreviations only when obvious
  2. Try finding one word that can replace a group of words
  3. Don't rely on comments exclusively
  4. Be explicit, write searchable names

The For-Loop Exception

"The length of a name should correspond to the size of its scope"

for (let i = 0; i < puppies.length; i++) { 
 console.log(i)
}


On that note: Avoid lowercase 'L' and uppercase 'o' to avoid confusion with 1's and 0's

int a = l;
if ( O == l )
 a = O1;
else
 l = 01;

Pro-Tip: Avoid Naming Disinformation!

Avoid having similarly named classes out of laziness.

Puppies, PuppiesInfo, ThePuppies or color/colour

"The hardest thing about choosing good names is that it requires good descriptive skills and a shared cultural background."

-Tim Ottinger , Clean Code

The Contextual Healing Manifesto

  1. Use a programmer's context


     
  2. Use your project's business domain  context, don't get cute
     
  3. Use real life conceptual or grammatical context (verbs, nouns)

     
  4. Stay consistent across the domain
     
  5. Don't over-do it
//CSS selectors
.nav { } 
.modal { } 
// Function design patterns
puppyFactory() {}
getCapitalAssets() vs showMeTheMoney()
getPuppyVideos() 
let puppy = { color: brown, name: Avocado }
const isHouseTrained = true
append() vs add() vs insert()
// For "Puppy Video App"
let PVAPuppyList, PVAVideoURL

The Change Is Scary Paradox

Don't be afraid to rename things! 

Code functionality changes, so should names

(sometimes associated with The Boy Scout Rule)

Boy Scout Rule: "Always leave the campground cleaner than you found it."

Naming Things Recap

  • Names are for people
  • Be descriptive yet concise, it's harder than it looks
  • Use your knowledge domain for context, don't get cute
  • Think of the future, Don't be afraid of change! 

Thank you! 

Eli Schutze

@elibelly

If you want to learn more read
"Clean Code" by Robert C Martin and friends)

http://ricardogeek.com/docs/clean_code.pdf

Naming Things Is Hard

By Eli Schütze Ramírez

Naming Things Is Hard

Inspired by Clean Code and pop culture, this is a quick lightning recap of some tips to make naming things in programming easier. If you want to learn more check out "Clean Code" by Robert C Martin and friends) http://ricardogeek.com/docs/clean_code.pdf

  • 2,749