by ssnri · 2y ago · 0 comments
When I write JS (not TS), I prefer as much as possible to use destructuring in every function definition. Named keyword arguments.
Try to change the name of something as little as possible even as it gets passed around. It’s more powerful than a type system in some ways. Not always doable, but just try it sometime; it’s fun.
I call it nominative programming.
function greet(greeting, name) {
return `${greeting} ${name}`
}
const greetWithGreetingHello = greet('hello')
greetWithGreetingHello('sally')
And this should work with named arguments too. function greet({greeting, name}) {
...
}
const greetWithGreetingHello = greet({greeting: 'hello'})
greetWithGreetingHello({name: 'sally'})
With named params, curried functions can be read more naturally too.greetWithGreetingHelloAndWith({name: 'sally'}).
"and with name sally"
A javascript object is like an S-expression if you squint. The subtree nesting is messier.