Closed AdamNorberg closed 2 years ago
I'm irritated to note that Mono's website says C# 7, but Godot explicitly refers to Mono's C# 8 support in its own docs - https://docs.godotengine.org/en/stable/getting_started/scripting/c_sharp/c_sharp_basics.html - so I would infer it is supported for our use.
To be clear, this is a proposal - switching language versions is a bunch of work, although there are usually tools to automate it. We could even wait for C# 9.0 to get out of Preview and switch to that once it's generally available, since that is theoretically close-ish.
Nullability annotations will be the biggest change to get used to: every field is or isn't nullable. If it's nullable, you must declare it as type?
rather than type
, even if it's a class
rather than a value type. If it's not, leave the declaration as-is. The compiler will forbid assigning literal null
to a non-null field and will warn on assigning a might-be-null value to a non-null field. (It does not emit this warning if it recognizes that the thing you're assigning from cannot be null.)
This allows the language to express, and the compiler to enforce, that a particular API is or isn't ready to handle null
references as parameters. null
is very often not a value you actually want to have as a parameter, so compiler-enforced null safety is nice to have IMO.
I agree, moving to C#8.0 should be done. I don't think it will produce many issues at this point, and I also like compilers catching bugs for me. I've tried to make Godot target C#8.0 specifically, but so far to no avail unfortunately.
Yeah, I think the limit right now is Godot. So this might not be feasible as long as that's our frontend.
Blocking #74.
Turns out Godot is just fine with C# 8.0 and .NET Standard 2.1, and I think I have it working.
Mono now supports C# 8.0, and Godot has adopted a version of Mono with that support. C# 8.0 adds some important features to the language, my favorite being nullability annotations. I like any language feature that makes the compiler catch my bugs for me.
This will involve a process of going through and converting null-oblivious code to null-annotated code, but (like all mass refactoring) this only gets harder the longer it's put off. It's also going to be annoying for everyone until we get used to null-annotated code, after which writing with null-oblivious code will feel scary and unpleasant once we are used to it.