Grokking Simplicity FP CH4 ~ CH5 #2
Yo0GuitarIT
started this conversation in
General
Replies: 1 comment
-
👍🏻 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
《簡約的軟體開發思維:用 Functional Programming 重構程式》
筆記章節
筆記資訊
回顧
Side Effect(副作用)
Actions(有副作用)
sendEmail()
saveUserDB()
getCurrentTime()
Calculations(純函數)
sum([1,2,3])
string_length("hello")
Data(資料)
{ "name": "Eric" }
[1, 2, 3]
核心觀念
Ch4:抽離 Action 中的 Calculation
常見觀念 Q&A
Q1. 程式碼越多是好事嗎?
Q2. FP 僅關心重用和測試?
Q3. 抽出來的計算能獨立使用重要嗎?
Q4. FP 強調不可變,為何仍會修改變數?
抽離 Calculation 的步驟
Note:參數與回傳值皆應保持不可變
概念總結
Ch5:改良 Actions 的設計
常見觀念 Q&A
Q1. 為什麼程式碼越寫越多?
Q2. 每次複製購物車陣列不會效能差?
原則:最小化隱式輸入與輸出
設計原則:拆解就是力量
函式的拆解優勢:
Calculation 函式分類(有助後續分層)
小結
Q&A
1. 純函式、副作用與可測試性
2. 關於 Function 拆解
3. FP(Functional Programming)與 OOP(Object-Oriented Programming)的比較
Functional Programming(FP):
addToCart(item)
、calculateTax(rate)
。Object-Oriented Programming(OOP):
Cart.add()
。🌟 混合式架構:
4. 常見困擾與現場經驗
命名與可讀性:
Fn 包 Fn
+pipe
很容易讓接手人迷失。維護與可讀性挑戰:
handleSave()
裡面塞一堆條件)也是常見問題。🔍 延伸閱讀與資源
🤔 討論總結
💬 金句摘錄
Beta Was this translation helpful? Give feedback.
All reactions