Live data from Hacker News

C# Pattern Matching

docs.microsoft.com

141–150 of 214 posts

Re: C# Pattern Matching

#141
post #140
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…

C# compiler doesn’t regard “x is object” or “x is null” as null checking statements, so you get warnings if you’re using nullable references. Also, I don’t understand the scare over operator overloading. It’s not common and it works fine with nulls too as long as it’s implemented correctly. If it’s buggy, you’re screwed for other cases anyway, it isn’t much helpful to try to fix null checks only. I find this advice o…

Unity used to take advantage of overloading to implement null checking with "sentinel values" representing a non-existent reference in the Editor

I found this post explaining they considered moving away from the pattern, but I'm not sure if they followed through:

https://blogs.unity3d.com/2014/05/16/custom-operator-should-...

Re: C# Pattern Matching

#142
post #84
post #3

Resharper has proven to be a great way for me to start learning and integrating new language features. I code in my original style and resharper suggests changes based on new features like pattern matching. At first I didnt see the benefit, but this is a hugely powerful feature once you start to wrap your mind around it.

I have clocked in way more hours in Rider than VS. I can flawlessly run and debug our decades old monolith with 40-50 projects and millions LOC, containing C#, VB, Web Forms, WPF, files with 80k lines... And all of our .NET Core services on MacOS, with all my unix-y tooling. There is “VS for Mac”, but it’s not really VS. It’s Xamarin Studio rebranded. Rider works excellent on my Linux box at home as well, where the a…

I have actually also switched more or less to only using Ubuntu, but have been using VS Code. It has become quite powerful in my book and I like that it is the same environment I use across React Native and C#. But I may have to have a little look at Rider then.

Re: C# Pattern Matching

#143
post #73
post #65

I'm super embarrassed as a dotNet developer, at times 'engineer', that I don't know this.. I can't list how many time's I've ran into this kind of issue when trying to explain to a peer/intern.. (Only know I probably messed up a bit now) And HN links like this just remind me that I would love to take a 'bus mans holiday' just to catch up on the framework. This is a huge plus to the benefits of sending employees and m…

It's OK, C# is a living thing, don't feel bad! I'm guessing you use Visual Studio and don't have ReSharper? If so, I have 2 recommendations to make: 1. Get ReSharper! When it sees code that could benefit from language features, it will suggest it 2. Get JetBrains Rider - seriously, try it - it's an alternative IDE with all the ReSharper stuff built-in. I personally find it a better experience than Visual Studio, and…

Visual Studio also does code suggestions for when you can replace a pattern with a newer language construct. I suspect ReSharper is better at it, but I haven't tried VS2019 yet.

Re: C# Pattern Matching

#144

I have been using F# since last year, haven't really looked back to C# since. Unfortunately although we are a small community, it does feel like being last on Microsoft priority list. Microsoft please listen to feedback of your F# users namely on fslang-suggestions and fslang-design repository. My personal wish list for F# are type classes, HKTs, macros and GADTs.

I'm a bit curious about the constant need of hkts. I had a fairly manufactured answer to the following question, which would have saved a couple keystrokes with hkts, but I don't yet get why it is constantly so high on the request list. It seems like something that is cool in theory but would rarely be used in real world code. https://stackoverflow.com/q/21170493/171121

Re: C# Pattern Matching

#145
post #136
post #84

Earlier quoted context omitted.

I have clocked in way more hours in Rider than VS. I can flawlessly run and debug our decades old monolith with 40-50 projects and millions LOC, containing C#, VB, Web Forms, WPF, files with 80k lines... And all of our .NET Core services on MacOS, with all my unix-y tooling. There is “VS for Mac”, but it’s not really VS. It’s Xamarin Studio rebranded. Rider works excellent on my Linux box at home as well, where the a…

My only complaint is I can’t ignore auto-gen’d code like EF migrations in dotCover, so my unit test coverage looks terrible. It doesn’t help that I write terrible unit tests, but still!

I run a little powershell script on build that adds the [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] attribute to generated classes in certain folders.

https://gist.github.com/mtone/aded2ff636cb6dd9d428cf5800f344...

Funnily, I have no clue how to setup a build script in Rider, did that in VS (Rider do run it).

Re: C# Pattern Matching

#146

Earlier quoted context omitted.

It always feels a bit half baked when the class library isn’t designed with it though. It would be as if generics were added but not System.Collections.Generic. So while I long thought it would be the perfect addition to C#, I’m not so enthusiastic any more. It would be great (F# is!) but not as good as it would be in a language and platform where it was there all along. In F# this is already an issue when you want t…

> It would be as if generics were added but not System.Collections.Generic I started with C# in the 1.0 days before generics. The lack of strongly typed collections was very annoying with all of the casts involved. I used to use a template engine/code generator to create strongly typed collections. Can't remember the name of the tool... Probably been since 2002 or 2003 since I used it.

Codesmith?

Re: C# Pattern Matching

#147
post #140

Earlier quoted context omitted.

C# compiler doesn’t regard “x is object” or “x is null” as null checking statements, so you get warnings if you’re using nullable references. Also, I don’t understand the scare over operator overloading. It’s not common and it works fine with nulls too as long as it’s implemented correctly. If it’s buggy, you’re screwed for other cases anyway, it isn’t much helpful to try to fix null checks only. I find this advice o…

Unity used to take advantage of overloading to implement null checking with "sentinel values" representing a non-existent reference in the Editor I found this post explaining they considered moving away from the pattern, but I'm not sure if they followed through: https://blogs.unity3d.com/2014/05/16/custom-operator-should-...

Yeah that means OP’s advice would actually break the code written for unity.

Re: C# Pattern Matching

#148
post #140

Earlier quoted context omitted.

C# compiler doesn’t regard “x is object” or “x is null” as null checking statements, so you get warnings if you’re using nullable references. Also, I don’t understand the scare over operator overloading. It’s not common and it works fine with nulls too as long as it’s implemented correctly. If it’s buggy, you’re screwed for other cases anyway, it isn’t much helpful to try to fix null checks only. I find this advice o…

Unity used to take advantage of overloading to implement null checking with "sentinel values" representing a non-existent reference in the Editor I found this post explaining they considered moving away from the pattern, but I'm not sure if they followed through: https://blogs.unity3d.com/2014/05/16/custom-operator-should-...

They didn't move away from the pattern and can't anymore as it would break almost every existing Unity project.

Re: C# Pattern Matching

#149

Earlier quoted context omitted.

Data science, vision, etc - this is where Python reigns supreme and using C# is really going against the rest of the industry. Using OpenCV from .NET is painful, but from Python it feels native.

Yeah, this is basically the boat I'm in. Python dominates. You either write it in Python, or maybe get away with writing it in something else and then wrapping it in Python. I don't mind Python, but now that I've gotten a taste of ADT's and non-nullable types, writing Python feels like a kludge.

Python (the language) feels more like a less-capable version of JavaScript now - with all of the disadvantages of lacking AOT type-safety (I know static type-checks are now available with 3.6 - but remember that most of the world is still using Python2...).

Re: C# Pattern Matching

#150
post #7
post #3

Resharper has proven to be a great way for me to start learning and integrating new language features. I code in my original style and resharper suggests changes based on new features like pattern matching. At first I didnt see the benefit, but this is a hugely powerful feature once you start to wrap your mind around it.

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 :)

For our 32 project solution, Rider is so awkwardly slow at startup and if you pull from master it just dies. Also it just loves to notify you about everything. I still prefer VS.
Post reply on HN