官术网_书友最值得收藏!

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!

主站蜘蛛池模板: 兴安县| 佳木斯市| 嘉兴市| 中牟县| 四子王旗| 桦甸市| 绵阳市| 武清区| 偃师市| 东兰县| 荆门市| 平果县| 南华县| 新乐市| 外汇| 龙江县| 扶沟县| 西畴县| 新宁县| 阳西县| 宜昌市| 沈丘县| 达拉特旗| 尼勒克县| 七台河市| 普定县| 武城县| 三门县| 河津市| 湟源县| 大新县| 额济纳旗| 宁南县| 扎鲁特旗| 盐津县| 河东区| 贵港市| 融水| 双峰县| 黔西县| 澳门|