HeadlinesBriefing favicon HeadlinesBriefing.com

Function Arguments vs Colors Explained

Hacker News •
×

In debates about function colors, some argue function arguments can be colors, citing Go's context value as an example. Context manages timeouts and cancellation, and is designed to be threaded through functions even if unused directly. Once a function uses context, you should pass it to all called functions, superficially appearing as a color.

However, if all parameters were colors, the concept wouldn't have been invented 50+ years after functions. Async has a distinct nature worth capturing. To clarify, consider a change dependency graph: changing a function attribute deep in a call stack can affect callers in three ways: no caller change, direct caller change, or all functions in the stack change.

A color forces all functions above to react, while a normal change only propagates to the caller and can be caught. In practice, functions break the chain, isolating higher functions from lower changes. Structured programming exists to isolate changes, and if every parameter change forced changes up the entire stack, it would be unmanageable.