Verbose Logging

software development with some really amazing hair

T + G I F R

The Philosophy of Naming Variables

· · Posted in Software
Tagged with

Russ Cox made a good comment on the golang-dev mailing list about the philosophy of naming variables. He links to his original short post on the subject as well.

A TL;DR version is that i makes more sense than index when you're looking at a small loop. For local variables that are only relevant for a short number of lines, having long verbose names actually makes them less efficient.

As the context or reach of a variable increases, having longer names (to a point) makes sense. This can be seen in publicly exported types, methods, functions, constants, variables, and even the package names themselves.

Russ Cox expresses this succinctly:

A name's length should not exceed its information content.

And I agree.