Is type-sensitive code totally acceptable now? I do use it at times but generally try to avoid it.
C# Pattern Matching
21–30 of 214 posts
Re: C# Pattern Matching
#22Such a beautiful, elegant language. Simple to grasp and lets the compiler handle all that legitimate complexity. Wish more language designers would respect code authors like these designers do.
Why are you being downvoted?
Re: C# Pattern Matching
#23Earlier quoted context omitted.
C# as standard uses camelCase for internal variables and UpperCamelCase for public variables, properties and methods. https://docs.microsoft.com/en-us/dotnet/standard/design-guid...
That's not what he meant. It's not the casing of the names, it's the switching on specific types, rather than building interfaces and using generic programming.
Re: C# Pattern Matching
#24Pattern matching is so much better in F#. C# gets more and bloated to the point of paralysis. It's not yet there but I;m sure it will at some point.
Re: C# Pattern Matching
#25Here's an example of the new syntactic sugar: public static double ComputeArea(object shape) { switch (shape) { case Square s: return s.Side * s.Side; case Circle c: return c.Radius * c.Radius * Math.PI; case Rectangle r: return r.Height * r.Length; default: throw new ArgumentException( message: "shape is not recognized", paramName: nameof(shape)); } } The when clause can be used to deal with special cases (e.g. to a…
With C# 8 you can also write it as: public static double ComputeArea(object shape) => shape switch { Square s => s.Side * s.Side, Circle c => c.Radius * c.Radius * Math.PI, Rectangle r => r.Height * r.Length _ => throw new ArgumentException( message: "shape is not recognized", paramName: nameof(shape)) };
Re: C# Pattern Matching
#26Such a beautiful, elegant language. Simple to grasp and lets the compiler handle all that legitimate complexity. Wish more language designers would respect code authors like these designers do.
By contrast, with a community language where these decisions are made in public, by committee, and perhaps by a team of volunteers, it seems like things are always just a bit more strained. I'm sure some of the more famous PEPs took a huge personal toll on GvR, and there's no doubt that they caused a lot of high emotions. I see similarly troublesome patterns in Nim and Scala, where it would seem that "trying to avoid too much conflict with people who are forcefully communicating strongly held opinions over a medium like the Internet where it's difficult to modulate emotions" can be a real factor in the decision of what language features to include and how. And, in that kind of environment, it's probably particularly difficult to keep the Internet, with all its . . . Internetiness, at bay for long enough to really make sure you've got all the details dialed in right. Much easier, I imagine, to go for the punt and get the whole business over with.
Re: C# Pattern Matching
#27Earlier quoted context omitted.
Wait till you get to work in some complex code bases and you'll understand why jamming all kinds of idioms into one language can become a disaster. It's a tool after all, if you know how to use it properly you don't paint yourself into a corner. However, too much flexibility can lead to many problems in larger teams. Good luck!
I don't know, what's easier to understand? Sorting a list with an IComparer instance that you have to implement in a concrete data type somewhere, or just tossing it a lambda expression? Just because it's new syntax doesn't mean it's automatically more difficult to understand the language.
Not saying C# is bad, thats what you all seem to understand though.
Good luck to you all
Re: C# Pattern Matching
#28Earlier quoted context omitted.
Why are you being downvoted?
Perhaps because he's somewhat implying that other languages aren't doing this, but C# is actually kind of late to the game here.
Re: C# Pattern Matching
#29Pattern matching is so much better in F#. C# gets more and bloated to the point of paralysis. It's not yet there but I;m sure it will at some point.
Unlike in C# pattern matching in F# is exhaustive. I’m guessing this is what was meant by “better”.
However, only direct experience will make you reconsider.
I’ve seen a discriminated union implementation in C# the other day and was repulsed.
Re: C# Pattern Matching
#30Such a beautiful, elegant language. Simple to grasp and lets the compiler handle all that legitimate complexity. Wish more language designers would respect code authors like these designers do.
Why are you being downvoted?