Maybe it's time to start substituting optional arguments at call-site

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:

  1. Maybe there is a library in javascript world which will call you function expecting exactly this behaviour.
  2. It’s already here and works.
  3. Ocaml does this.

Case 1 you can do manually and others are not really good reasons in my opinion.
Why do that:

  1. 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.
  2. 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.
  3. Will allow to add optional arguments to extern functions.
  4. 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.

1 Like

Personally I tend to agree, but I think the github issue tracker is a better place to raise such a matter - or perhaps a haxe evolution proposal.

1 Like

Yeah, but github does not want to register me so that’s why I’m writing everything here. And as far as I’ve noticed for simple enhancements like that compiler maintainers do not generally need to make a proposal, so someone could just pretend it was their idea all along and do it.