This was actually bothering me from the day I learned haxe.
I can think of only three reasons why nonspecified optional arguments should turn to nulls:
- It’s already here and works.
- Ocaml does this.
Case 1 you can do manually and others are not really good reasons in my opinion.
Why do that:
- Speed. It kinda sucks that you cannot use functions with optional arguments inside tight loops, because there is a penalty for every optional argument. And the penalty is there even if you specify all of the arguments.
- It’s not hard to do (maybe leave a compiler switch/metadata to enable current behaviour for occasional extern-to-haxe calls in js/lua). Probably even easier than how it’s done currently.
- Will allow to add optional arguments to extern functions.
- There is basically no reason why compiled language should do it differently.
You can already do this with two functions (one of them being inline and have optional args while other is not) but this will require you to either write two functions where one is needed or carry a macro everywhere. And it will not work with library functions that do not follow this convention, unless you are willing to go and edit library code. There may also be problems with reflection.