Chad Perrin: SOB

14 February 2007

arguing over semantics vs. syntax

Filed under: Cognition,Geek,Humor,Metalog — apotheon @ 03:46

So much for my post about Java. I've been distracted by other things. Maybe I'll get back to it when I'm feeling inspired by the subject again.

So: What's on my mind now?

How about a discussion of the two primary factors of language design (as contrasted with implementation)? Let's discuss what happens when I make a fairly straightforward, unarguably true (I thought) statement about the importance of syntax in language design.

It all started with a reddit discussion of Lisp vs. Python — or, more accurately, a discussion of a lengthy explanation of how the two compare titled Merits of Lisp vs. Python and composed by some aerospace engineer guy apparently named Tom. It's worth a read, by the way — even if you disagree with some of it, there's a lot of good information in there, presented in the form of Tom's perspective after two glasses of wine.

Anyway . . . someone with the username sigfpe questioned the importance of prefix vs. infix notation in determining the elegance and simplicity of a language's syntax. It seems sigfpe thinks that's just a superficial detail, and wonders if (s)he missed something. My response went a little something like this:

> "Or is there some subtle and deep property of the placement of operators that I'm missing?"

Yes, there is. Prefix operators, employed consistently in a language, allows for a greater elegance and simplicity to the interconnected rules of syntax within that language. Precedence confusion, dirty hacks to chain operations, and grouping ambiguities are pretty much impossible with a consistent system of prefix, vs. infix, operators.

Realize that what the aerospace engineer who wrote that really meant, whether it consciously occurred to him or not, was not that prefix operators are more elegant than infix operators: it's that prefix operators and everything they imply constitute a more elegant way to do things.

Ultimately, there are two important factors in determining the strength of a language design (as opposed to a language's features, which is another subject entirely): syntax and semantics. "Semantics" refers basically to the superficial aspects of language design, like "Are we going to call our function constructor fun or defun?" "Syntax" refers to the form the language takes, the kind of thinking the (successful) programmer will do, and how programs fit together. That's the deep magic of a given programming language, as manifest in its design. The choice of prefix or infix operators is a part of that.

The first response to me, from someone with the username andyc:

I think you got syntax and semantics mixed up

Needless to say, my mind boggled. Anyone out there reading this that understands subjects like syntax and semantics, particularly as they apply to programming language design, should be pretty clear on the fact that andyc said something pretty odd. I figured I should try to explain the situation, especially since for some reason andyc got an upvote from someone for that statement — indicating that andyc isn't the only person at reddit who wondered whether I said something incorrectly. Time to settle the matter, complete with links to dictionary definitions in case the misunderstanding was due to unfamiliarity with the actual meanings of the terms being used:

Nope. Syntax relates to how "statements" (typically lines of code, blocks, et cetera) are composed. Semantics relates to what terms mean.

Examples:

syntax = foo(bar) vs. bar.foo

semantics = foo(bar) vs. baz(bar)

That should settle it. Right? Right!? Well . . . apparently not. User pjdelport (yes, that makes three people so far that have actually pitched in their displays of ignorance) responded with this gem of "Am I too short? Did that go over my head?":

In your original post, i think you got them the other way around, though.

Syntax is form, or "the superficial aspects of language design, like 'Are we going to call our function constructor fun or defun?'". Semantics is meaning, or "the deep magic of a given programming language, as manifest in its design".

The choice of prefix, infix, or postfix syntax is ultimately a surface issue, as demonstrated by the various infix syntaxes for Scheme, and Haskell's support for switching arbitrarily between prefix and infix application.

About the most flattering thing I can say about that is "At least pjdelport knows how to properly nest quotation marks."

I responded to him, of course, though I didn't say anything new and interesting — just double-checked with incredulity what he is assuming. You can read it there if you really want to.

Brian told me his take on what happened in that discussion:

in this case i think they're idiots.

Sterling "chipped in" (sorry, the pun had to be made):

They just don't get it.

This was Allison's reaction when she saw that thread of the discussion:

snerk What I want to know is where you get the patience necessary to hang out online and answer these people.

I literally laughed out loud at that one.

edit: I wonder if the confusion of someone like pjdelport can be blamed on the facile manner in which people have used the word "meaning" over the years to refer to the deeper questions of philosophy, as if saying "meaning" with some kind of ominous intonation or emphasis makes something more honest, insightful, and altogether important. Maybe the problem is the degeneration of university English departments in the post-Derrida era.

9 Comments

  1. pjdelport gets stuck on the "form vs meaning" distinction. s/he doesn't realize that the form is what creates the expressive power of a programming language, and the meaning you express with it is secondary.

    Comment by Sterling Camden — 14 February 2007 @ 04:10

  2. Yeah . . .

    As someone pointed out to me in IMs (I think it was Allison, but I don't really recall off the top of my head), the issue with pjdelport's (mis)understanding may arise from the simple fact that we (programmers) often trivialize syntax by how we make reference to it when discussing programming languages. For instance

    Err, wait, found the direct quote. It was indeed Allison:

    (15:28:52) Allison: I suspect the other language issue that one hits, when discussing syntax v. semantics, is that people often use syntax in the "I don't know Java, but I know C++, and after that it's just a matter of learning the syntax." That is, there's a third level: that of programming paradigm, and it trumps any of the lower-level language details.

    (15:29:46) @: True . . . but that isn't really a "design" issue — it's a bit more fundamental than that, and is largely manifest in syntax.

    (15:31:13) Allison: Not design, but architecture, yes. It's just that the way we talk about these things tends to trivialize syntax, except where language holy wars are taking place. <wry grin>

    (15:31:26) @: True, that.

    (15:31:40) @: I thought the Derrida bit was a more amusing possible explanation, though.

    Comment by apotheon — 14 February 2007 @ 04:30

  3. very insightful. i think there is still this prominent misconception that form and function can be separated, and that any given function can be swapped for an "equivalent" one without impacting form.

    Comment by sosiouxme — 15 February 2007 @ 06:35

  4. though perhaps now i'm confusing which is syntax and which is semantics :-) or just relating a different dichotomy.

    Comment by sosiouxme — 15 February 2007 @ 06:39

  5. [...] When it comes to the expressive power of a programming language, syntax (the form of statements) makes a huge difference. Semantics (the meaning of terms) are relatively inconsequential, so long as they are precisely defined. [...]

    Pingback by Chipping the web - Free as a bird -- Chip’s Quips — 15 February 2007 @ 02:13

  6. You are mistaken. The canonical example is Knuth's man or boy test. The results of this code are different depending on whether call-by-value or call-by-name are used. The syntax is identical.

    Comment by tjalfi — 16 February 2007 @ 02:36

  7. Thanks for the input, tjalfi.

    What you're failing to include in your analysis is that the man or boy test actually tested for differences in behavior. The syntax used in the test is the same for differing results because the syntax and semantics implemented in the language are different.

    Comment by apotheon — 16 February 2007 @ 03:11

  8. The definitions you are using are different from those in the following books: Semantics of Programming Languages, the Formal Semantics of Programming Languages, and Theories of Programming Languages. The only formalism that defines what you're referring to as synax with what most people call syntax is W-grammars. There is a Russian saying that comes to mind, "when three men tell you you're drunk, go home."

    Comment by tjalfi — 16 February 2007 @ 05:34

  9. Funny — I'm pretty sure those books don't contradict my statements that syntax is structure and semantics is meaning. Maybe I should go double-check.

    Comment by apotheon — 17 February 2007 @ 12:13

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

All original content Copyright Chad Perrin: Distributed under the terms of the Open Works License