関数型Pythonアンチパターン
https://pycon.jp/2020/timetable/?id=203810
https://speakerdeck.com/ukyo/guan-shu-xing-pythonantipatan
#PyCon_JP_2020
関数型かつPythonic
トークでは関数型かつunPythonicを紹介 (slide=4)
関数型 (slide=5)
状態変化を排除
高階関数
Pythonic (slide=6) ※ただしお気持ち
Pythonの言語機能にマッチする
Pythonのコミュニティの価値観によりマッチする
まとめ (slide=47)
関数型としてC#のLINQの例 (slide=9)
Where, Select, Average
-> Python組み込み関数のmap, filterを重ねる(slide=10)と読みづらい
アンチパターン
1. 長い式を連ねる
-> 式を区切り、名付ける
2. map/filterを使う
『Pythonハッカーガイドブック』(第8章)
Pythonicの観点では、Python 組み込み関数 filterより内包表記 (slide=25)
内包表記のほうがちょっと速い https://stackoverflow.com/questions/1247486/list-comprehension-vs-map
Guidoさん、The fate of reduce() in Python 3000
functools.partialと組み合わせるのに限ってmap/filter
3. 内包/reduceを乱用する
-> ループを書き、隠蔽する
関数の中ではループを書いてもいい。状態変化を外から見えなくする
関数的プログラミング(On Lisp 第3章)
functools.reduce
Appendixに 4.クロージャを濫用する
-> オブジェクトと使い分ける
IMO:Pythonにパイプライン演算子がない(slide=17)が、作るトークがあった:Demystifying Python's Internals: Diving into CPython by implementing a pipe operator
https://www.youtube.com/watch?v=mk0qJA2y-8A