You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
891 B
23 lines
891 B
|
|
Writing good methods/functions:
|
|
* Naming
|
|
* Give descriptive names that say exactly what the routine does (usually verb-noun)
|
|
* The name should include or imply the return type
|
|
* Lines of code
|
|
* Functions over a couple hundred lines of code tend to be more error-prone
|
|
* Otherwise, no hard constraints on method length - whatever is natural for the situation
|
|
* Parameters
|
|
* Use parameter order consistently among different functions
|
|
* Document assumptions on parameters
|
|
* Document units
|
|
* Document zero-based-counting vs one-based-counting if not obvious
|
|
* Error handling
|
|
* Check values of input parameters
|
|
* Use assertions to check for bugs. Use error handling to check for bad input.
|
|
* Techniques for error handling:
|
|
* Return null or neutral value
|
|
* Print or log the error and continue execution
|
|
* Throw an exception/error
|
|
* Terminate the program
|
|
|