blog.sspboyd.ca

  • Archive
  • RSS
  • Ask me anything

Choosing Descriptive Variable Names: Code !is English

When starting a new project I often find one of the hardest parts is choosing accurate, descriptive variable names for the objects and variables I’m working with. I’m sure this isn’t a new observation but it is striking me now as I try to sort through the best way to structure a Class in Java that generates a histogram of some colour data in an array (PImage ints in Processing).

This has nothing really to do with programming but with finding the right words in english to describe what I think I’m trying to do as I work through the code. My sense is that the trouble stems from the fact I’m trying to use one structured communication mode (english) to describe what’s going on in another structured communication mode, Processing/Java code. Not surprisingly, there isn’t a 1:1 relationship there. 

I’m no where near competent enough to understand 99% of what Donald Knuth writes, but this quote in “Literate Programming” seems to speak to this difficulty:

The practitioner of literate programming can be regarded as an essayist, whose main concern is with exposition and excellence of style. Such an author, with thesaurus in hand, chooses the names of variables carefully and explains what each variable means.  

Edit: Thanks to Derek Watson for sending me the the exact quote I was looking for:

“There are only two hard things in Computer Science: cache invalidation and naming things” - Phil Karlton
    • #processing.org
    • #variable naming
    • #english
    • #programming
  • 1 year ago
  • Permalink
  • Share
    Tweet

About

Pages

  • Test Page

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr