Hacker News new | past | comments | ask | show | jobs | submit login

In Clojure, for functions that will probably have more than a couple args, I like to pass a map, then destructure it by its keys in the function definition. Two benefits are: you don't need to remember the order of args, and it makes refactoring easier in cases where you are simply adding a new optional arg (you don't need to update all the old calls of that function if they aren't using the new option).



That's a pattern I use in a lot of Typescript, it's pretty useful!


We’ve got to write argument names twice when we do it in typescript though:

  function foo({ bar }: { bar: string }) {
Still a great pattern, but I’d probably use it a lot more if I only had to write the variable names once.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: