Ray Shih

@rayshih

Joined on May 11, 2020

  • 看了一堆解釋就是看不懂 Design Pattern? 你可能看了好幾個教學,但就是覺得好像抓不到某個 Design Pattern 的要領?這系列文應該可以幫助到你。 那麼這系列會有什麼不同呢? 通常 Design Pattern 都會用 Class diagram 來描述結構,然後以文字來輔助說明。這系列文我會直接用 type system 來做說明。 Type System 是什麼? Type System 可以算是一種邏輯表示方法。跟在學校學的邏輯符號不一樣的地方是,它更靠近程式語言,所以他同時有邏輯符號的嚴謹性跟程式語言的易用性。另外現在很多程式語言都有支援不錯的 type system,不過語法上可能會有些差異。為了方便理解,我也會附上 TypeScript 的範例來比較。
     Like 2 Bookmark
  • 我在寫一篇入門教學文時,想到幾乎沒有人在問是不是學會 OOP 了,但好像有不少人不知道怎麼入門 FP。於是就在我的 twitter 跟 facebook f2e.tw group 裡面問了這個問題「你們怎麼驗證一個人會不會 FP 了?」而大家的回答都滿有趣的。這邊就讓我來收集分類一下答案:(由簡單到難) 注意:以下只是列出所有的提到的答案,除了 pure function 跟 first class function 以外都可以直接忽略。 Pure function Side effect First class function
     Like 3 Bookmark
  • 本文會試著用最簡單的方式來幫助你入門 functional programming。 什麼是 Functional Programming 其實定義有很多種。簡單的可以是「只要有用到 first class function 就算」,而困難的可以到「必須使用 mathematical function 才算」。而這邊我們採用的定義是: 用到 first class function 盡量避免 side effect 什麼是 First Class Function? 原本的 JS function 都是這麼定義的
     Like 1 Bookmark
  • 前一陣子看到 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")) {
     Like  Bookmark
  • First, 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.
     Like  Bookmark
  • 最近有稍微跟幾位不同的朋友討論到相關的問題。這些問題本質上都是在探討怎麼讓程式碼更好維護,而其中一個問題是命名方法。我的看法是: 命名很重要,但是可能沒有你想像中的重要 問題的核心 Naming 跟 Cache invalidation 是 Computer Science 最大的兩個問題 相信大家都有多少聽過這句話,問題的核心是:怎麼用最少的資源來做最多的計算,其中資源包含了維護成本。那麼命名在這個命題中是扮演了怎麼樣的角色呢?
     Like  Bookmark