3 ms·
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
by elwell 6y ago
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).
- mxz3000 6y agoThat's a pattern I use in a lot of Typescript, it's pretty useful!
- genuine_smiles 6y agoWe’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.