3 ms·
I was actually just thinking recently about eliminating unchecked null errors in my haXe code, went looking through the features and discussions, and came up wi
by chipsy 17y ago
I was actually just thinking recently about eliminating unchecked null errors in my haXe code, went looking through the features and discussions, and came up with two "today" solutions and one "proposed for the future". In light of how little Java seems to be doing to eliminate those errors, maybe they will interest:
-Right now it's possible to use the haXe Enum to implement a form of "Maybe" type: calling some "get" function returns the Maybe, and then you do a switch statement on it. From there the compiler forces you to cover all cases.
Caveat: Enum is quite a slow feature.
-I can force the "get" function to pass in handling code for null and non-null cases as arguments.
Caveat: Requires the handlers to be full functions, not just expressions, which is bulky and inflexible. This should be doable in Java too, but without inference, you might have to fight the type system more to get it right.
-Macros are proposed: Then I can turn my "get" function into a "get" macro that forces me to always provide the null handler.
Caveat: It's a bit more involved than a Maybe type, which would do the compile checks automatically.
Overall, I'm really happy with where haXe is going. It's growing some really useful features while remaining a cross-target language. If macros get in(hotly anticipated, but probably not soon) it'll be a very exciting time for the language.