4 ms·
Oh, I’m huge on doing the opposite of this. When I write JS (not TS), I prefer as much as possible to use destructuring in every function definition. Named ke
by ssnri 3y ago
Oh, I’m huge on doing the opposite of this.
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.
- valty 3y agoI feel like JS needs auto-currying. 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"
- ssnri 3y agothe key idea for me was realizing that variables are really 3 things: value, type, and identifier. A javascript object is like an S-expression if you squint. The subtree nesting is messier.
- veqq 3y agoI'm responding to an unrelated old comment of yours about questioning all assumptions. In Forth, Chuck Moore said local vars are dangerous. Rather, everything should be a global. (However multithreaded Forth implementations do require locals.)