Researcher question – what's the point of semicolons and curly braces?
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Tue May 3 00:53:15 PDT 2016
On Mon, 02 May 2016 21:23:48 -0700
Walter Bright via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> On 5/2/2016 8:48 PM, Joe Duarte wrote:
> > Why are curly braces and semicolons necessary? What information do
> > they carry that a compiler could not otherwise reliably obtain?
>
> You are correct in that they are (mostly) redundant. Some ambiguities
> can arise because D is not a whitespace delimited language. However,
> the real reasons are:
>
> 1. Redundancy in specification means the compiler can catch more
> 'typo' mistakes rather than having them compile successfully and then
> behave mysteriously. If a language has 0 redundancy, then any
> 8745b48%%&*&hjdsfh string would be a valid program. Redundancy is a
> critical feature of high reliability languages.
That redundancy also can make it much easier for the programmer to figure
out what's going on. And it better expresses the intent of the code when you
have some of those redundancies. Without them, it can be a lot less obvious
when something was intentional or a mistake (e.g. how far a particular line
was supposed to be indented).
I know that there are plenty of folks who start out programming with a
scripting language of some sort and don't like it when they have to deal
with braces and/or terminating semicolons, but I think that it's a lot like
static typing vs dynamic typing. At first, it might _seem_ more liberating
to have dynamic typing, but the number of errors that creep in with dynamic
typing is much higher than with static typing, because the compiler simply
isn't set up to catch many problems for you with a dynamic language, where
it is with a static one.
I think that it's clear that languages like python have shown that it's
possible to have a successful language with no curly braces or semicolons
and puncuation-like syntax overall, but I don't think that it's been shown
that it's necessarily a _good_ idea - just that it can work. It's not that
hard to find rants online from folks who used to love python's use of
whitespace as a delimiter only to have big enough problems with it in a
serious program that they now hate it with a passion.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list