Function call is a hidden goto

I’ve recently had two instances of studying some innocent looking code, only to realize it’s riddled with something you are ordinarily actually recommended to do. “If a function is too long, separate blocks of code into separate functions!”

Yes, that’s all nice. This rule rocks, but not when you go and insanely apply it to rather short functions.

Remember: most IDEs don’t allow easy browser-style navigation: click on a symbol name, read, then go back. This means reading complex code, spread over several functions spanning hundreds of lines of code if you look from top to the bottom… this is horrifying, and studying that code is near impossible.

If goto is considered harmful, don’t ignore the fact that function call is a hidden goto; in some cases, a wolf in sheep’s clothing.

Now, if I tell you one of the instances was some (supposedly relatively simple) sample code by a well known software company…

Image source: xkcd


via blog.vucica.net

Leave a Reply

Your email address will not be published.

 

What is 10 + 6 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

This site uses Akismet to reduce spam. Learn how your comment data is processed.