Author Topic: Overview of syntax  (Read 7667 times)

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Overview of syntax
« 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

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Overview of syntax
« Reply #1 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.

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Re: Overview of syntax
« Reply #2 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.

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Overview of syntax
« Reply #3 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)...

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Re: Overview of syntax
« Reply #4 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.

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Overview of syntax
« Reply #5 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.

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Re: Overview of syntax
« Reply #6 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.

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Overview of syntax
« Reply #7 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..

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Re: Overview of syntax
« Reply #8 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.