Hacker News new | ask | show | jobs
by sachinjoseph 2227 days ago
The use use of '=' here scares me:

   function add2(x: Int, y: Int): Int {
       return x + y;
   }
   
   add2(2, 3)     //5
   add2(x=2, y=3) //5
   add2(y=2, 5)   //7
The language already supports '=' operator for assignment of variables in the current scope, so should you use the same operator for denoting value assignment formal parameters in a function call? This can lead to a lot of confusion between variables in the scope and formal parameter names in a function that is called from the current scope.
4 comments

Python, one of the most popular languages, uses this syntax, so I'm guessing the vast majority of people don't find it scary (I certainly don't).
This seems like a non issue to me and as tomp said, is already done in popular languages without problems. The third example (keyword arguments before positional) does seem a bit odd though, as interleaving positional and keyword arguments seems like a recipe for confusion, but using = for keyword arguments doesn’t seem like a problem to me.
This and a few other parts seem to be inspired by StandardML / Ocaml

https://learnxinyminutes.com/docs/standard-ml/

I love this feature - calling named parameters is (for me) a glaring omission from Javascript (and surprisingly Typescript), I know you can define an object argument, but not many do and that’s not very elegant.