Things I found great about TypeScript that D could benefit from
SimonN
eiderdaus at gmail.com
Sat Apr 28 21:25:28 UTC 2018
On Friday, 27 April 2018 at 19:17:14 UTC, w0rp wrote:
> The first feature I found really useful is the
> --strictNullChecks option that TypeScript has. I hate null
> dereferencing errors with a passion, and they have been the
> number one source of bugs that I've seen.
> * Strict null checking is a winner, and you can use ordinary
> syntax to handle this.
> That's it, let me know your thoughts.
Non-null class references are my #1 missing D feature. :-) When
we don't have to worry about null-or-not, we have our mind free
for the interesting problems. I love to peek around other
languages and see how they tackle this problem. Thanks for the TS
overview!
You advocate automatic narrowing inside if (x != null) even over
Optional types. Is it because you find automatic narrowing
cleaner than Optional? Or do you simply consider automatic
narrowing a worthwhile addition whether or not a language has
non-null + Optional?
```
void f(Optional!T x) { if (x !is null) g(x); }
void g(T x) { h(x); }
void h(T x) { writeln(x.myField); }
```
With a strictly non-nullable T, you can write `g` and `h` cleanly
and null-safely. Without non-nullable types, even with implicit
narrowing, both `g` and `h` would need an if/get or optional
dispatch, complicating their definition.
-- Simon
More information about the Digitalmars-d
mailing list