July 08

On Saturday, 8 July 2023 at 12:42:13 UTC, Bastiaan Veelo wrote:

>

On Saturday, 8 July 2023 at 08:30:47 UTC, Danilo Krahn wrote:

>

Please add this and super to constructor parameters.

Note that for structs, there is no need to define a constructor if parameters map on fields one on one and the constructor does nothing else:
...
And if they don't map one on one, the caller can use a static or dynamic initializer instead:

    Rectangle r2 = {width:6, height:7, x:4, y:5};
    writeln(r2); // Rectangle(4, 5, 6, 7, Blue)

That doesn't allow fields to be dynamically initialized automatically, like constructors do.

>

For classes, though, this isn't available.

Your proposal wouldn't work in a nested class, as this and super refer to the nesting class.

No, this and super refer to the nested class instance. You access the outer class instance using the outer property:
https://dlang.org/spec/class.html#outer-property

July 08

On Saturday, 8 July 2023 at 15:58:57 UTC, ryuukk_ wrote:

>

On Saturday, 8 July 2023 at 15:33:34 UTC, Danilo Krahn wrote:

>

On Saturday, 8 July 2023 at 14:52:34 UTC, ryuukk_ wrote:

>

Constructor on structs?

Vectors as classes with inheritance?

Sorry, but this is just bad advice that nobody should follow

It's not advice. It's explaining what the example code means with the new feature.

>

nobody should use constructor on structs

That's the first time I've ever heard that.

https://dlang.org/phobos/std_typecons.html#.Nullable.this
https://dlang.org/phobos/std_typecons.html#.Tuple.this
https://dlang.org/phobos/std_typecons.html#.Unique.this

>

and nobody should use classes for basic stuffs that should be simple pod

What if you want a vector reference type on the heap, e.g. for immutable vectors to share across threads? new Struct would return a pointer, so += won't work. Or if you want it to be synchronized?

July 08

On Saturday, 8 July 2023 at 19:57:55 UTC, Nick Treleaven wrote:

>

On Saturday, 8 July 2023 at 15:58:57 UTC, ryuukk_ wrote:

>

On Saturday, 8 July 2023 at 15:33:34 UTC, Danilo Krahn wrote:

>

On Saturday, 8 July 2023 at 14:52:34 UTC, ryuukk_ wrote:

>

Constructor on structs?

Vectors as classes with inheritance?

Sorry, but this is just bad advice that nobody should follow

It's not advice. It's explaining what the example code means with the new feature.

>

nobody should use constructor on structs

That's the first time I've ever heard that.

https://dlang.org/phobos/std_typecons.html#.Nullable.this
https://dlang.org/phobos/std_typecons.html#.Tuple.this
https://dlang.org/phobos/std_typecons.html#.Unique.this

All of these are poorly designed constructs

Nullable? should be a tagged union or something built-in, tuple, should be built-in as well

> >

and nobody should use classes for basic stuffs that should be simple pod

What if you want a vector reference type on the heap, e.g. for immutable vectors to share across threads? new Struct would return a pointer, so += won't work. Or if you want it to be synchronized?

This is the result of poorly designed software, you always want to do more esoteric things; "the java way"

July 09

On Saturday, 8 July 2023 at 18:34:44 UTC, claptrap wrote:

>

On Saturday, 8 July 2023 at 08:30:47 UTC, Danilo Krahn wrote:

>

Please add this and super to constructor parameters.

To get a new feature added to the language someone needs to write a detailed "D improvement proposal" for it...

https://github.com/dlang/DIPs

It takes a lot of effort, so either you have to care enough about it to do it yourself or you need to find someone else who feels the same.

All you get by asking for a feature in the forum is a bunch people yapping about it.

Im only telling you this so you dont have unrealistic expectations regarding your request. And it is worth considering that it's probably something that's been suggested before, I dont remember for sure, but probably. And there's pretty much always bigger fish to fry.

Thanks!

July 09

On Saturday, 8 July 2023 at 08:30:47 UTC, Danilo Krahn wrote:

>

Please add this and super to constructor parameters.

better to add records
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/record

July 09

On Saturday, 8 July 2023 at 20:54:14 UTC, ryuukk_ wrote:

>

This is the result of poorly designed software, you always want to do more esoteric things; "the java way"

To be fair, java is a really well designed language for its domain. It follows the idea of a simple language with a rich standard library, which is what I think OP is expecting of D.

July 09

On Saturday, 8 July 2023 at 19:41:39 UTC, Nick Treleaven wrote:

>

...

>

And if they don't map one on one, the caller can use a static or dynamic initializer instead:

    Rectangle r2 = {width:6, height:7, x:4, y:5};
    writeln(r2); // Rectangle(4, 5, 6, 7, Blue)

That doesn't allow fields to be dynamically initialized automatically, like constructors do.

https://dlang.org/spec/struct.html#dynamic_struct_init
Is this not... "automatic"?

July 10

On Saturday, 8 July 2023 at 08:35:12 UTC, FeepingCreature wrote:

>

For simple code, you can use my boilerplate library https://code.dlang.org/packages/boilerplate

And for really simple cases you can just do:

class C {
    int x;
    string y;
    float z;

    this(typeof(C.tupleof) args) {
        this.tupleof = args;
    }
}
void main() {
    auto c = new C(1, "foo", 1.0);
}

But I guess boilerplate supports more advanced features.

July 12

On Sunday, 9 July 2023 at 17:32:20 UTC, IchorDev wrote:

> >

That doesn't allow fields to be dynamically initialized automatically, like constructors do.

https://dlang.org/spec/struct.html#dynamic_struct_init
Is this not... "automatic"?

It's dynamic, but it's not automatic.

1 2
Next ›   Last »