2 points · by andrewstuart · 8y ago · 4 comments
And I feel like I should break it up into smaller functions.
But the thing is, it's meant to be several hundred lines of sequential instructions. There's just a long sequence of things that need to happen at this point in my application.
Breaking it into functions would seem to be introducing unneeded complexity. After all - functions are there to be reused. And whenever you see a function you have to consider what places in the code might be using it. Whereas in this case, if I broke this code into functions, none of those functions would be re-used.... they would all be called in sequence.
Admittedly it is hard to navigate up and down this long function which does have logical sections to it. Maybe I should just bite the bullet and pull out each section into a separate function?
I dunno. It feels wrong to have a several hundred line function but it also seems wrong to break it up, thereby increasing complexity.
What do you think?
Also, assume that this big function breaks for some reason. Having sub functions will make it easier for you or anyone else maintaining the code to isolate it and track the source error in a much easier way.
So for me, functions are not just about re-usability, but also about maintenance and readability of code.
def function:
do_foo()
something = do_bar()
frobnicate(something)
than this: def function:
// do foo
lots
of
detailed
code
// do bar
lots
something = of
other
stuff
// frobnicate
...
At least it makes the dependencies and logical blocks of functionality more clear.The smaller thing: it's about how you interact with it in an editor, ide.
http://number-none.com/blow/john_carmack_on_inlined_code.htm...