3 ms·
Agree, especially with having as much part of the code as pure functions. I think where functional programming really shines is in combination with a good type
by mejutoco 4y ago
Agree, especially with having as much part of the code as pure functions.
I think where functional programming really shines is in combination with a good type system, that can enforce those restrictions. In languages like js I find it not so useful (even if using map, filter, etc.) because I have no guarantees that there is a hack somewhere in the function that I did not see.
When there are a lot of pure functions the cognitive load is reduced so much I can use the "extra capacity" to focus on the task.
- gizmo 4y agoIn Javascript Object.freeze() and Object.seal() are wonderful to prevent accidental mutation.
- mejutoco 4y agoI did not know that. Another one is const to declare simple variables. There are some features, I agree. But how do I declare that a function returns a specific type and have it enforced? IMO, only by switching to Typescript or similar.
- gizmo 4y agoVSCode can enforce return types with jsdoc annotations, even when using plain javascript. VSCode uses typescript internally for all type inference, so you get that for free. Type inference works flawlessly 95% of the time, even for iterators/generators/inheritance/containers.