Hacker News new | ask | show | jobs
by jpittis 2542 days ago
> I typically find it very difficult to understand complex functions

It seems to me like "complex" and "ability to understand" mean the same thing, so this phrase doesn't have much meaning.

It's difficult to define "ability to understand" / "complex" without using either of those words in the definition. For example, you mention lines of code, nesting and multiple concepts.

I tend to agree with your examples, however not necessarily the lines of code. I've seen single large functions that represent an algorithm in a way that's easier to understand than the implementation that breaks it up into tens of little functions. It made liberal use of comments to explain each section of code in the function. I believe its advantage was that when reading, you could simply scroll down the function line by line rather than having to jump all over the file.

2 comments

Local functions are also really handy when you want to break up a large function into smaller pieces but keep them localized.
Sure, all I mean is that I get frustrated and lose unnecessarily much time being distracted by keeping a model of how the function works and how variables interact in my head. I have ADHD so my working memory isn't fantastic for these kinds of functions.

I suppose you could take my definition of complexity to be approximate to cyclomatic complexity