-
Notifications
You must be signed in to change notification settings - Fork 59
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
Shorthand nullable-type syntax #77
Conversation
This looks fine to me and I agree with the motivation. Originally I was against and I'm still a bit undecided regarding adding syntax sugar for nullable types, because I believe that usage of nullables should generally be minimized. However the current situation is that having Regarding type-as-expression, I think it's the same situation as with the type params - we just don't parse that at all currently, so |
I'm generally in favor of this since it would reduce the visual clutter when working with null safety by a lot. However, I wonder about the "consequences" considering the the existing optional argument and object field syntax. The following would all be possible, but look confusing: function foo(?i:Int?) {}
typedef Foo = {
var ?i:Int?;
}
typedef Foo = {
?i:Int?
} Putting a
I think we should consider simply forbidding to put whitespace there, similar to the |
Regarding the proposal, maybe it's worth showing some awkward possible situation with implicit |
I think we can emit an error if a redundant |
@RealyUniqueName Which redundancy are you talking about? The optional |
Thanks for the quick feedback! For starters, the "type-as-expression" was a bit ambiguous when I wrote it due to lack of in-depth compiler knowledge, but I was also thinking about parenthesis as a solution. I'll go ahead and remove some of the uncertainty in the section and commit to explicitness through either parenthesis or For the whitespace, I just committed to allowing it since both C# and Kotlin allow it, but quite frankly it looks horrible, even with just a single space and would actually much prefer it force no whitespace. Would be more than happy to change that as well. In regards to printing, do you mean there should be some differentiation between And finally, in regards to |
The latter. We don't retain the details of the original syntax anyway, especially in the typed tree. |
Regarding |
I don't like how this looks. IMO I acknowledge that this is easier to type, but in that case it should be solved at IDE-level. |
Since we already have |
TL;DR: While I'm not against
I'm afraid to say that we don't have optional types but actually optional arguments/fields that are coincidentally marked in Not to mention that optional and nullable works differently (i.e. optional args can be skipped but nullable args cannot), I think we should at least try to not mix up optional and nullable, they are meant to work in a completely different layer. TypeScript is one example which has optional properties and arguments, just like we do, but (unsurprisingly) lacks shorthand nullable-type syntax. And I'm sorry if I summoned Nic's veto, as this state would confuse beginners even more (hey I've just defined a typedef with nullable field in Summary: We should first clean up and break optional, which would not happen, before making another use of the P.S. I personally welcome a haxe-evolution that deletes the ternary (I don't mind typing |
That's circular reasoning. For the parser For the legacy function syntax, there's indeed some ambiguity, as Maybe postfix
Many (most?) people would, because it often stands in the way of adding sane syntax. Unfortunately it's quite widely used, so it's doubtful such a breaking change will ever come ;) |
We have rejected the proposal in the haxe-evolution meeting today. The syntax has no clear advantage other than potentially being shorter. There were also concerns about possible syntactic ambiguities that could arise from this. |
Allow
T?
as shorthand forNull<T>
.Rendered version