On Friday, 1 December 2023 at 13:02:06 UTC, Dom DiSc wrote:
>Either allow it for all initializations, or get rid of it, like DIP 1031 suggested.
I thought the decision actually was made to just get rid of it.
December 01, 2023 Re: struct initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dom DiSc | On Friday, 1 December 2023 at 13:02:06 UTC, Dom DiSc wrote: >Either allow it for all initializations, or get rid of it, like DIP 1031 suggested. I thought the decision actually was made to just get rid of it. |
December 01, 2023 Re: struct initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dom DiSc | On Friday, 1 December 2023 at 13:02:06 UTC, Dom DiSc wrote: >
This IS an initialization and the type is known. Requiring the repetition of the type is also here annoying. Right. |
December 01, 2023 Re: struct initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dom DiSc | On Friday, 1 December 2023 at 13:02:06 UTC, Dom DiSc wrote: >
This IS an initialization and the type is known. Requiring the repetition of the type is also here annoying. Technically you don't have to repeat the type. You can write the return type as
Or you can use
|
December 01, 2023 Re: struct initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Wednesday, 29 November 2023 at 16:48:09 UTC, Paul Backus wrote: >[...]
Indeed. Seems to be in dmd since 2.103.0 (2.102.2 didn't support this syntax). Alas, the Change Log [1] remain silent about it.
The named parameters are not restricted to struct constructors:
|
December 01, 2023 Re: struct initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dom DiSc | I completely agree with the OP, and I want to illustrate this by another example which I find quite bizarre:
I'm a C++ programmer in my day job and the very first instinct I'd have is to replace the first version by the second to reduce verbosity and eliminate an unnecessary copy. However, for some reason the compiler is not able to deduce the type in the second case, so I'm out of luck. I'm glad to hear that, with a compiler update, I will at least be able to do
instead of
but it still seems very inconsistent. |
December 01, 2023 Re: struct initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | Hi All, I feel lonely, just as those who come from C++ find it strange, because I think it makes it difficult to read code. On Friday, 1 December 2023 at 14:53:16 UTC, Paul Backus wrote: >Technically you don't have to repeat the type. You can write the return type as
Or you can use
Paul's example is very readable and short so it's nice. Moreover, when there are named parameters in D, what is the need for them. While there is so much convenience in D, getting stuck on a very simple option... You decide:
SDB@79 |