lua-users home
lua-l archive

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


Hm, starting the line is an uncommon approach - but it makes sense.
I don't use semicolons at all - I prefer putting statements simply into different lines. I am occassionally making exceptions when creating short callback functions or chaining calls, i.e. when calling gsub combined with sub and so on. I simply haven't yet seen a piece of code where the meaning would have been clearer with the ; put in between.
Though the case that I wrote is in deed ambigious and is in need for a splitter... my subjective feeling on semicolon is however that I am already using up all special chars when writing code in other languages - and I find these characters simply ugly and hard to write on the keyboard. One of the things that I appreciate the most when writing Lua code is the lack of required special characters. I didn't feel more confident when using semicolons so I stopped using them after a short while when I began learning Lua. I didn't put them between statements consequently enough and in that case, the code looks quite weird in my opinion. My refusal for semicolons in code goes even that far, that I prefer rewriting ambigious code (if it is acceptable) than using these characters.


2009/2/19 David Manura <dm.lua@math2.org>
On Wed, Feb 18, 2009 at 4:41 AM, Mark Meijer wrote:
> print("Statement 1");(false or print)("Statement 2")
>
> In this case, if I omit the semicolon, Lua complains about an attempt
> to call a nil value. Makes sense. It may become more difficult to
> interpret the error report, if the return value of Statement 1 is
> something callable. Personally, I always end my statements with a
> semi-colon. It's a paranoia thing, I guess, but evidently not entirely
> unwarranted :-o

The rule I try to follow is always put semicolons between statements
that exist on the same line (a rare case) but avoid whenever possible
putting semicolons between statements on separate lines.  According to
these rules, one would never write

 print("Statement 1")  (false or print)("Statement 2")

but one might accidentally write

 print("Statement 1")
 (f or print)("Statement 2")

The error in the first example could conceivably be silent or detected
only at run-time.  However, the error in the second example is more
benign since it is quickly detected by the compiler during parsing
("ambiguous syntax").  On discovering this, you can add the semicolon:

 print("Statement 1")
 ;(f or print)("Statement 2")

I choose putting the semicolon in front of the first line.  Starting a
line with a parenthesis is a red flag as is starting a line with a
semicolon.