frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

What Color is Your Function? (2015)

https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/
30•tosh•1h ago

Comments

frankfrank13•44m ago
My first ever EM showed me this piece ~10 years ago, and I still think about it a lot. One pattern I've adopted is to keep as much code to be synchronous as possible. On larger teams, especially when the slop-cannon is really going, I can at least depend on codeowners to tag me if someone tries to convert something to async (eg. adding a DB call somewhere), because they chain of things that need to be converted to async is so long. Then I can jump in and say "this entire chain of code is sync, if you want a DB call, do it somewhere else"
gordonhart•37m ago
For Python backends I've seen good success with just making it company policy that everything is synchronous (normal-colored) and bypassing the developer overhead from async/await. Cooperative multitasking is a pain because, well, it requires cooperation. You can go pretty far by just adding more threads, processes, and replicas before it's worth the overhead.
graemep•21m ago
I just do not want to do async in Python. If you need async its questionable whether Python is a good choice at all, and if you use Python maybe look at another solution if at all possible (even using more processes and throwing hardware at it).
seabrookmx•16m ago
You not only leave performance on the table (which depending on your use case/environment, may not matter if you can just throw more threads at it) but also some developer ergonomics.

asyncio.gather is a lot less code than having to manage a thread pool or something like Celery with all it's underlying infrastructure.

If you're in an ecosystem where a lot of the async boilerplate is free/cheap (ex: FastAPI) then the developer overhead of sprinkling awaits on your I/O bound calls is pretty low IMO.

nickcw•42m ago
Go doesn't have colored functions due to its nice fat runtime hiding all the async magic away for us.

That makes it a pleasure to code concurrent stuff for IMHO.

It does have its own similar problems though - does a function return an error? If so you are going to need to plumb the error return through all the callers. Does a function need a context.Context? Ditto.

I guess you can't win them all :-)

vq•30m ago
And Haskell is an ensemble of rainbows. It's very fun and pretty to look at.

Type classes can smooth over some of it but it's not unusual to have to do some plumbing.

jerf•6m ago
This is a subtle point that I've seen missed repeatedly, but: The reason that "color" is important is that if you have a function ten layers down in your stack that is the wrong "color", you now have to change that top-level function.

Propagating errors up the stack is not the same, because the top-level function is not developing an error return because of the 10-level-nested function. It is developing one because the function it called has one, and apparently, it needs to return it to its local caller. It's a local consideration. It is true that it may be a recursive local consideration where this was true 10 times, but the reason it is different is that it doesn't have to be that way. It could have been the case that the function 7 layers down handled the error somehow and it stopped propagating up the stack. But at each point, the consideration was local, and as such, amenable to local solutions other than just tossing the error up. If you choose to "correctly" plumb the error through all your functions, well, good on you for apparently being willing to apply good software engineering practices even when it's annoying, but this is just normal day-to-day function activity stuff.

By contrast, in a function coloring situation, if the color is wrong 10 layers down, you must change the calling function. It's a non-local consideration. You don't get to decide not to change it. You can't encapsulate it. You don't get a choice. It pollutes the entire stack, forcibly.

If you don't have this, you don't have "color". Like, some people will say that in their language that maybe there is some way to encapsulate it. If you can, then you don't have an async color. Although I will say that if your "encapsulation" is basically to run it in a non-concurrent environment, that's not encapsulation.

Go's context.Context is similarly not a color. You can always just create a context.Background() and pass that down. If you didn't have any context already in hand, which means you must not care about any of the features context offers, then that is usually a fine thing to do. Context is trivially bypassed if you don't want it. It can be encapsulated within a portion of the stack without "polluting" the rest of the stack like any other function parameter.

The key aspect of color is that it is not optional. It isn't something that you can just decide to ignore and stop passing up, or trivially create a value for passing down to other functions. You have to change the "color". Modulo "unsafe", Haskell's IO is a color; anything that wants to use IO must also be in IO, and you can't just whip up your own "IO" value. Async is a color in many environments. There aren't really that many colors in programming languages because they are very, very quickly inconvenient and we tend to squeeze them out. Statement versus expression distinctions are another one, where a "statement" may not be usable in an "expression", and you'll note how languages have in general erased that one over time because it's really just a cost without much benefit.

preommr•22m ago
> You still can’t call a function that returns a future from synchronous code. (Well, you can, but if you do, the person who later maintains your code will invent a time machine, travel back in time to the moment that you did this and stab you in the face with a #2 pencil.)

Author makes up a lie.

Then lampshades it away with a colorful non sequitur.

---

The alternatives that people praise like golang, have other tradeoffs that are much worse because the async logic is now implicit. Your entire codebase is now a surface area that is at risk of being blocked by waiting on a channel; the the mitigation of this is through responsible use of coroutines, but then you're right back around to extra information about your code that is analogous to colring, except not as explicit as async/await.

assbuttbuttass•7m ago
> Your entire codebase is now a surface area that is at risk of being blocked

The point of goroutines is that they can freely block when needed. It's not like async where you have to be paranoid at every moment about writing blocking code

Tzt•21m ago
Purple.
satvikpendem•21m ago
We need algebraic effects in more languages, this solves the function coloring problem. OCaml 5 has them and it seems to be doing quite well, combine that with the semantics of the borrow checker in the form of OxCaml and we might just have an ideal language. I'd like to see algebraic effects in Rust as well but sadly it seems their keyword generics initiative is languishing.
bre1010•18m ago
I wish the key word was instead dontawait and was used inversely to how await is used. 99% of the time I'm using an async function, despite however slow it is, there's nothing for my code to do but wait for it to finish. But if for some reason I would like the next line of code to run before the current one is done, I'll let you know.

Like, why can't my sync function await something asynchronous? If it has to lock up the whole thread while that function executes, that's fine because that's how it was going to work anyway 99% of the time

axus•12m ago
Like the & at the end of a shell command?
gnarlouse•11m ago
> Spidermouth the Night Clown

Thanks for my next horror shortfilm plot. Twist: he's the protagonist

What Color is Your Function? (2015)

https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/
31•tosh•1h ago•14 comments

Uber, Lyft drivers in Massachusetts form first US ride-share union

https://www.reuters.com/business/world-at-work/uber-lyft-drivers-massachusetts-form-first-us-ride...
140•onemoresoop•1h ago•59 comments

The Ballad of TIGIT

https://www.owlposting.com/p/the-ballad-of-tigit
32•crescit_eundo•1h ago•1 comments

Is "colorectal cancer" rising in "young people"?

https://dynomight.net/crc-rates/
21•surprisetalk•1h ago•2 comments

Launch HN: Minicor (YC P26) – Windows desktop automations at scale

https://www.minicor.com/
37•fchishtie•2h ago•23 comments

Language Models Need Sleep

https://arxiv.org/abs/2605.26099
100•juxtapose•2h ago•73 comments

Sage Care (YC S24) Is Hiring Software Engineers

https://www.ycombinator.com/companies/sagecare/jobs/xtloH8r-senior-software-engineer
1•ian-gillis•40m ago

Don't Subscribe So Casually

https://thebestworstcase.substack.com/p/dont-subscribe-so-casually
72•shmublu•2h ago•57 comments

Spain blocks prediction markets Polymarket, Kalshi over lack of gambling licence

https://www.reuters.com/business/spain-blocks-prediction-markets-polymarket-kalshi-over-lack-gamb...
323•thm•4h ago•167 comments

C64 Basic: Game Map Overhead "Camera View"

https://retrogamecoders.com/overhead-camera-view/
43•ibobev•3h ago•5 comments

Using AI to write better code more slowly

https://nolanlawson.com/2026/05/25/using-ai-to-write-better-code-more-slowly/
1013•signa11•18h ago•384 comments

Opaque Types in Python

https://blog.glyph.im/2026/05/opaque-types-in-python.html
75•lumpa•3d ago•26 comments

Netherlands blocks US takeover of vital digital supplier

https://www.politico.eu/article/netherlands-blocks-us-takeover-vital-digital-supplier/
359•vrganj•5h ago•126 comments

DynIP – Dynamic DNS with RFC 2136, IPv6, DNSSEC, and BYOD

https://dynip.dev/
260•dynip•10h ago•106 comments

A few interesting modern pixel fonts

https://unsung.aresluna.org/a-few-interesting-modern-pixel-fonts/
8•zdw•20h ago•2 comments

Taking a walk may lead to more creativity than sitting, study finds (2014)

https://www.apa.org/news/press/releases/2014/04/creativity-walk
513•bilsbie•19h ago•204 comments

Are we self-sovereign PKI yet?

https://buffrr.dev/blog/are-we-self-sovereign-pki-yet/
29•ca98am79•4d ago•8 comments

Outsourcing plus LocalAI will soon become more economical vs. Frontier labs

https://www.signalbloom.ai/posts/outsourcing-plus-localai-will-soon-become-more-economical-vs-fro...
128•GodelNumbering•5h ago•144 comments

Don't put aria-label on generic elements like divs

https://www.matuzo.at/blog/2026/aria-label-generic-elements
73•cyanbane•4d ago•52 comments

Phantasy Star IV – 1993 Developer Interviews

https://shmuplations.com/phantasystariv/
111•speckx•4d ago•37 comments

Rosalind: A genomics toolkit in Rust running whole-genome pipelines on a laptop

https://github.com/logannye/rosalind
3•samuell•5d ago•0 comments

Incident with Actions and Pages

https://www.githubstatus.com/incidents/gnftqj9htp0g
70•hakube•6h ago•20 comments

Eagle 3.1: Collaboration Between the EAGLE Team, vLLM Team, and TorchSpec Team

https://vllm.ai/blog/2026-05-26-eagle-3-1
58•berlianta•5h ago•20 comments

How Shamir's Secret Sharing Works

https://ente.com/blog/how-shamirs-secret-sharing-works/
333•subract•19h ago•58 comments

How do you build a semiconductor company on something that's free?

https://www.siliconimist.com/p/the-open-source-silicon-business
57•johncole•4d ago•18 comments

Ferrari shares fall after launch of first EV as Jony Ive design proves divisive

https://www.theguardian.com/business/2026/may/26/ferrari-luce-ev-jony-ive-design-sports-car
21•coffeeyesplease•1h ago•17 comments

Ferrari Luce

https://www.ferrari.com/en-EN/auto/ferrari-luce
431•jumploops•20h ago•795 comments

What we lost when we stopped letting kids leave the front yard

https://stevemagness.substack.com/p/the-cost-of-safetyism
465•obscurette•1d ago•495 comments

A successful Japanese trial of a ramjet engine designed for Mach‑5 aircraft

https://www.bgr.com/2178211/japan-hypersonic-engine-ramjet-2-hour-flights-to-us/
221•rmason•21h ago•166 comments

Stockholm poised to become leading European geospatial intel player

https://www.intelligenceonline.com/europe-russia/2026/05/26/stockholm-poised-to-become-leading-eu...
29•alephnerd•2h ago•10 comments