|
|
|
Ask HN: How do you deal with 2000 line functions?
|
|
26 points
by pinkunicorn
3808 days ago
|
|
I'm working with an archaic code base and I'm stuck at trying to add new business logic into a 2000 line function that is absolutely crappily written with nothing but if() conditions in it. Given such a scenario, how do I go about adding a new functionality to this mess? Should I tell my manager that the function needs to be refactored and take time to refactor it? Edit: Removed offensive word |
|
2. Read the function a few times to get a sense of what it's doing.
3. Break the function into blocks of statements that are performing a related task.
4. Factor those out into smaller functions.
5. Recursively repeat 3-5 until you're satisfied with the new functions' line count.
> Should I tell my manager that the function needs to be refactored and take time to refactor it?
It's absolutely worth mentioning. Time estimations are one of the harder tasks of Software Engineering. Being up front with your manager can help better set expectations.