- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 221字
- 2021-07-02 23:54:31
Best practices in function definition
There are proven best practices for function and method definition provided by amazing software engineering resources, such as Clean Code: A Handbook of Agile Software Craftsmanship, by Robert C. Martin, Code Complete: A Practical Handbook of Software Construction, Second Edition, by Steve McConnell, and Coding Horror (https://blog.codinghorror.com/code-smells/), that we can summarize as follows:
- Try not to exceed 8-10 lines of code in each function as shorter functions or methods are easier to read, understand, and maintain.
- Keep the number of parameters minimal because the more parameters a function has, the more complex it is.
- Functions should have at least one parameter and at least one return value.
- Avoid using type names in function names since they are going to be redundant.
- Aim for one and only one functionality in a function.
- Name a function or method in a way that it describes its functionality properly and is easy to understand.
- Name functions and methods consistently. For instance, if we have a connect function, we can have a disconnect one.
- Write functions to solve the current problem and generalize it when needed. Try to avoid what-if scenarios as probably You Aren't Going to Need It (YAGNI).
It is important to follow these best practices. After all, we are talking about FP and you know, functions are important!
推薦閱讀
- 數據庫應用實戰
- 云計算環境下的信息資源集成與服務
- Python數據分析入門:從數據獲取到可視化
- Modern Programming: Object Oriented Programming and Best Practices
- 圖解機器學習算法
- WS-BPEL 2.0 Beginner's Guide
- 大數據架構商業之路:從業務需求到技術方案
- SQL應用及誤區分析
- 科研統計思維與方法:SPSS實戰
- Hadoop大數據開發案例教程與項目實戰(在線實驗+在線自測)
- Visual FoxPro數據庫技術基礎
- Unity Game Development Blueprints
- 大數據測試技術:數據采集、分析與測試實踐(在線實驗+在線自測)
- 大數據技術體系詳解:原理、架構與實踐
- 深入理解Flink:實時大數據處理實踐