The elements of programming style,好程式的要素
軟體工程經驗
本是Fortran語言時代的軟體工程經驗總結,感覺多數條目也適合使用任何語言開發專案。
條目
Write clearly - don’t be too clever 清晰是最重要的,不要耍聰明
Say waht you mean, simply and directly 詞要達意
Use library functions 不要重造輪子
Avoid temprorary variables 避免濫用臨時變數
Write clearly - don’t sacrifice clarity for “efficiency” 清晰性總是第一位的,比效能重要
Let the machine do the dirty work 又髒又累、繁瑣的工作讓機器做
Replace repetitive expressions by calls to a common function 程式碼複用、重構
Parenthesize to avoid ambiguity 使用括號消除歧義
Choos variable names that won’t be confused 選擇變數名稱
Avoid the Fortran arithmetic IF
Avoid unnecessary branches
Use the good freatures of a language; avoid the bad ones 擇善而用
Don’t use conditional braches as a substitute for a logical expression
Use the “telephone test” for readability 選用清晰的邏輯表達
Use DO-END and indenting to delimit groups of statements
Use IF-ELSE to emphasize that only one of two actions is to be performed
Used DO and DO-WHILE to emphasize the presence of loops
Make your programs read from top to bottom 保證程式從上至下閱讀,慎用GOTO
Use IF…ELSE IF…ELSE IF…ELSE… to implement multi-way branches
Use the fundamental control flow constructs 使用語言提供的本徵控制結構
Write first in an easy-to-understand pseudo-language’ then translate into whatever language you have to use 易於理解的虛擬碼
Avoid THEN-IF and null ELSE
Avoid ELSE GOTO and ELSE RETURN
Follow each decision as closely as possible with its associated action 將功能和語義相近的程式碼儘可能的放在一起
Use data arrays to avoid repetitive control sequences 使用迴圈簡化重複
Choose a data representation that makes the program simple 選擇和調整資料結構,以使程式簡單
Don’t stop with your first draft 第一個草稿不能用
Modularize. Use subroutines 模組化
Make the coupling between modules visible 模組耦合清晰
Each module should do one thing well 一次只做好一件事
Make sure eavery module hides something 資訊隱藏
Let the data structure the program 資料決定程式整體結構,以資料為中心
Don’t patch bad code - rewrite it 重寫爛程式碼
Write and test a big program in small pieces
Use recursive procedures for recursively-defined data structures
Test input for validity and plausibility 一定要檢查輸入
Make sure input cannot violate the limits of the program 檢查輸入在合理範圍內
Terminate input by end-of-file or marker, not by count
Identify bad input; recover if possible
Treat end of file condtions in a uniform manner
Make input easy to prepare and output self-explanatory
Use uniform input formats
Make input easy to proofread
Use free-form input when possible
Use sefl-indentifying input. Allow defaults. Echo both on output
Localize input and output in subroutines
Make sure all variables are initialized before use 保證所有變數使用前初始化
Don’t stop at one bug BUG多多
Use debugging compilers
Initialize contants with DATA statements or INITIAL attributes; initialize variables with executable code 顯式的初始化常量
Watch out for off-by-one errors 小心多一錯誤
Take care to branch the right way on equality 小心處理變數相等情形
Avoid mutiple exits from loops
Make sure your code “does nothing” gracefully
Test programs at their boundary values 測試程式碼邊界
Program defensively 防禦程式設計
10.0 times 0.1 is hardly ever 1.0
Don’t compare floating point numbers just for equality 避免比較兩個浮點數是否相等
Make it right before you make it faster 調優之前要保證程式碼正確
Keep it right when you make it faster 調優過程中要保證程式碼正確
Make it clear before you make it faster 調優過程中要保證程式碼清晰
Don’t sacrifice clarity for small gains in “efficiency” 不要為蠅頭小利犧牲清晰性
Let your compiler do the simple optimizations
Don’t strain to re-use code; reorganize instead 處處重構
Make sure special cases are truly special
Keep it simple to make it faster 優化過程中要保持簡單性
Don’t diddle code to make it faster - find a better algorithm 找一個更好的演算法
Instrument your program. Measure before making “efficiency” changes 測量是優化的基礎
Make sure comments and code agree 註釋避免驢脣不對馬嘴
Don’t just echo the code with comments - make every comment count
Don’t comment bad code - rewrite it 不註釋爛程式碼,重寫之
Use variable names that mean something 變數名字要選好,望文生義最好
Use statement labels that mean something
Format a program to help the reader understand it 美化程式碼
Indent to show the logical structure of a program 美化程式碼
Document your data layouts
Don’t over-comment 少說廢話
相關文章
- 好程式設計師web前端精講 web前端三要素程式設計師Web前端
- go 程式基本要素Go
- WPF style BasedOn base style
- "sideEffects": [ "dist/*", "esm/**/style/*", "lib/**/style/*", "*.less" ], 的作用是什麼IDE
- API(Application Programming Interface,應用程式程式設計介面)APIAPP程式設計
- C 語言程式構成要素
- Blocking ElementsBloC
- html中list-style-type與list-style的區別HTML
- 面向切面程式設計 ( Aspect Oriented Programming with Spring )程式設計Spring
- 本地開發好的 SAP Fiori Elements 應用,如何部署到 ABAP 伺服器上?伺服器
- vue 的 class 與 style 使用Vue
- [論文速覽] Separating Style and Content for Generalized Style TransferZed
- [Javascript] Refactor blocking style code to stream style for fetching the stream dataJavaScriptBloC
- GO語言————4.2 Go程式的基本結構和要素Go
- 小程式與Vue對比·class與style繫結Vue
- Wpf ComboBox style
- SAP Cloud Application Programming 程式設計模型(CAP)的設計準則CloudAPP程式設計模型
- 抓住這些要素,或許能做出一款好遊戲遊戲
- SAP Fiori Elements 概述
- 擴充套件01:程式碼風格/python規範style套件Python
- Programming with ISTAD and ENET
- Introduction to Systems Programming .
- EbookFoundation/free-programming-books:免費提供的中文程式設計書籍程式設計
- JavaScript style 屬性JavaScript
- vim Google style formatGoORM
- list-style-position
- 常見的Git 程式碼提交規範,feat、fix、style都是什麼意思?Git
- OOP物件導向程式設計(Object-Oriented Programming)概述OOP物件程式設計Object
- 《The Rust Programming language》程式碼練習(part 1 基礎部分)Rust
- 《The Rust Programming language》程式碼練習(part 2 進階部分)Rust
- 《The Rust Programming language》程式碼練習(part 3 簡單web )RustWeb
- 強制修改CSS的屬性styleCSS
- 十二要素
- 前端進階之養成一個良好的程式碼風格--JavaScript standard style前端JavaScript
- CS 551 Systems Programming
- Programming languages Domain summaryAI
- SAP Fiori Elements controller extension 的載入原理Controller
- style attribute 'attr/progressDrawable ' not find