lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2017-06-16 2:22 GMT+02:00 Soni L. <fakedme@gmail.com>:

> Spaces are superior because you can instantly tell who wrote what, since
> different ppl use different indentation levels. (/s)
>
> (At the end of the day, it all comes down to personal preference. I have
> used logarithmic indentation before.)

Another possibility is Fibonacci indentation, 1,2,3,5,8,13,.... You can think
of it as a generalization of the standard tab stop of 8 spaces, since 8 is
a Fibonacci number.

It has the theoretical advantage of being unbounded, although in practice
it becomes hard for the human eye to distinguish between a line-wrapped
89-space indentation and an empty line followed by an 8-space indentation.
If this bothers you, use reverse Fibonacci indentation, e.g. 8,5,3,2,1.

Most sophisticated of all is bidirectional indentation: reverse Fibonacci for
comments, forward Fibonacci for code. This has an attractive "wavy"
appearance.

             --- First  line of a standalone comment block (13 spaces)
        -- Major heading inside a comment block (8)
     -- Minor heading (5)
   -- Actual comment (3)
  -- allowing three (2)
 -- levels (1)
-- of subdivision (0)
function abc(...)
 local a,b,c = ...
 if type(a)=='string' then
  for pos,char in a:gmatch"()(.)" do
   -- inline comments come at the level where the code would be
   if char:match"%u" then
     while true do
        local p = io.read(1)
        if p:upper():match"Q" then
             os.exit(pos)
        end
     end
   end
  end
 end
end

Such a systems requires some mental arithmetic from the user. It is easy
to say that if such an effort is beyond you, then computer programming
is not a sound career option, but no matter how good you are, some of
your biological CPU gets diverted.

It is therefore nicer to have an editor that allows you to set custom
tab stops (of course, filling it in with spaces; no need to risk your
cushy salary). In the 1980s I used a truly marvellous editor called
PC-Write which allowed that. It is still available (now free, in fact)
but you need a DOS emulator to run it.