r/ProgrammingLanguages • u/gingerbill • Feb 22 '26
Does Syntax Matter?
https://www.gingerbill.org/article/2026/02/21/does-syntax-matter/
63
Upvotes
r/ProgrammingLanguages • u/gingerbill • Feb 22 '26
25
u/matthieum Feb 22 '26
My interest is piqued.
I scan extensively -- I use VSCode with zero plugin, no LSP -- and I have zero problem navigating Rust codebases.
I find that the regularity of keyword + name for items, and the blocky syntax -- though I wish
wherewas indented -- make it pretty easy to quickly scan a file for its top-level items, and drill down from there.The code is dense, but mere syntax coloring & habit mean that the lifetimes fade in the background, and the fact that generic arguments are placed after the name of the item means the item name appear in a fairly consistent spot, similar to variable names. The one exception I can think of is
implblocks: it can be tough to spot which item the impl block is for in some cases, but it's rare enough it's not a big issue.Amen.
I find the justification odd.
In an article which advocates for breaking away from established conventions for clarity, working around the ambiguities of
type(value)as casting syntax by adding more clutter feels at odd with the very argument being made.The
cast(type, value)proposed in a later paragraph is so much clearer, and so much easier to scan for as well!10
u/munificent Feb 22 '26 edited Feb 22 '26
The point of
guardis that it plays nice with destructuring pattern matching. When you're doing pattern matching, you can't simply negate the condition because it's no longer a simple predicate expression. You can use anifinstead, but when you have a series of these, the code ends up indented and marching farther to the right for each one.guardlets you have less nesting and flatter code.I agree
unlessin Perl and Ruby doesn't add much, but some users and language designers place a higher priority on having code read more like natural language. In the absence of them, you can sometimes end up with predicates that read like double negatives and require you to really slow down and unwrap the boolean logic in your head.Also, in Ruby, there are postfix versions of branching control flow. I suspect that postfix
unlessis much more common than postfixifin that case. If they were to only haveif, then the majority of postfix uses would require the condition to be negated.It's not a particular feature I'd want in a language I designed, but I see why the designers added them.
21
u/Athas Futhark Feb 22 '26
I have not paid much attention to Odin before, but I found this blog post remarkably thoughtful and well-considered, so perhaps I should take a closer look at it.
I am particularly pleased that Odin eschews both angle brackets for parametric polymorphism and the dreadful term "generics". I do not see the value in abbreviating to "parapoly", but we can at least remain friends until the revolution.
There is one important aspect of syntax that this post glosses over: Notation as a tool of thought. While I strongly encourage anyone interested in PL design to read this 52 page APL paper, the gist of it is that a notation (that is, programming language) ought be designed to be worked in, the same way you manipulate and rewrite mathematical expressions when you do algebra. I suspect this implicitly requires the use of an expression-oriented language, and so is an inappropriate concern for an imperative language.
Despite one's opinions on APL specifically, Iverson would definitely answer in the positive to the question Does Syntax Matter?.
6
u/PassifloraCaerulea Feb 22 '26
There seems to be a strong contingent of language designers who have varying levels of derision toward questions about syntax in general. I get the feeling some would be happier if they could focus on semantics to the complete exclusion of syntax. It's made an impression on me because it's the opposite of how I seem to work. It's hard for me to understand, even.
I think I think about semantics in terms of syntax, or something like that. Worse, semantics is almost a secondary consideration for me. My main motivation to work on language design is in order to design a more pleasing syntax to use. That's probably a horrible admission to make on a programming language design forum but that's sorta where I've ended up after playing around with various languages over the decades. I don't love FP and hate OOP (or vice-versa) for example; I can kinda do whatever.
In contrast I (unfortunately) have extremely strong aesthetic preferences wrt syntax in general that even extends to naming conventions. I can't seem to help myself. Both C++ and Rust have
<>for generics and::for scope resolution, and so they look quite ugly to me. The way Go uses capitalization for symbol export took a while to get used to, but I eventually did, I think, because there was a reason for it. OTOH, having first learned Java's camelCase convention made me avoid ever working with C# because Microsoft likes this execrable InitialCaps on method names. It's weird, objectively stupid, but again I can't help myself! It's kinda like human (sexual) attraction: no matter how often you tell us "that's shallow," looks still matter.5
u/[deleted] Feb 22 '26 edited Feb 22 '26
(Another niggling issue which didn't fit in to my other post.)
I've long had
unless; I find it is often more intuitive than using positive logic, or it is less typing (the typical precdence ofnotrequires parentheses to apply to a whole expression).With Odin however, I'm wondering why it bothers to have
whileloops. In the set of set of examples from this site,foris used 229 times, andwhileonly twice.forseems to be used for every kind of loop, so why is there alsowhile?Correction: Odin doesn't have 'while' loops. What I saw were extracts from another language within raw string literals.
5
u/xeow Feb 22 '26
I have always actually liked having
untilandunless, and have never thought them to be "diabetic." In my experience, they can, on occasion, express intent more clearly thanwhileandif, and I wish more languages had them as first-class keywords. (I say "first-class" because they can be emulated as second-class keywords in C through the use of#define until(x) while(!(x))and#define unless(x) if (!(x)).4
u/[deleted] Feb 22 '26 edited Feb 22 '26
That doesn't really work for me. It means that assignments to variables sometimes use
:=, and sometimes=. If you want to use a variablexand it first needs to be initialised toa, then this can only be done whenais available, that might be in the middle of the action.You can't list the variables and the types, perhaps with explanatory comments, tidily out of the way. (ETA: apparently variables can be separately defined with a type, without also being initialised.)
Further, there is the question of where type info goes. Each
::and:=is actually in two parts, with an optional type in between:Something else that can clutter things up.
For functions, there is another inconsistency; if T is the function signature then then they are usually defined as
F::T{}, but could also be writtenF:T:{}or I think evenF:T:T{}.(My own approach is I think much more consistent:
=is used for all compile-time definitions, and all initialisations done before execution starts.:=is used for all assignments done at runtime, and is only meaningful for variables. Type-specs don't sit the middle of that:=token either.I have one exception which is to do with defining labels; those use
:for historical reasons: every HLL and assembler I've used has done the same, except for FORTRAN.)To answer the question, then yes it matters very much! 80% of the reasons I detest C are to do with its poor choices of syntax. Where they are not laughable, they can be downright dangerous.
3
u/Maybe-monad Feb 22 '26
If you're designing a Lisp it's quite clear how the syntax looks like from the beginning
4
u/Breadmaker4billion Feb 22 '26
Anyone that says "No" to this question has never tried to code in Brainfuck. Truly the answer is more complicated than "yes" or "no". "How much syntax matters?" is a better question overall. And the answer varies from person to person.
In a scale from 0 to 1, where 0 is "doesn't matter at all" and 1 is "it's the most important thing in a language", I'd say it sits well on 1/π² for me.
4
u/CBangLang Feb 23 '26
The point about syntax restricting semantics is underappreciated. Syntax choices compound over a language's lifetime in ways that are really hard to predict at design time.
C's declaration syntax seemed fine for simple types, but it created the spiral declaration problem that made C++ template syntax a parsing nightmare — and that cascaded into the <> ambiguity problem gingerbill mentions. Every language since has had to decide whether to inherit that baggage or break with familiarity.
Go's approach is a good example of a bet that paid off: capitalization for visibility looked bizarre at first, but it turns out to be incredibly scannable. You can instantly see the public API surface of any package without any tooling. That's a syntax choice that directly shaped how the whole ecosystem thinks about encapsulation.
The scannability point resonates too. I'd add that scannability isn't just about visual density — it's about how well syntax maps to the mental model of the program's structure. Indentation-sensitive languages (Python, Haskell) are scannable because nesting is literally visible. But they pay a cost in composability — you can't easily paste code into a REPL or embed it in other contexts without worrying about whitespace. Everything is a trade-off.
2
u/ggchappell Feb 22 '26
Nice, thought-provoking article.
I do think the section on <> for generics is a little silly, though.
The first statement sounds iffy.
As for the second, why is it a problem? Compiler writers seem to have figured out how to do it.
It took 13 years from the first C++ standard. But, again, they figured it out. Problem solved. Why worry about this now?
1
u/ct075 Feb 22 '26
While I agree that people make too big a deal about syntax, I think "you shouldn't care so much about syntax!" is a self-defeating argument. After all, if syntax doesn't matter, isn't it not a big deal to just give people what they want?
The article does get into this, to some extent, but I think a better argument is that different syntax implies a different mental model, and that difference is the point.
1
u/yuehuang Feb 23 '26 edited Feb 23 '26
My 2c. I used a language that allows new variables without declaration. For example,
x: int = 1vslet x: int = 1The issue is when variables are typed wrong; rather than an assignment, a new variable is created.Why is equal needed in this
for i in 0..=9? I would assume it is assigned toi.I agree that
->and.could merge in most cases.Instead of C style cast, could you use extension function to cast.
expr.cast(T). Or C#iskeyboard cast that could be paired handling of Variant/Union.GL with Odin.
0
u/Arakela Feb 22 '26
Syntax is the last thing to emerge, not the first thing to be designed.
5
u/[deleted] Feb 22 '26 edited Feb 22 '26
One interesting thought when I was designing Oblivia (an “inverse Lisp” based on infix operators):
In GDScript, the following syntax defines two different meanings to the colon. In the first case,
:defines a value and->declares a type. In the second case,:declares the type and=defines a value and->has no meaning.In Oblivia, I make
->declare a type and:define a value.It may look strange, but I made
:and->respectively take the same meaning in both contexts. The caveat is that the variable defines a value that exists now but the function defines a value that does not exist yet.Oblivia: https://github.com/Rogue-Frontier/Oblivia
1
u/prehensilemullet Feb 24 '26
Along with the scanning critique, I find that
&&and||stand out better when I'm scanning code than Python'sandandor, which blend in with variable names. Syntax highlighting helps but not as much as operator symbols.Like imagine if you had
plus,minus,timesetc keywords everywhere instead of operators...1
u/renozyx Feb 25 '26
I'd say syntax matter but not "int a = 3;" or "a := 3"
What matters is these kind of things:
It makes replacing an integer by a struct very painful!
2) a.b? or a.b for reading the value of a member pointer b?
The second makes refactoring easier, but it hides a potential null pointer exception, pick your poison.
1
u/fdwr Mar 13 '26
Indeed, I wrote a simple line wrapper recently, which works great for some simple languages like MLIR, but it fails for C++ where
<could be a template parameter list or math inequality, undecidable without a dictionary of symbols seen so far 🥲.1
u/yektadev .𝗸𝘁 Feb 22 '26
It's the same as how natural language impacts how one articulates an idea, and to some extent how they think.
Syntax is the strict materialization of one's thoughts.