April 03, 2021

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?

SIL (in-house language @ Symmetry Investments, implemented in D) has optional semi-colons. We made them work by insisting that statements are unambiguous between eager and non-eager parsing over line-breaks. Instead of choosing which version is correct with a rule, we simply disallow anything that would be ambiguous.

For example:

a = foo
(bar())

Instead of deciding which interpretation is correct (assign the function foo to a then call bar or call bar, pass result to foo, assign result of foo to a), this is simply a parse error and the user must include a backslash or a semicolon after foo to disambiguate.

We are more conservative about this than we should be and therefore disallow some code that isn’t actually ambiguous, but in practice it doesn’t seem to be much of a problem.

Having said all that, D is fine with semicolons and should keep them.

May 11, 2021
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?

Please never even considering semicolons to be optional in D. I once hit a optional semicolon issue in JavaScript, that took two weeks to debug. I hate that feature since then (~2005).

If you don't want to use semicolons, just use Python-like syntax, and then run it thour some converter for example.

May 11, 2021
On Tuesday, 11 May 2021 at 15:41:02 UTC, Witold Baryluk 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?
>
> Please never even considering semicolons to be optional in D. I once hit a optional semicolon issue in JavaScript, that took two weeks to debug. I hate that feature since then (~2005).
>
> If you don't want to use semicolons, just use Python-like syntax, and then run it thour some converter for example.

function foo()
{
    return
    {
        foo: "bar"
    }
}

console.log(foo())

What does this log? "undefined", obviously, what did you expect?

I learned this the hard way too.
May 11, 2021
On Tuesday, 11 May 2021 at 16:31:34 UTC, deadalnix wrote:
> On Tuesday, 11 May 2021 at 15:41:02 UTC, Witold Baryluk 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?
>>
>> Please never even considering semicolons to be optional in D. I once hit a optional semicolon issue in JavaScript, that took two weeks to debug. I hate that feature since then (~2005).
>>
>> If you don't want to use semicolons, just use Python-like syntax, and then run it thour some converter for example.
>
> function foo()
> {
>     return
>     {
>         foo: "bar"
>     }
> }
>
> console.log(foo())
>
> What does this log? "undefined", obviously, what did you expect?
>
> I learned this the hard way too.

Will not work unless it is `void foo()` function.
LDC will also complain about unreachable code, at least in release/optimization mode.
It is also another story in languages with implicit last statement return like Nim or Kotlin (and Rust IIRC).
May 11, 2021
On Tuesday, 11 May 2021 at 16:31:34 UTC, deadalnix wrote:
> On Tuesday, 11 May 2021 at 15:41:02 UTC, Witold Baryluk 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?
>>
>> Please never even considering semicolons to be optional in D. I once hit a optional semicolon issue in JavaScript, that took two weeks to debug. I hate that feature since then (~2005).
>>
>> If you don't want to use semicolons, just use Python-like syntax, and then run it thour some converter for example.
>
> function foo()
> {
>     return
>     {
>         foo: "bar"
>     }
> }
>
> console.log(foo())
>
> What does this log? "undefined", obviously, what did you expect?
>
> I learned this the hard way too.

Yeah.

How about this:

```javascript
function bar(x) { return x; }
function baz(x) { return x; }

function foo(aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {
  return bar(aaaaaaaaaaaaaaaaaaaaaaaaaaaa)
         + baz(aaaaaaaaaaaaaaaaaaaaaaaaaaaa);
}
console.log(foo(21))
```

Learned very hard way.

May 13, 2021
On Wednesday, 31 March 2021 at 21:59:22 UTC, 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.

Since when? I use LDC 1.24 and it won't compile without semicolons...
1 2
Next ›   Last »