Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Maybe in c#8. #3

Open
moh-hassan opened this issue May 30, 2019 · 3 comments
Open

Using Maybe in c#8. #3

moh-hassan opened this issue May 30, 2019 · 3 comments

Comments

@moh-hassan
Copy link

c# 8 is considering reference type isn't null by default and now there are two different ways for handling null reference types: Maybe and c#8.
What's the recommendation of using Maybe in c# 8.
Is there a plan for porting the library to be compiled with c# 8 support.

@kmcginnes
Copy link
Owner

That is a good question. I'll start with the bad news first.

I've moved on to Swift development as of about 3 months ago. That means most of my C# projects will start to collect a serious layer of dust.

But I like this question. I took a quick look at how C# 8 is going to implement nullable reference types, and I must say that I'm not impressed. Microsoft seems to be playing it safe and not angering anyone, except the people who would like to see the language grow into something more than it currently is.

That being said, I would recommend always going with the built in way of doing it when that way covers the basics well enough. This gives you the advantage of using a technology that present and future team members will either already know, or can pick up fairly quickly. And when they gain experience using this built in technique they can use that experience in future projects.

I'd suggest copying the SpicyTaco.Maybe code into your project and as you adopt C# 8 see where Maybe fits in. It might go away completely. It might wrap C# 8's option type (I couldn't find where the type is called out, if it exists). It might grow to support it using some new extension methods. I'm not sure. But you'll be much better served by having the code local to your project.

And I can guarantee that this repository won't see any updates in the near to long term. I'm actually going to set a reminder to archive some of my old C# repos so that others will know not to depend on them heavily.

Thank you for the thought provoking question!

@moh-hassan
Copy link
Author

Thanks for reply and clarification.
I cloned the project and migrated it to vs2019 and enabled c#8, then get warning(no errors) in the attached file
warning.txt

I run the test and it pass successfully.

Trying to resolve these warning, I had to define the constraint <T>. then I was stuck with the BIG error:

Error CS8627 A nullable type parameter must be known to be a value type or non-nullable reference type. Consider adding a 'class', 'struct', or type constraint.
So T should be either class or struct not both !!!.

After more reading for c#8 null reference type, I think the goal of Maybe doesn't conflict with c#8:

  • Maybe mange null at run-time for both Reference types and Value types and stop NullReference Exception.
  • C#8 mange null at compile time for Reference types, to avoid NullReference Exception at run-time.

In my opinion Maybe can go side by side with c# 8 , and it can be the last defense against the NullReference Exception at run-time.

CLR isn't aware if the code compiled with c#8 or not.

In my opinion Maybe WIN :)

@kmcginnes
Copy link
Owner

kmcginnes commented Jun 2, 2019

That's interesting. Interesting enough that I setup Dotnet Core 3.0 and Visual Studio Code on my Mac.

But I ran into a lot of issues and a big learning curve migrating the code to dotnet standard. I was able to work past a lot of them. I have the code building and running tests from the command line.

All of that took me a couple of hours to get done today. I don't want to devote any more time to it at the moment. I may pick it up again in the future, but I don't want to make any promises.

The branch I was working on was dotnet-standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants