3 ms·
I try hard to stick to these "rules" for determining method/function size. 1) Keep methods/functions shorter than one "screenfull". 2) If I code the same or s
by njharman 18y ago
I try hard to stick to these "rules" for determining method/function size.
1) Keep methods/functions shorter than one "screenfull".
2) If I code the same or substantially the same logic twice, it gets extracted to it's own method/function. [I also do the opposite, if method/function is used once I remove it and inline logic.]
3) Logic extraneous to the problem at hand gets extracted into method/function/language feature such as macro's or decorators if it takes more than a couple lines. (logging, safely opening a file, wrapping in a try/catch, etc)
Less often:
1) Logic that needs it's own unit test gets extracted.
2) If a comment precedes a block of code saying what it does. extract the code, name method/function after the comment, delete the comment.
# load the exception records from exception file
bla bla bla for 10 lines...
exceptions = load_exception_records_from_file(fh)