9 ms·
Well, we're getting closer to F#. Still waiting on discriminated unions and expression blocks. (Yes, I know, discriminated unions in F# are just implemented in
by tsomctl 6y ago
Well, we're getting closer to F#. Still waiting on discriminated unions and expression blocks. (Yes, I know, discriminated unions in F# are just implemented in the class hierarchy. But it's awfully nice syntactic sugar.)
> Point p = new (3, 5);
At first glance, not impressive, since you could just do:
> var p = new Point(3,5);
However, it would clean up code like:
> graphics.DrawRectangle(RedBrush, new(3, 5, 2, 2))
- woodrowbarlow 6y ago> graphics.DrawRectangle(RedBrush, new(3, 5, 2, 2)) > graphics.DrawRectangle(RedBrush, new Point(3, 5, 2, 2)) what's the advantage of the first example? i prefer the second, because i don't have to look at the definition of DrawRectangle in order to know that the second argument is a 'Point' object.
- maxton 6y agoThe second argument is a Rectangle, which means you'd be repeating 'Rectangle' twice in one line with the second style.
- surye 6y agoI think this clarification proves his point, and I tend to agree that I prefer the more explicit, verbose style.
- Infinitesimus 6y agoThat's not obvious from the function name though. The function definition could easily be `DrawRectangle(SolidColor, CornerRadii, Point)` and you wouldn't know by seeing a bunch of `DrawRectangle(RedBrush, new(1,2,4,5), Point(4,5,2,2))` would you? It's still nice to have the option in cases where it improves readability (maybe with named args or sth)
- deleted 6y ago[deleted]
- yread 6y agoSomeone in the comments also mentioned array initializers, arguably a better use of the feature.
- nycdotnet 6y agothis specifically. new List<KeyValuePair<string,int>> { new (“a”, 1), new (“b”, 2) } versus having to barf out the type name for every element will be REALLY nice.
- jayd16 6y agoTooling can show it. Rider will show it for you, I'm sure. Saves some typing but it also has refactor implications too. If you change the parameter type, it would change the object being constructed.
- thelazydogsback 6y agoI would love for C# to get rid of "new" as F# does -- why do we need it? var p = Point(3,5). For cases like this it's no big deal, but deep/complex initalizers (like expression trees, etc.) look horrible in C# unless you create static helper fn's to init objects.
- oaiey 6y agoConsidering that MAUI MVU layer is doing a SwiftUI copyjob, that would be advisable. Swift also dropped new at the same time when SwiftUI came out.