| |
| Posted by Steven Schveighoffer in reply to Andrei Alexandrescu | PermalinkReply |
|
Steven Schveighoffer
Posted in reply to Andrei Alexandrescu
| On 3/31/21 10:40 PM, Andrei Alexandrescu wrote:
> On 3/31/21 10:13 PM, Walter Bright wrote:
>> On 3/31/2021 2:59 PM, deadalnix wrote:
>>> On Wednesday, 31 March 2021 at 21:51:07 UTC, Arun wrote:
>>>> Just curious. Does the compiler need semicolon anymore? Are there corner cases that don't work without semicolon?
>>>
>>> They aren't strictly needed most of the time, but they do make things much clearer, especially when you have a syntax error.
>>
>> Yup. They're a form of redundancy like a parity bit is.
>
> There are a few cases that would be ambiguous. Not sure how realistic:
>
> auto a = b;
> *c;
>
> Without semicolons the semantics would be different.
Languages without semicolons generally use some other delimiter, usually newline.
The nice thing about semicolons is that you can pick whatever format you want, so whitespace can be done however you want. But it's a curse as well.
I've been recently teaching a class with D to homeschool kids with super-limited coding experience (in fact, everything they know they learned from me pretty much). We started with Javascript (optional semicolons), and lua ("begin/end" tags), and now on D, I find one of the most common errors that they have a hard time solving is a lack of semicolon. I don't know if this is specific to D, but I do notice that forgetting punctuation usually produces a wall of errors, of which only the first one is relevant (usually). When you have not been programmed to write punctuation in coding properly, the oddest things come out. I sometimes spend minutes trying to figure out why their code is not compiling, when I finally notice a stray closing curly brace somewhere off in the distance.
Not sure if there's a way to improve it.
-Steve
|