The Dao of Immutability – JavaScript Scene – Medium

The dao of immutability: The way of the functional programmer  #ReactJS #JavaScript

  • Therefore the wise think before acting, and act only when the thinking is done.If you try to perform effects and logic at the same time, you may create hidden side effects which cause bugs in the logic.
  • A tree cannot grow without water.
  • The foolish create special tools for each new creation.Type-specific functions can’t be reused for data of a different type.
  • Wise programmers lift functions to work on many data types, or wrap data to make it look like what the function is expecting.
  • I have not reproduced the illustration because I don’t believe I could do it justice.

I was wandering the archives of an old library, and found a dark tunnel that led to the chamber of computation. There I found a scroll that seemed to have fallen on the floor, forgotten. The scroll…

@ReactiveConf: The dao of immutability: The way of the functional programmer #ReactJS #JavaScript

I was wandering the archives of an old library, and found a dark tunnel that led to the chamber of computation. There I found a scroll that seemed to have fallen on the floor, forgotten.

The scroll was encased in a dusty steel tube and labeled: “From the archives of The Church of Lambda.”

A master programmer and his apprentice sat in Turing meditation, contemplating the Lambda. The apprentice looked at the master and asked, “Master, you tell me to simplify, but programs are complex. Frameworks ease the work of creation by removing hard choices. Which is better, a class or a framework?”

The master programmer looked at his apprentice and asked, “did you not read the teachings of wise master Carmack?”, quoting…

“But master,” the apprentice started — but the master interrupted, asking:

“Is it not true that the word for ‘not functional’ is ‘dysfunctional’?”

On the back of the sheet was an index that seemed to refer to many books in the chamber of computation. I peeked inside the books, but they were filled with big words I did not understand, so I put them back and continued to read the scroll. I noticed that the margins of the index were filled with short commentary, which I will reproduce here, faithfully, along with the writing from the scroll:

Immutability: The true constant is change. Mutation hides change. Hidden change manifests chaos. Therefore, the wise embrace history.

If you have a dollar, and I give you another dollar, it does not change the fact that a moment ago you only had one dollar, and now you have two. Mutation attempts to erase history, but history cannot be truly erased. When the past is not preserved, it will come back to haunt you, manifesting as bugs in the program.

Separation: Logic is thought. Effects are action. Therefore the wise think before acting, and act only when the thinking is done.

If you try to perform effects and logic at the same time, you may create hidden side effects which cause bugs in the logic. Keep functions small. Do one thing at a time, and do it well.

Composition: All things in nature work in harmony. A tree cannot grow without water. A bird cannot fly without air. Therefore the wise mix ingredients together to make their soup taste better.

Plan for composition. Write functions whose outputs will naturally work as inputs to many other functions. Keep function signatures as simple as possible.

Conservation: Time is precious, and effort takes time. Therefore the wise reuse their tools as much as they can. The foolish create special tools for each new creation.

Type-specific functions can’t be reused for data of a different type. Wise programmers lift functions to work on many data types, or wrap data to make it look like what the function is expecting. Lists and items make great universal abstractions.

Flow: still waters are unsafe to drink. Food left alone will rot. The wise prosper because they let things flow.

[Editor’s note: The only illustration on the scroll was a row of different-looking ducks floating down a stream just above this verse. I have not reproduced the illustration because I don’t believe I could do it justice. Curiously, it was captioned:]

[Editor’s note: The scroll ended with this final verse, which had no commentary:]

The Dao of Immutability – JavaScript Scene – Medium