C2 forum
General Category => General Discussion => Topic started by: lerno on October 27, 2018, 02:41:05 PM
-
I recommend the following two sites for overview of different types of syntax:
https://rosettacode.org
http://rigaux.org/language-study/syntax-across-languages.html
-
Having keywords written out (like begin or end) always reminds me of my very early Basic days.
Especially fully capitalized versions (BEGIN .. END) really scream 1980's.
-
For me, begin / end is very much Pascal.
However, there is something to be said for "some start"-end.
Consider this:
K&R
func int test() {
if (foo == 45) {
do_a();
} else {
do_b();
}
}
Allman
func int test()
{
if (foo == 45)
{
do_a();
}
else
{
do_b();
}
}
Ruby-like
func int test()
if (foo == 45) do
do_a();
else
do_b();
end
end
Here I'd actually say that the Ruby-like syntax retains the positive terseness of K&R (no special lines just for the start of a block), with the readability of Allman (blocks are visually extremely easy to make out). The only thing I don't like about this style is that "end" seems such a long keyword.
-
I must say that I do find the Ruby version quite readable. This surprised me. Maybe the end keyword is easier on the eyes then the }.
If never like the Allman style where half your screen seems filled with lines only containing a single character ({ }).
Changing the curly brackets to begin/end keywords, does change the language a lot at the surface (what people view first)...
-
Definitely, I'm not suggesting anything other than { } for C2. (Unless we find some reason that changing { } would make things much much more readable.
-
In the early stages, I did a big test with trying to remove the semicolon (;) after each statement. That really
made the code look so much easier to read. I managed to get the syntax/parser to do this, except for a few
corner cases, with the if statement if I remember correctly. I used the same way as Go, just let the
Lexer insert semi-colons at certain points.
-
I'm actually a fan of ";". It makes macros and generated code so much easier to do.
-
As a fun experiment, just take a piece of C/C++ code and remove all the semi-colons (in vim: %s/;//g )
Now just look at the code before and after..
-
I've worked quite a bit in Ruby. If found the lack of ";" makes single line conditionals and loops less nice to work with.