C2 forum

General Category => General Discussion => Topic started by: lerno on October 27, 2018, 02:41:05 PM

Title: Overview of syntax
Post 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
Title: Re: Overview of syntax
Post by: bas on October 28, 2018, 09:44:47 AM
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.
Title: Re: Overview of syntax
Post by: lerno on October 28, 2018, 10:53:27 AM
For me, begin / end is very much Pascal.

However, there is something to be said for "some start"-end.

Consider this:

K&R
Code: [Select]
func int test() {
   if (foo == 45) {
      do_a();
   } else {
      do_b();
   }
}


Allman
Code: [Select]
func int test()
{
   if (foo == 45)
   {
      do_a();
   }
   else
   {
      do_b();
   }
}

Ruby-like
Code: [Select]
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.
Title: Re: Overview of syntax
Post by: bas on October 31, 2018, 09:39:16 AM
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)...
Title: Re: Overview of syntax
Post by: lerno on October 31, 2018, 09:58:58 AM
Definitely, I'm not suggesting anything other than { } for C2. (Unless we find some reason that changing { } would make things much much more readable.
Title: Re: Overview of syntax
Post by: bas on November 07, 2018, 09:49:36 AM
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.
Title: Re: Overview of syntax
Post by: lerno on November 08, 2018, 03:38:58 PM
I'm actually a fan of ";". It makes macros and generated code so much easier to do.
Title: Re: Overview of syntax
Post by: bas on November 09, 2018, 08:37:15 PM
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..
Title: Re: Overview of syntax
Post by: lerno on November 10, 2018, 06:06:20 PM
I've worked quite a bit in Ruby. If found the lack of ";" makes single line conditionals and loops less nice to work with.