NEP16 Comment character - ghewgill/neon-lang GitHub Wiki
This proposal changes the comment character from #
to --
(see also NEP10 Comment character).
History
The (single-line) comment character was originally %
. NEP10 Comment character changed this to #
. However, both these character glyphs occupy the same shape as upper case characters, which can visually conflict with Neon keywords, making code harder to read.
Proposal
This proposal has two parts:
- Change the single comment character to
--
- Change the multiline comment characters to
/*
and*/
The --
comment style is used by venerable languages such as Ada, Eiffel, Haskell, Lua, SQL, and VHDL. It would look like this in Neon code:
-- File: fizzbuzz.neon
--
-- For each integer from 1 to 100, print "Fizz" if the number
-- is divisible by 3, or "Buzz" if the number is divisible
-- by 5, or "FizzBuzz" if the number is divisible by both.
-- Otherwise, print the number itself.
FOR i := 1 TO 100 DO
-- Check divisibility of number.
IF i MOD 15 = 0 THEN
-- Divisible by both 3 and 5.
print("FizzBuzz")
ELSIF i MOD 3 = 0 THEN
-- Divisible by 3.
print("Fizz")
ELSIF i MOD 5 = 0 THEN
-- Divisible by 5.
print("Buzz")
ELSE
-- Not divisible by 3 or 5, print just the number.
print(i.toString())
END IF
END FOR
Comment styles are by nature mostly subjective, but this style does have one objective advantage:
- Consistency with embedded SQL (which also uses
--
and/* */
).
Some subjective advantages are:
- Clean visual style.
- Easy to type single line comments without having to use shift key.
One disadvantage is we would have to reintroduce the grammar special case that allows the #!
shebang at the start of the file, but this is minor.