- 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!
推薦閱讀
- 企業(yè)數(shù)字化創(chuàng)新引擎:企業(yè)級(jí)PaaS平臺(tái)HZERO
- 數(shù)據(jù)產(chǎn)品經(jīng)理高效學(xué)習(xí)手冊(cè):產(chǎn)品設(shè)計(jì)、技術(shù)常識(shí)與機(jī)器學(xué)習(xí)
- 云計(jì)算環(huán)境下的信息資源集成與服務(wù)
- Oracle RAC 11g實(shí)戰(zhàn)指南
- SQL查詢:從入門到實(shí)踐(第4版)
- 數(shù)據(jù)庫(kù)系統(tǒng)原理及應(yīng)用教程(第4版)
- Oracle高性能自動(dòng)化運(yùn)維
- 大話Oracle Grid:云時(shí)代的RAC
- 大數(shù)據(jù)架構(gòu)和算法實(shí)現(xiàn)之路:電商系統(tǒng)的技術(shù)實(shí)戰(zhàn)
- Power BI智能數(shù)據(jù)分析與可視化從入門到精通
- 智慧的云計(jì)算
- 計(jì)算機(jī)組裝與維護(hù)(微課版)
- 計(jì)算機(jī)視覺
- Oracle 11g+ASP.NET數(shù)據(jù)庫(kù)系統(tǒng)開發(fā)案例教程
- 大數(shù)據(jù)與機(jī)器學(xué)習(xí):實(shí)踐方法與行業(yè)案例