If you could make any changes to D, what would they look like?

Dennis dkorpel at gmail.com
Mon Oct 25 17:51:35 UTC 2021


On Monday, 25 October 2021 at 16:31:36 UTC, H. S. Teoh wrote:
>> - Function body literals (`{}` instead of `() {}`)
>
> One can argue about syntax till the cows come home, and we 
> wouldn't come to an agreement. :D

I don't mind the look of it that much, but it's super ambiguous. 
The current parser has a hack to distinguish them from struct 
initializers, and fails to parse it in places where it the 
grammar allows it e.g. [Issue 
14378](https://forum.dlang.org/reply/mailman.357.1635179501.11670.digitalmars-d@puremagic.com).

> These are awesome!  Lets you construct array arguments on the 
> stack where a function accepting only an array would force a GC 
> (or other) allocation.

You can pass an array literal to a `scope int[]` parameter 
`@nogc`.

> But is() expressions are also the backbone of much of D's 
> metaprogramming prowess, so unless you come up with something 
> better, they are here to stay.

Yeah, they'd need a replacement, but man they are so hard to use 
currently. Was it `is(T == E[], E)` or `is(E[] == T, E)`? Why 
does `E` become in-scope when the `is()` is in a `static if`, but 
not in a template constraint? Why is `function` in an `is()` 
expression a function type while elsewhere it's a function 
pointer type?

>> - `alias` reassignment
>
> Whaddya mean, that's one of the best things to happen to D 
> lately, that gets rid of a whole bunch of evil recursive 
> templates from druntime and Phobos.

That could be done in other ways, without introducing AST 
mutation.

>> - `opCall`
>
> opCall is needed for function objects. How else are you 
> supposed to reify functions when you need to?!

I don't know, I never made custom function types.

>> - `opApply`
>
> This is actually useful in cases where the range API may not be 
> the best way to do things (believe it or not, there *are* such 
> cases).

You can still call an `opApply`-like function directly without 
`foreach`.

> One example is iterating over a tree without needing to 
> allocate more memory for the iteration.

I tend to use recursion for that, since my trees don't get that 
deep.


More information about the Digitalmars-d mailing list