this post was submitted on 20 Oct 2023
39 points (93.3% liked)

Programming

17020 readers
428 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 11 months ago (3 children)

I'm sure a lot of work went into this, but it seems crazy that we need another way to initialise collections, and another way to make fixed sized arrays.

I just want less boilerplate.

[–] [email protected] 3 points 11 months ago (1 children)

The new list initializing syntax is less boilerplate, no?

[–] [email protected] 0 points 11 months ago (1 children)

Look how clunky it is to add support on a collection. Take the example here:

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions#collection-builder

It involves adding a new builder class, and they actually have to reference the function by string name.

It's actually making me even more angry now that I look at it in detail.

[–] [email protected] 2 points 11 months ago

This is for custom collections, right? And you don't even have to use it, you can keep using existing ctors for your custom collections

Worse case scenario you keep doing what we've always had to do. But for the 99% of use cases we get a much more streamlined initializer, with extensions to use our own.

I don't see how that's a bad thing

[–] [email protected] 1 points 11 months ago

I think for arrays it's not really a benefit. But for other types it's superior, compared to the current syntax which just calls add on the list object, which is very inefficient compared to building the whole thing at once which is what this new syntax does.