Jabberwocky

snicker-snack!

Full Names Only

| Comments

If there’s one thing I’ve learned over my years of development, through reading my own and other peoples’ code:

NEVER try to save on keystrokes for identifiers

Please, please don’t write p instead of product, don’t write fl instead of fileLocation. I may be preaching to the choir, but a random look at code shows that it bears repeating.

There are many possible reasons to use abbreviations instead of the full name of things:

  • long and complex names moduleNamesAndLabels
  • it doesn’t fit on my editor window
  • I’m practicing code golf in my day job
  • I can’t be bothered and haven’t had my coffee yet

In my experience attempts at typing less (in this instance) will result in blood and tears later. It’s an implicit part of the imperative Code for the maintainer

Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live.

On the practical side, you can fix your workflow so you won’t be tempted. All sensible editors have autocomplete facilities. In vanilla vim Ctrl-N will get you autocomplete. The snippet below pasted in .vimrc will change Ctrl-N to tab (one keystroke less!) and will give you the dictionary to boot (adapt the location of the dictionary to your system).

1
2
3
4
5
6
7
8
9
function! Tab_Or_Complete()
  if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return "\<C-N>"
  else
    return "\<Tab>"
  endif
endfunction
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
:set dictionary="/usr/share/dict/words"

I’m reasonably sure emacs, sublime text and certainly IDE will have equivalent features. So laziness is not an acceptable excuse not to use the full name of things.

Do you want to be exposed to code that looks like this?

Mystery code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
if (a_neg ^ b->neg)
  {
  /* only one is negative */
  if (a_neg)
      { tmp=a; a=b; b=tmp; }

  /* we are now a - b */

  if (BN_ucmp(a,b) < 0)
      {
      if (!BN_usub(r,b,a)) return(0);
      r->neg=1;
      }
  else
      {
      if (!BN_usub(r,a,b)) return(0);
      r->neg=0;
      }
  return(1);
  }

(bonus points if you guess which project this is from :) ) (no cheating)

Coders of the world, type it like it is.

Comments