查看完整版本 : Object Calisthenics - 9 steps to better software design today

fitcat07 2017-10-17 04:16 PM

Object Calisthenics - 9 steps to better software design today

[url]https://www.cs.helsinki.fi/u/luontola/tdd-2009/ext/ObjectCalisthenics.pdf[/url]

If you think it is crazy, see this:
[url]http://williamdurand.fr/2013/06/03/object-calisthenics/[/url]

Anyone following these rules?

Susan﹏汪汪 2017-10-17 05:58 PM

汪汪習慣按功能分拆散做不同methods

不過如果係需要追求效能的部分
無可避免一定會一堆nested for loop

fitcat07 2017-10-17 07:31 PM

[quote]原帖由 [i]Susan﹏汪汪[/i] 於 2017-10-17 05:58 PM 發表 [url=http://computer.discuss.com.hk/redirect.php?goto=findpost&pid=469513091&ptid=26997392][img]http://computer.discuss.com.hk/images/common/back.gif[/img][/url]
汪汪習慣按功能分拆散做不同methods

不過如果係需要追求效能的部分
無可避免一定會一堆nested for loop [/quote]
Those guidelines are target for software maintainability of large-scale systems. If performance is needed, they are not applicable. In my opinion, unless performance is deem necessary or is proved to be an issue by measurement tools, these guidelines should be followed as much as possible.

Susan﹏汪汪 2017-10-17 07:38 PM

[quote]原帖由 [i]fitcat07[/i] 於 2017-10-17 07:31 PM 發表 [url=http://www.discuss.com.hk/redirect.php?goto=findpost&pid=469517159&ptid=26997392][img]http://www.discuss.com.hk/images/common/back.gif[/img][/url]

Those guidelines are target for software maintainability of large-scale systems. If performance is needed, they are not applicable. In my opinion, unless performance is deem necessary or is proved t ... [/quote]
如果係講緊large scale system

佢的例子似乎有D細眉細眼

jasonchan35 2017-10-17 09:51 PM

[quote]原帖由 [i]fitcat07[/i] 於 2017-10-17 04:16 PM 發表 [url=http://computer.discuss.com.hk/redirect.php?goto=findpost&pid=469508422&ptid=26997392][img]http://computer.discuss.com.hk/images/common/back.gif[/img][/url]
[url=https://www.cs.helsinki.fi/u/luontola/tdd-2009/ext/ObjectCalisthenics.pdf]https://www.cs.helsinki.fi/u/luontola/tdd-2009/ext/ObjectCalisthenics.pdf[/url]

If you think it is crazy, see this:
[url=http://williamdurand.fr/2013/06/03/object-calisthenics/]http://williamdurand.fr/2013/06/03/object-calisthenics/[/url]

Anyone following these rule ... [/quote]

唔係好有用咁, 寫出黎既 code 當然要易睇, 所以寫得多都會有 sense
佢所謂既 rules, 一就用唔著, 一就正常人都知要咁做

form5 2017-10-17 09:53 PM

第一個我都會跟,vs refactor 好方便
Keep 住一個function 少過十行,C#用一個override string 包住,可以就甘print

第二個應該漏左enter 時check null,  假如用asp.net 係個controller 入面check login, 吾會用reposository,  用service 去check, repository 應該係data access layer

Getter/setter 係 GUI programming 上特别好用,
one dot per line 都會甘做,除左fluent functions

...

[[i] 本帖最後由 form5 於 2017-10-17 09:56 PM 編輯 [/i]]

煙民母親生賤種 2017-10-18 04:52 AM

[url=https://code.jquery.com/jquery-3.2.1.slim.min.js]https://code.jquery.com/jquery-3.2.1.slim.min.js[/url]
符合呀! 佢用左 1 行 ONLY! :fst_008:

[attach]7462724[/attach]

stupidsing 2017-10-18 05:52 PM

I write else for nearly every if......

同埋拆開 nested for 做細 method會易睇左咩?

用少 d mutable variables 係正經

assembly.jc 2017-10-22 10:26 PM

唔記得是否出自 Apply UML and Pattern 1st edition,好的程式設計,最終都會符合以下2個法則:
1. high cohesion (陰)
2. loose coupling (陽)
是為程式設計之「道」。

以此檢視這 9 條原則。
1. Only One Level Of Indentation Per Method,排版上容易閱讀,如果 indentation 好多層,確是可達到 isolation of complexity 的效果,但和以上這2 法則無關。

2. Don’t Use The ELSE Keyword,簡單的 case,用 else 比較方便。多層 else, else if,用polymorphism, Strategy pattern,確是比較容易維護和擴充。但和以上這2 法則無關。

3. Wrap All Primitives And Strings,OOP 本來就應這樣。

4. First Class Collections,符合high cohesion 原則。但似和 functional programming 原則相違, FP 鼓勵用 List, tuple, dictionary 結構結合 function 使用。

5. One Dot Per Line,依賴 1 個 class 好過 依賴 2 個 class,符合loose coupling的原則。

6. Don’t Abbreviate,如果  method 和 class 名稱太長,反映出設計可能有問題,或者負責的工作太多。這是好的建議,後者和 high cohesion有關。

7. Keep All Entities Small。coding style 問題,沒有固定的標準吧。

8, 9 No Classes With More Than Two Instance Variables 和 No Getters/Setters/Properties,把 high cohesion 原則具體化,相關的工作高度集中,Setter 基本就不需要? Instance variable 可減少至最多得 2 個?

[[i] 本帖最後由 assembly.jc 於 2017-10-23 01:37 AM 編輯 [/i]]

assembly.jc 2017-10-23 01:48 AM

X Window spec 的設計原則,spec 和 implementation 的原則好唔同:

Design principles section of
[url=https://en.wikipedia.org/wiki/X_Window_System_protocols_and_architecture]https://en.wikipedia.org/wiki/X_Window_System_protocols_and_architecture[/url]

From X Window System : core and extension protocols ([url=https://www.amazon.com/Window-System-Core-Extension-Protocols/dp/155558148X]https://www.amazon.com/Window-System-Core-Extension-Protocols/dp/155558148X[/url])

[[i] 本帖最後由 assembly.jc 於 2017-10-23 02:02 AM 編輯 [/i]]

tom.care 2017-10-26 08:12 AM

My 2 cents?
Gone too far.
Too much good things becomes unrealistic
Standard too high means there will be violations
頁: [1]
查看完整版本: Object Calisthenics - 9 steps to better software design today