|
|
|
|
|
by mikehaggard
4065 days ago
|
|
>setting thresholds on method / class sizes seems quite arbitrary and potentially harmful. Splitting a method into n different ones, none of which is called more than once is setting up the code for opportunistic reuse and obscures it's true function. Sometimes, but in general I don't agree. If the functions are made private and giving appropriate names than it's really a way of self-documenting code, which helps. Suppose you have: some_function() {
// Calculate interest
// 100 lines of code
// Apply tax
// 120 lines of code
// Store results
// 30 lines of code
}
Then the need to have those "banner comments" there already indicate it might be a good idea to decompose the function into: some_function() {
calculate_interest(...);
apply_tax(...);
store_results(...);
}
It's not just about reuse, but about documenting what each section of code does, and about limiting interactions between arbitrary sets of variables. Functions are create boundaries (assuming they don't intensively use global variables or class instance variables when part of a class) |
|