Loading ...
Sorry, an error occurred while loading the content.

1360Re: Enhancement Request: Identifier length restriction

Expand Messages
  • Marc Draco
    Jul 6, 2010
      Austin may be vitriolic, but he has a point.

      Code Complete by Steve McConnell is my bible and it has some interesting
      things to say on single-character identifiers.

      Personally, I only ever use single-character vars in short loops. For a
      single iterator, I tend to use "n" (which betrays my beginnings in an
      early BASIC); and I would generally eschew i, j, k for nested loops
      unless there's a very good reason - i and j are so easy to confuse due
      to "confirmation bias".

      x & y (and z) are a special case also - these are handy for short loop
      iterations when co-ordinate systems are in use.

      Where speed isn't paramount, I've found a short object can be very
      helpful. Using X and Y as an example, let's say I need two versions of
      each, I might create two literal, local objects like this:

      var old = {};
      var cur = {};

      and initialise some variables

      old.x = 0;
      old.y = 0;
      cur.x = old.x +10;
      cur.y = old.x +10;

      Any operations could conceivably use "with" on these but that has
      problems all of its own. Personally I never use it.

      This is far clearer than using very long names, is very easy to type and
      less error prone because we're grouping related variables. Of course,
      your mileage may vary.
    • Show all 11 messages in this topic