Description
Null safety is an optional feature of the Haxe compiler which enforces compile-time checking of nullable values.
By implementing null safety throughout HaxeFlixel, we can greatly reduce the frequency of crashes and other errors. This can be done using the @:nullSafety
annotation at the top of each class, and can be done incrementally until every class in the library is compliant.
This would not break existing code which has null safety enabled, but it would:
- Improve documentation by informing users which variables are
Null
-able (such asFlxG.sound.music
). - Reduce the incidence of certain crashes within the engine by guaranteeing they are caught and handled.
- Improve the compatibility with other code where null safety is enabled.
As an example of the last case, I have started to enable null safety in Funkin', and have had to create blocks of code where null safety is not enabled in several places, simply because Flixel itself regularly neglects to use Null<T>
for nullable values (again, trying to set FlxG.sound.music = null
makes the compiler complain until you specifically exclude that line).
One major obstacle to implementing null safety is that null safety is not necessarily finalized (see this issue or any of these issues). Overall though, I would like to see it become a long-term goal of the engine, especially since it can be done in a non-breaking manner in most cases.