by mikehaggard · 11y ago · 0 comments
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)