Hacker News new | ask | show | jobs
by Leftium 1056 days ago
FP is a way of thinking, which FP languages give nice features/syntax for. You can do non-FP style programming with an FP language.

In fact, many FP language features have been borrowed by non-FP languages to the point people don't consider them "FP" anymore[0]. (Like JS `.map()` and `.reduce()`. Even Excel macros now support first-class functions[1].)

Three features that would make FP thinking in JS easier:

1. immutable tuples and records[2]

2. pipe operator[3]

3. pattern matching[4]

Major epiphany: According to Grokking Simplicity[5], good functional programming isn't about avoiding impure functions; instead it's about giving extra care to them. Impure functions depend on the time they are called, so they are the most difficult to get right. In the end, the purpose of all software is to cause some type of mutation/effect (flip pixels on a screen, save bits to storage, send email, etc).

"Functional Core, Imperative Shell"[6] is probably the most useful FP concept. It is about pushing mutation/errors/impure functions to the outer edges of your code, so the inner code can focus on the "happy path." Complex business logic lives in the inner core; the outer shell is often simple/branchless so unit tests aren't even needed.

[0]: https://hw.leftium.com/#/item/21280429

[1]: https://hw.leftium.com/#/item/26900419

[2]: https://hw.leftium.com/#/item/23924933

[3]: https://hw.leftium.com/#/item/34454184

[4]: https://hw.leftium.com/#/item/16921652

[5]: https://www.manning.com/books/grokking-simplicity

[6]: https://hw.leftium.com/#/item/18043058