Posts

The Secret Life of JavaScript: Currying vs. Partial Application

Image
  The Secret Life of JavaScript: Currying vs. Partial Application # javascript # coding # programming # softwaredevelopment Timothy was staring at his monitor with the distinct expression of someone whose brain had just finished buffering and decided to crash. On his screen was a single line of JavaScript he had pulled from a functional programming utility library. const formatUrl = protocol => domain => path => ` ${ protocol } :// ${ domain } / ${ path } ` ; "Margaret," Timothy said, without looking away from the screen. "My eyes are crossing. Why are there so many arrows? And why does calling it look like a nesting doll accident?" He pointed to how the function had to be used: formatUrl ( ' https ' )( ' somewebsite.com ' )( ' /blog/post-1 ' ); Margaret rolled her chair over, coffee mug in hand. She smiled. "Ah. You've discovered the 'scary syntax' part of functional programming. You're looking at  Cu...

Python by Structure: List Comprehensions and Their Hidden Complexity

Image
  Python by Structure: List Comprehensions and Their Hidden Complexity # python # coding # programming # software Timothy was refactoring some data processing code when he hit a comprehension he couldn't understand. "Margaret, someone wrote this comprehension and I can't figure out what it does. It's all on one line and my brain just... stops." Margaret looked at the code: result = [ item for sublist in data for item in sublist if item > 0 if item % 2 == 0 ] "Ah," Margaret said. "That's a comprehension that's crossed the line from clever to confusing. Let me show you what's actually happening here." The Problem: Comprehensions Gone Wrong "Comprehensions are powerful," Margaret explained, "but they can become write-only code. When you nest loops and stack filters, the execution order isn't what most people expect." Timothy nodded. "I thought comprehensions were supposed to make cod...