Double-Parentheses ()() Requires Too Much Cognitive Load For My Brain
I have no idea if this affects anyone else other than myself; but, when I see back-to-back sets of parentheses in the code, my brain just comes to a complete stop. Unlike so much other code, which I can picture with a simple, linear mental model, I feel like double-parentheses require me to branch off and hold parallel values in my head while simultaneously trying to understand control-flow. It may sound trivial, but it brings my machinery to a catastrophic stand-still.
To be clear, when I talk about double-parentheses, I am referring to code that immediately invokes the return value of another function. Code that looks like this:
- require**(** "thing" )( options )
- connect**(** thisthing )( thatthing )
And, it gets even worse if one of the function arguments is, itself, a function call. Code that looks like this:
- withStuff**(** getthing**() )(** stuff )
At this point, my brain starts throwing parsing errors. I literally (with no exaggeration) have to skip over this block of code and just hope that I have a vague understanding of what it does as I continue to process the rest of the file in my head.
They say that in computer science there are only two hard things:
- Cache Invalidation
- Off-by-One Errors
I think part of why I struggle so much with the double-parenthesis is that I am forced to create a temporary name to hold the conceptual understanding of what the first parenthesis produces. Meaning, when I see code that looks like this:
connect**(** thisthing )( thatthing )
... my brain is actually trying to create an expression that looks more like this:
( var SOME_INTERMEDIARY_CONCEPT = connect( thisthing ) ).call( null, thatthing )
And that's where I stumble. With the name. With creating a name that portrays intent, usage, and functionality. With creating a name that makes sense and is informative. With creating a name that any other developer would understand if they had to read and maintain my mental syntax tree. With doing one of the hardest things in computer science - on-the-fly - while simultaneously trying to understand what the rest of the file is doing.
Glad that I am not the only person who has this problem and is not ashamed to admit it.
When I bump into curried functions I start to imagine all of the scopes and how they are maintaining state. Then I find myself with a notepad and a pen questioning my sanity. It's easier to say 'this bit of code seems fine' and move on. Ha!
Glad I'm in good company :) It could be my personal mental block; or, my personal experience bias; but, I feel like intermediary variables just make the code easier to read and reason about. It seems like nice thing to do for the "next" developer.
Haha! You explained my thinking exactly. I'd concluded I was just too stoopid to get it!!
If you're stupid, then at least you're in good company :D :D :D