Live data from Hacker News

C# Pattern Matching

docs.microsoft.com

151–160 of 214 posts

Re: C# Pattern Matching

#151

Earlier quoted context omitted.

Every single feature C# got in past years increased my productivity. I understand that it may cause issues to new learners, but overall, what of them do you consider bloat?

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!

So not a single example? Your name is fitting.

Re: C# Pattern Matching

#152
post #53
post #7

Earlier quoted context omitted.

as an aside, if you got Rider as part of your resharper subscription, try it out, it is basically a drop in replacement for visual studio but faster and with many many little quality of life improvements you never knew you needed :)

I started using Rider recently. It's faster yes, but seems to be a bit more memory hungry out of the gate than VS+Resharper. There is one HUGE thing I miss however - the Package Manager console. There's still a few things I have to do in there and thus have to switch back to VS.

VS is 32 bit, so instead of getting more memory when it needs it slows to a crawl and eventually crashes. I think that the early versions of VS are a bloodbath. VS 2019 just crawled with a small solution just because there were mixed C# and F# projects. I should remember to upgrade always after 2 or 3 minor revisions instead of being a guinea pig for MS. On the other hand some time ago I got a bug in rider where the F# code worked perfectly in VS but didn’t work at all in rider and until today I have rider highlighting some errors in perfectly valid c# code but the build is successful while for resharper that code is fine. And the biggest current pain that I have is that I cannot debug ny tests in VS but they work perfectly in rider. So for now I’m sticking to both of them until rider irons up some small wrinkles.

Re: C# Pattern Matching

#153
post #93

Heads up for C# devs, you should switch all your code bases to use (x is null) and !(x is null) instead of ==. The is operator can't be overloaded, and always compiles to IL eq, whereas == can be overloaded in custom types. Of course it would also be nice if everything was moved to nullable reference types [0], but that's a non trivial amount of work. Note that most C#8 features can be enabled manually through the cs…

> The is operator can't be overloaded, and always compiles to IL eq, whereas == can be overloaded in custom types.

That's exactly the reason to use the opposite. In certain C# environments (like Unity game engine) the == is overloaded in a very meaningful way (when C# objects are used as representations of unmanaged objects, and they appear to "equal null" if the represented object is no longer available in the system), and using methods other than == to compare to null (such as casting to boolean) can introduce hard to detect bugs.

Re: C# Pattern Matching

#154
post #109

Earlier quoted context omitted.

> replacement for visual studio but faster How can a IntelliJ Idea derivative written in Java be faster than VistalStudio which is native code? Both Idea and PyCharm work much slower than VisualStudio on my machine.

Visual Studio has been unable to keep up with my (not notably fast) typing since like 2005. Rider has no issue. Nor does IntelliJ or CLion or Goland.

I worked in Visual Studio full-time for many years, now I'm coding in PhpStorm (IntelliJ IDEA) since July 2019, and while overall it's really powerful, I still kind of miss VS. One notable problem I have with PhpStorm is that oftentimes when I'm trying to find files or text in files, I press the respective keyboard shortcut and start typing immediately, in WebStorm the first few letters often end up being typed into the currently opened file instead of the "Find..." dialog, which never happened to me in VS. A minor issue, but it occurs every single day.

A similar thing makes me go nuts in Windows as well - in Windows 7 I pressed the WinKey and started typing immediately to find an application, never had a problem, but Windows 10 often misses the first few keystrokes after the Start menu opens. I can't believe this hasn't been fixed for years.

--

EDIT: fixed a typo

Re: C# Pattern Matching

#155

I've always seen switch statements as an anti-pattern in C#. These examples however, do demonstrate neat time saving techniques. Does anybody have examples of real-world use cases that take advantage of this that couldn't (or shouldn't) be solved in a more OO way (Visitor, Strategy, Template Method, etc)

Why are switches an anti-pattern? Switching a simple switch with a strategy pattern can make code far more complex and hard to understand. Switches are simple to code, simple to read, and easy to change.

Because it’s a switch statement, not an expression and a lot of people tend to use it for doing stuff more complex than a single line. Being it a statement there is nothing that forces you to return from each case and you may forget to use the break keyword mistakenly executing also the next case.

Re: C# Pattern Matching

#156

Java is getting tuples, PHP is getting union types, C# is getting pattern matching... someone is going to announce algebraic data types and I'll die. Nice work, C#!

The proposed record implementation in C# is awful, so don’t hold your breath.

Re: C# Pattern Matching

#157
post #7

Earlier quoted context omitted.

as an aside, if you got Rider as part of your resharper subscription, try it out, it is basically a drop in replacement for visual studio but faster and with many many little quality of life improvements you never knew you needed :)

> replacement for visual studio but faster How can a IntelliJ Idea derivative written in Java be faster than VistalStudio which is native code? Both Idea and PyCharm work much slower than VisualStudio on my machine.

I haven't used rider but VS can spin up some Nodejs processes if you work with js and they are an abomination

Re: C# Pattern Matching

#158

Earlier quoted context omitted.

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.

I got nothing against functional programming, I embrace it. However, im stating again, shoving everything under one umbrella is bound to create a complex monster. Functional programming is actually easier to understand in F# rather than C#, the idioms do translate but clunkily. Do yourseves a favor and spend some time outside C# and you’ll come back illuminated. Not saying C# is bad, thats what you all seem to unders…

I really am not sure why you seem to think no one besides yourself has tried F#/OCaml/Haskell/SML before.

Your comments are extremely condescending.

Re: C# Pattern Matching

#159
post #109

Earlier quoted context omitted.

Visual Studio has been unable to keep up with my (not notably fast) typing since like 2005. Rider has no issue. Nor does IntelliJ or CLion or Goland.

I worked in Visual Studio full-time for many years, now I'm coding in PhpStorm (IntelliJ IDEA) since July 2019, and while overall it's really powerful, I still kind of miss VS. One notable problem I have with PhpStorm is that oftentimes when I'm trying to find files or text in files, I press the respective keyboard shortcut and start typing immediately, in WebStorm the first few letters often end up being typed into…

Windows 10 start menu is so bad I cut it out from every Windows machine I have any authority over. Try Keypirinha, it's very snappy and supports fuzzy search.

https://keypirinha.com/

Re: C# Pattern Matching

#160
post #93

Heads up for C# devs, you should switch all your code bases to use (x is null) and !(x is null) instead of ==. The is operator can't be overloaded, and always compiles to IL eq, whereas == can be overloaded in custom types. Of course it would also be nice if everything was moved to nullable reference types [0], but that's a non trivial amount of work. Note that most C#8 features can be enabled manually through the cs…

a number of the C# lang developers prefer (x is object) for the latter, FWIW.

why not add an operator so you can say (x !is null)?
Post reply on HN