Breaking up classes and methods into smaller units
Posted
by
micahhoover
on Programmers
See other posts from Programmers
or by micahhoover
Published on 2014-06-11T17:17:40Z
Indexed on
2014/06/11
21:38 UTC
Read the original article
Hit count: 253
During code reviews a couple devs have recommended I break up my methods into smaller methods.
Their justification was (1) increased readability and (2) the back trace that comes back from production showing the method name is more specific to the line of code that failed. There may have also been some colorful words about functional programming.
Additionally I think I may have failed an interview a while back because I didn't give an acceptable answer about when to break things up.
My inclination is that when I see a bunch of methods in a class or across a bunch of files, it isn't clear to me how they flow together, and how many times each one gets called. I don't really have a good feel for the linearity of it as quickly just by eye-balling it.
The other thing is a lot of people seem to place a premium of organization over content (e.g. 'Look at how organized my sock drawer is!' Me: 'Overall, I think I can get to my socks faster if you count the time it took to organize them').
Our business requirements are not very stable. I'm afraid that if the classes/methods are very granular it will take longer to refactor to requirement changes. I'm not sure how much of a factor this should be.
Anyway, computer science is part art / part science, but I'm not sure how much this applies to this issue.
© Programmers or respective owner