Closed LPeter1997 closed 2 years ago
I think Option 3 just adds more unnecessary noise to the code. I mean it's obvious when I write:
if (foo() == bar()) {
baz()
}
That means I want to call baz
method only and only if foo() == bar()
condition is met, any other keywords like do
or then
are just redundant or even noise. It may make code more readable for non-programmers but it would make code less concise and more verbose in the long run.
What is important is as @LPeter1997 said:
but for separability, the block always has to be explicit
We're always going to need some sort of characters like {
, }
to define blocks. In conclusion I prefer Option 1.
There are a few different styles we could pick when designing the syntax for the basic control flow structures. The options are in no particular order.
Option 1: Required parentheses for the condition element
This is how C does it. Allows the parser to distinguish the condition from the block, if the block braces are omitted.
Option 2: Required braces for the block element
This "frees up" the condition, but for separability the block always has to be explicit.
Option 3: Separator keywords
Separator keywords like
then
anddo
reduce the number of separator tokens, as they don't need to be symmetric like parentheses.Note that the block syntax and semicolon usage are still up for discussion. Personally I really like option 3 so far, even with the current syntax.
{ }
can be thought of as the block composing operator or something.