簡評二

制作一个苦力

用swift寫一個JSON parse,想學寫compiler果時可以睇返。

MVVM 介绍

VM stand for View Model. The idea is to improve MVC by adding a layer (View Model) between Controller and Model.
View Model handles all presnetation logic, such as format data in Model for View. In MVC, we put the data formating code in Controller. MVVM make the controller slimmer.

We should put all code which cannot be reused in Controller. I thought data format code usually is not reusabile, it makes sense to put the logic in Controller. When the system grow and become more complex, we can apply MVVM to break down the controller is small pieces. So the code base will be cleaner.

Pros of MVVM:

  • easy to migrate from MVC by adding view models
    • we can migrate progressively
  • view model is testable
    • in most cases, controller is not worth to write automated test
  • easier to bind logic, as controller is smaller

I have no experience on MVVM. I need to find some example to support my thought

Comment

Aug 27, 2018:

  • 文中有一個assumption,view controller同view係requirement上tightly coupled
    • 唔會有一個controller對應幾個view嘅存在,但係MVC嘅design本身就係想做到更換view而唔洗轉controller。
    • 唔肯定係作者理解錯,定係MVVM真係咁設計
  • MVC -> MVVM
    • 將model嘅data format logic搬去view model
    • Controller依然存在,但係就簡單好多,都係一D直接嘅data passing

iOS APP 架构漫谈

“How to manage the information flow” is the problem front-end architecture pattern want to solve. I can see the shadow of MVC and redux from the examples.

Comment

Aug 27, 2018:
A nice introduction for information flow concept.

以下無需重讀

It give some guideline on naming functions and variables.

  • No short form unless it is common term
    • URL, HTTP is acceptable
    • Need to have a consensus on “Common Terms” with in a team
  • Use Will, Did and Should prefix for naming function with specific purpose
    • Will is the hook run before some action, such as WillSendMessage = function(){...}.
    • Did is the hook run after some action, such as DidSendMessage = function(){...}.
    • Should determine whether some action should be perform or not. It always return a boolean. Such as ShouldSendMessage = function(context){...}
  • Put data description before data type
    • titleLabel is better than labelTitle

I don’t argee with the Get function prefix part outside the context of Objective C.

1
2
3
4
5
6
7
8
9
10
11
Class foo {
function get_value($query, &$value){
...
$value = "some value";
return $is_success;
}
function value(){
...
return "some value";
}
}

get_value() put the return value into input parameter by reference. value() return the value directly.
There are three drawbacks:

  • get_value have 2 entry point
    • Try to avoid function’s “side effect” by avoid using pass by reference
    • Function should return value using return, it make the code easier to understand
    • If we want to detect error, we should use throw instead of return some falsy value.
  • It is confusing to determine value is a function or object field
    • This may be ok for Objective C, as function calling and data accessing have different syntax
      I prefer to use get_value() for object function and value for object data.

子类

If two class have few common method, we should not use sub-class pattern. If two class have the same interface, but different implementation, there are better design pattern than sub-class. In weak typing language, we can use duck typing directly.

Objective C is a strong typing language. The article provide 4 design patterns:

Delegate

A delegate object is injected, which is a specific implementation of the method. What we need to do is only keep the same function interface.

Configuration

We provide an interface to let user configurate the implementation. It is perfect for the language with first class function. We only need to pass the implementation, instead of implementation lots of sub class.

1
2
3
4
5
6
7
8
9
10
11
12
13
// Suppose we have a class "MessageSender" to send a message to different channel
var sender = new MessageSender();
// We don't need to create a set of subclass "SlackSender", "MessagerSender" and "WhatsAppSender"
// We only need to pass the implementation to the object like this:
sender.config(function sendToSlack(){
...
})
sender.config(function sendToMessager(){
...
})
sender.config(function sendToWhatsApp(){
...
})

Categories and Combinations

I think these two patterns are specific for Objective C. In most of the modern language, we have duck typing. We can replace these pattern with duck typing.

Comment

May 15, 2018:
Just some Basic design pattern, don’t need to revisit

更轻量的 View Controllers

文中帶出 MVCS 嘅 concept 去改MVC,S可以係 Store 或 Service 嘅簡寫,都係指同一樣野。其實就係將 Model 嘅 database 或 network logic 放去 Store/Service object,令個Controller 可以精簡一D。

Comment

May 15, 2018:
例子係Objective C,唔係咁岩睇。拆database logic做一個driver class係普通野,篇文冇必要再睇。

数据的秘密(上)- 为什么要关注数据 数据的秘密(下)- 如何分析数据

Data 己經講同爛。簡單黎講,Data係一種唔可以缺少嘅System Feedback。冇左Data,好難去 debug, optimize 同做 tuning

比較有意思嘅一點係,Data 要易睇同易分析。好多時係data extract insight,要日復日嘅觀察同多方面嘅分析。如果每日都要搞一大輪野先睇到,好容易會miss左D野。

Comment

May 15, 2018:

  • Monitor both server and user data
    佢所講嘅道理我都明白,反而係佢講果D事例,有時間值得慢慢研究
  • 稻盛和夫用數據挽救左日航
  • 林彪係1948年嘅遼西,透過戰爭嘅日常數據,估到敵方野戰司令部嘅位置,贏得戰事

《引爆点》读书心得

流行理論可以分做三個因素。

內部因素

件野本身要好。「好」嘅定義可以係得意,幫到用戶解決問題

可控因素

要先揾到關鍵人物做用戶,等佢地幫你宣傳。可以分為内行,聯系人員同推銷員。文中冇解釋,搞到我有D想睇。

不可控因素

環境因素。如時機,行業發展。

以下無需重讀

应该如何管理密码 - 我的密码管理心得

唔重要嘅account可以直接用third party tool去管理,避免repeated password attack。可以用facebook/google login就用。

Comment

May 15, 2018
我都subscribe左1Passwrd

Javscript library detector

如題。對分析人地唧網站好有用。