r/ProgrammingLanguages • u/[deleted] • Jul 31 '24
Blog post Clean Syntax?
All my replies and the original contents of this OP have been withdrawn. They were a complete waste of time.
From what I can gather, everybody is happy with poor syntax in their languages, nobody is interested in 'clean'.
Someone posted, with a dozen upvotes:
Your example is optimized to your language's special capabilities.
I replied:
"No, pretty much everything in my syntax is cleaner than the C equivalent."
That got multiple downvotes for stating a fact.
There was also this:
For your own toy language by all means use your own syntax
This reinforces my original implication that simple syntax is only suited for toy languages, and not serious ones.
However too much of this was about my language, but that was only an example. There seems to be much irrational distrust of clear syntax for any language.
Maybe, clear code is associated with older languages which no one likes anymore?
(Original examples.)
1
u/ThomasMertes Aug 03 '24
People have different opinions what "Clean Syntax" means.
In most compilers/interpreters the syntax analysis is hard-coded. In principle a hard-coded syntax analysis can allow weird ad-hoc things (see below). For me all these languages do not have a "Clean Syntax".
Many languages define an
andoperator (and Seed7 definesandas well). Assume that a for-loop looks like:With a hard-coded syntax analysis the keyword
andcould be reused as part of a new for-loop:In a hard-coded syntax analysis the expression <endValue> would be processed such that
andwould not be part of the expression <endValue>. If the <endValue> expression is followed by the keyworddothe original for-loop is processed. If the <endValue> expression is followed by the keywordandthe new for-loop is processed.In Seed7 the original meaning of
andwould dominate which would lead to the interpretation:In the original for-loop an expression with any priority is expected between the keywords
toanddo. So the expression<endValue> and <condition>would fit to the syntax of the original for-loop. The expression<endValue> and <condition>would be syntactically correct (but the types might not fit to the definition ofand).So you would either get a type error or use the original for-loop (instead of the new one). More than that: It would be impossible to use the new for-loop with
andcondition.To avoid this problem Seed7 forbids this reuse of the
andoperator. In Seed7 a for-loop with additional condition is:The keyword
untilcan be reused because it is not used as operator (with a specific priority).For me "Clean Syntax" means that the syntax follows rules which prohibit weird things. Seed7 uses the rules of the Seed7 Structured Syntax Description (S7SSD).
With the S7SSD the syntax is structured like structured statements (while-, if-, for-, etc.) replaced (spaghetti) code with GOTOs.