lua-users home
lua-l archive

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


On 2010-Sep-27 (Mon) at 10:14 (+0000), Jon Akhtar wrote:

>> I know that a lot of code formatting is a matter of personal taste,
>> however, I am developing a code formatter for Lua, and I am in need
>> of a "default" format to support "out of the box".
>> 
>> There are a lot of nuances to code formatting, and I'd like to cover
>> as many as possible.

Jon,

   Well, although it's different to the PiL style and to that of most
   Lua programmers, I very much prefer to indent the keyword 'end'
   to the level of the block which it closes; for example:

      i = 0
      while i < 10 do
         if i % 2 == 0 then
            print( i, "is even" )
         else
            print( i, "is odd" )
            end
         i = i + 1
         end
      print( "goodbye for now!" )

   My feeling is that since 'end' does not really 'mean' anything
   by itself, but is just a syntactic bracket, that it's neater
   to tuck it away, aligned with the rest of its block.

   Also, it makes it visually easier to spot the next construct,
   such as the 'i = i + 1' or the final 'print' in the above example.

   Any thoughts, anyone, for or against?

   ( maybe it's my inner Pythonist struggling to break free,
     with indentation denoting nesting :-)

Joseph

------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / manning@cs.ucc.ie
------------------------------------------------------------------------