Re: Researcher question – what's the point of semicolons and curly braces?

ag0aep6g via Digitalmars-d digitalmars-d at puremagic.com
Sat May 14 16:33:01 PDT 2016


On 05/15/2016 01:01 AM, Joe Duarte wrote:
> Good point that line-ending semicolons carry no information if they're
> on every line (I assume you meant semicolons instead of commas).
[...]
> By the way, anyone should be able to create a version of C, D, or Go
> that doesn't use curly braces or semicolons, just by enforcing some
> rules about indentation and maybe line length that are already adhered
> to by virtue of common coding standards (e.g. blocks are typically
> indented; and I realize Go doesn't require semicolons). If we looked at
> typical code examples in almost any language like C, C#, D, Java, Swift,
> and we systematically encoded their meaning, reducing them down to a
> concise and non-redundant form, we'd find lots of redundancy and a lot
> of textual dead code, so to speak. This would be true even without
> semicolons and braces. There's still a lot for a compiler or any
> interpretive agent to go on.

On semicolons:

There is a promoted style in D that does not use semicolons on every 
line. This example is on the dlang.org home page:

----
// Sort lines
import std.stdio, std.array, std.algorithm;

void main()
{
     stdin
         .byLineCopy
         .array
         .sort!((a, b) => a > b) // descending order
         .each!writeln;
}
----

A leading dot is valid, too. (It means module scope rather than local 
scope.) So without semicolons, there would ambiguities:

----
foo()
.writeln()
----

`foo(); .writeln();` or `foo().writeln();`?


More information about the Digitalmars-d mailing list