On Tuesday, 3 May 2016 at 03:48:09 UTC, Joe Duarte wrote:
Hi all,

I'm a social scientist and I'm preparing some studies on the effects of programming language syntax on learning, motivation to pursue programming, as well as any disproportionate effects that PL syntax has on the appeal of programming to women (more on the latter in a separate post).

So I want to get a better idea of the rationale for various syntactical design decisions, and I'm going to ask you the same question I'll ask the Rust community:

Why are curly braces and semicolons necessary? What information do they carry that a compiler could not otherwise reliably obtain?

Here's an example from the D Overview page:


class Foo
{
    int foo(Bar c) { return c.bar; }
}

class Bar
{
    int bar() { return 3; }
}


Okay, if we remove the curly braces and semicolons, we have:


class Foo

    int foo(Bar c) return c.bar


class Bar

    int bar() return 3


Would it be difficult to compile the clean version? Would there be issues with the design of the lexer/parser? I assume the compiler would recognize keywords like return (and a clean syntax could drive different rules for what statements and expressions could appear on the same line and so forth).

In reality, a compiler would see the above with line ending characters terminating every line (e.g. U+000A), so it would be as line-aware as a human. I've never built lexers or parsers, much less compilers, so maybe I'm missing a major implementation hurdle. I'm just thinking that Facebook has built software that recognizes my face in other people's pictures, so it seems like building software that understands structured text would be a solved problem. It puzzles me to see so much apparent punctuation noise in a 21st-century language (and, to be fair, Rust puzzles me for the same reasons).

JD

Compilers, with or without curly braces and semicolons, will handle their intended syntax for their corresponding language just fine, in a matter of milliseconds. Also, compilers are a mature science now and they are well understood in general.

The important thing to consider is the human programmer. We don't read code in milliseconds, we take dozens of seconds, even minutes, to read and understand a page of code.

Therefore, any help the language syntax can provide in order to help us read and understand code faster, is extremely welcome.

Many times, that help comes from our text editor. We use text editors with many different colours for many different parts of code.

Now, the curly braces and semicolons are coloured too. And these coloured symbols help us read and understand code faster than simple indentation. In fact, I avoid to read code without colours.

They can be a burden to type, which is a reason some developers dislike them, but code is written fewer times than it is read.

Anyway, this is my opinion. They are used because they help us to read and understand code faster. Compilers don't need them, we do.

Reply via email to