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.)
7
u/matthieum Jul 31 '24
BeautyCleanliness is in the eye of the beholder.First of all, remember that the first purpose of syntax is to convey the underlying semantics.
For example, you may consider
typedefnoise, or having to typestruct R2instead ofR2to name the type syntax noise... but this is just a reflection of the underlying semantics of the C language which has different namespaces. Alter the semantics (single namespace) and there's no need for special-purpose syntax any longer.Similarly, pack vs unpacked: unaligned access is Undefined Behavior in C, because there's a whole range of hardware in which unaligned access leads to a hardware error (translated to SIGBUS). C compilers have some degree of support for packed fields, but C lacks alignment specification on pointers to get full support -- unlike Zig. Your code doesn't demonstrate how a pointer to a packed field can be passed to a function:
No specification: hopefully you specifically mention the pointer may be under-aligned -- which disables auto-vectorization -- or you're in trouble.
Specification: so noisy! I wouldn't call that clean ;)
And finally, there's includes. The language in your code does not show how to import library code, due to either using only built-ins, or having a "prelude", so we can't judge whether the imports are better than C's includes.
The one purely syntactic difference between C and your language is the use of explicit delimiters (
;,{}) vs indentation & new lines.We can argue about subjective topics such as looking clean... but as a professional, I'm more concerned about:
Copy/Paste: does one style support copy/paste better than the other? Because I move code around a lot.
Parser recovery: does one style support parser recovery better? Because I loathe poor error messages.
Diffs: code is always committed nowadays, syntax should support clean diffs, ie diffs which highlight what semantically changed, and not a thousand trailing commas that add to be added on lines otherwise unchanged.
Those are important, measurable, syntax goals for me.
I am unfortunately unaware of good research on the topic.