看了一堆解釋就是看不懂 Design Pattern? 你可能看了好幾個教學,但就是覺得好像抓不到某個 Design Pattern 的要領?這系列文應該可以幫助到你。 那麼這系列會有什麼不同呢? 通常 Design Pattern 都會用 Class diagram 來描述結構,然後以文字來輔助說明。這系列文我會直接用 type system 來做說明。 Type System 是什麼? Type System 可以算是一種邏輯表示方法。跟在學校學的邏輯符號不一樣的地方是,它更靠近程式語言,所以他同時有邏輯符號的嚴謹性跟程式語言的易用性。另外現在很多程式語言都有支援不錯的 type system,不過語法上可能會有些差異。為了方便理解,我也會附上 TypeScript 的範例來比較。
10/3/2021本文會試著用最簡單的方式來幫助你入門 functional programming。 什麼是 Functional Programming 其實定義有很多種。簡單的可以是「只要有用到 first class function 就算」,而困難的可以到「必須使用 mathematical function 才算」。而這邊我們採用的定義是: 用到 first class function 盡量避免 side effect 什麼是 First Class Function? 原本的 JS function 都是這麼定義的
8/1/2021前一陣子看到 PTT Soft Job 上面有人寫了一篇文描述怎麼用 Strategy Pattern 來 refactor 某段 code,我在這邊為了方便閱讀先節錄一部分: from https://www.ptt.cc/bbs/Soft_Job/M.1607866053.A.4BB.html public double shippingFee(String shipper, double length, double width, double height, double weight) { if (shipper.equals("black cat")) { return // some calculation } else if (shipper.equals("hsinchu")) { return // some calculation } else if (shipper.equals("post office")) {
1/16/2021First, let's start with what do we mean by being pythonic. By googling this term, here is the list of top 3 links: https://docs.python-guide.org/writing/style/ https://towardsdatascience.com/how-to-be-pythonic-and-why-you-should-care-188d63a5037e https://hub.packtpub.com/write-python-code-or-pythonic-code/ Have List Comprehension From those links, I think it's fare to say using list comprehension is a big part of being pythonic. Especially this one is mentioned in all three links.
7/25/2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up