軟體設計
下圖可以看到各種java 測試框架的source code行數
比喻成報紙的新聞頭條,名字要取的簡單又可以概括想要講的內容,detail再交給source code來執行,報紙由很多小文章所組成,每個文章短小精煉,如果直接用一長串的故事事實來寫,不會有人去讀
幾乎所有source code由上往下,由左往右讀
在每個函數和每個package,import之間用space隔開可以影響code的視覺外觀,讓讀者知道每個空格之後都是新的一個獨立的concept
相關的代碼應該要互相靠近不藥用註解相隔太遠
有時候想要trace一個function,裡面的variable卻是從其他function定義或甚至是其他class繼承過來的,但是明明只有這個function才用的到而已
Variables should be declared as close to their usage as possible
local variable should appear at the top of each function
Control variables for loops should usually be declared within the loop statement
把source file code切成兩半,public/private()
Instance variable should be declared at the top of class
The rule is not about placing public methods on the very top / bottom of a file Nope it’s just about not mixing public and private methods.
java–-top
c++ –-buttom
只要知道哪裡可以看到所有的instance variable就好不要零零散散