User Tools

Site Tools


guides:programstyle:functions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
guides:programstyle:functions [2020/08/04 15:37] – [Function Length] wikiadminguides:programstyle:functions [2024/07/25 15:01] (current) – external edit 127.0.0.1
Line 57: Line 57:
 ===== Function Cohesion ===== ===== Function Cohesion =====
  
-===== The main function =====+There are two aspects of function cohesion:
  
 +   - The code in a function should perform a single well-defined task.
 +   - The code in a function should be at the same level of abstraction.
 +
 +In the first case, this may be a simple or very complex task but it is a single task.
 +
 +In the second case, the program should consist  of either high level (other function calls) or low level (computation, input, ...) actions.  High level routines should read like an algorithm.
 +
 +===== The main Function =====
 +
 +The main function for most advanced programs should read like an algorithm to solve the main problem.  It should not contain detailed code, but consist of a number of calls to functions.
 +
 +A single line main function is not acceptable.  
 +
 +
 +===== An Example ======
  
guides/programstyle/functions.1596555427.txt.gz · Last modified: 2024/07/25 15:01 (external edit)