What Color is Your Function? (2015)
5 hours ago
- #async programming
- #concurrency
- #programming languages
- The article discusses a metaphorical 'colored function' concept to illustrate issues with synchronous and asynchronous functions in programming languages.
- Red functions represent asynchronous functions with constraints like needing special call syntax, being callable only from other red functions, and having more complex usage patterns.
- Blue functions represent synchronous functions that are simpler but limited, especially when interacting with red functions.
- Higher-order functions become problematic due to color constraints, forcing developers to manage color polymorphism.
- Asynchronous programming models like callbacks, promises, and async-await alleviate some pain but still maintain the color divide.
- Languages using threads, coroutines, or fibers (e.g., Go, Lua, Ruby) avoid the color problem by allowing suspension of entire callstacks without unwinding.
- The core issue is the need to reify callstacks for async operations, which threads solve elegantly by parking and resuming execution contexts.