Bob Nystrom
journal.stuffwithstuff.com · Personal blog · on HN since 2008
Bob Nystrom, a Google engineer and author of Crafting Interpreters, writes about programming languages, parsers, and game programming.
What HN saysCommenters love his writing, calling out "What Color Is Your Function?" and the code formatter post, and note his compiler and interpreter expertise.
392HN people shared it
282linked it in comments
186stories submitted
8.0Kstory points
4 months agolast shared
2008people per year2026
Most-shared posts
- 1What Color Is Your Function?192 people · 871 points · first shared 2015 · 143 comments on HN
- 2JavaScript Isn't Scheme26 people · 294 points · first shared 2013 · 108 comments on HN
- 3Baby's First Garbage Collector25 people · 545 points · first shared 2013 · 84 comments on HN
- 4Pratt Parsers: Expression Parsing Made Easy (2011)25 people · 374 points · first shared 2011 · 59 comments on HN
- 5The Hardest Program I've Ever Written – How a code formatter works (2015)24 people · 1.4K points · first shared 2015 · 133 comments on HN
- 6Crafting “Crafting Interpreters”17 people · 966 points · first shared 2020 · 74 comments on HN
- 7Iteration Inside and Out12 people · 12 points · first shared 2013 · 5 comments on HN
- 8640 Pages in 15 Months11 people · 2 points · first shared 2012 · discussion on HN
- 9Long Names are Long10 people · 257 points · first shared 2016 · 80 comments on HN
- 10Rooms and Mazes: A Procedural Dungeon Generator9 people · 608 points · first shared 2014 · 48 comments on HN
- 11Crafting Interpreters: 640 Pages in 15 Months8 people · 435 points · first shared 2021 · 26 comments on HN
- 12The impoliteness of overriding methods6 people · 150 points · first shared 2012 · 49 comments on HN
- 13Higher Order Macros in C++6 people · 93 points · first shared 2012 · 29 comments on HN
- 14The Biology of Sloppy Code6 people · 33 points · first shared 2010 · 6 comments on HN
- 15Show HN: How I made the print and eBook versions of my web book5 people · 239 points · first shared 2014 · 66 comments on HN
What HN people wrote when they linked it
matheusmoreira · 2026-07-20
My favorites are:
http://wingolog.org/
https://www.journal.stuffwithstuff.com/
> I miss the 2009 era of blogging about personal projects
I've been doing that. Not sure if I've made it into anyone's favorites yet.
https://www.matheusmoreira.com/
MatheusRich · 2022-02-07
It's not regularly updated, but I absolutely love anything @munificentbob writes at https://journal.stuffwithstuff.com/
munificent · 2015-09-18
> I don't think good content necessarily needs to be paid for. Much of the best content on the web is created as a hobby, with no attempt to monetize, like dr-iguana.com (and countless others.)
I felt that way for a long time. I am basically living that philosophy. My blog[1] has always been free to read and free from ads. I wrote a book[2], and you can read the entire thing online for free, again with no ads. Almost all the code I write is open source.
I imagined a utopia where all kinds of creative people would have enough free time to pursue their hobbies and share the fruits of their labor. I am lucky enough to basically live that utopia now—I happen to love programming, which is a very lucrative field.
It's fine to dream of a world where my personal utopia is more widely available, but that world isn't here today. You can think of a culture or society as the aggregate sum of all of its shared creative works.
When creative works can only be done by those who can afford the leisure, it skews society towards the perspective of the rich. Think back to 19th century English literature and how few novels there are that show how regular working-class people lived. That's because regular working-class people back then were too busy working in the mines to write a book.
There are some counterexamples, sure, but even most of those were created by rich people observing the poor from a distance. As sympathetic as Dickens was towards the poor, the stories he tells are still…
albertzeyer · 2026-05-05
The classic function coloring problem. https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
Philpax · 2026-04-24
For context, this is the author of https://craftinginterpreters.com/ , and https://gameprogrammingpatterns.com/ , and https://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-… .
I promise that he knows a thing or two about compilers and performance!
For what it's worth, I agree with him. A recent example is the porting of the TypeScript compiler to Go: it hasn't been fully released yet, but people are already going wild for its performance improvement over the original in-TS compiler.
Of course, it took them over a decade to reach the point where a port was necessary - so it's up to you to decide when that decision makes sense for your language.
throwawaymaths · 2025-12-02
1) zig's io is not a viral effect type, you can in principle declare a global io variable and use it everywhere that any library calls for it. Not best practice for a library writer, but if you're building an app, do what you want.
2) There are two things here, there is function coloring and the function coloring problem. The function coloring problem is five things:
https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
1. Every function has a color.
2. The way you call a function depends on its color.
3. You can only call a red function from within another red function.
4. Red functions are more painful to call.
5. Some core library functions are red.
You'll have some convincing to do that zig's plan satisfies 4. It's almost certain that it won't satisfy 5.
It's open to debate if zig's plan will work at all, of course.
WickyNilliams · 2025-09-16
It's not confusing. It's an observation on their nature. The colouring isn't specific to promises, or even async/await. It applies to continuation style callbacks too.
If you haven't, I recommend reading the (original?) article https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
essnine · 2025-07-22
This is a good read. I remember first using eventlet for writing concurrent code, and then having to do a bit of mental adjustment when moving to asyncio.
Another piece of writing I found useful for perspective at the time was What Color is Your Function?[1], which I bumped into after looking at the Node.js model of concurrency and being confused.
[1](https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
joshdata · 2025-07-01
Is the goal to make good ORM queries easier or to prevent bad queries? It's not clear there's really a compiler solution to the latter. If you're inside a loop in which a database cursor is in scope, then further database queries are prohibited? It's hard to see how that could be enforced other than something like What Color Is Your Function (https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct… with some functions marked as making queries and others as not.
To solve this, maybe instead best practice would be to ensure the database connection is not in a global variable and must be passed down. That would make it more obvious when a database is improperly used within a loop.
The same problem exists for any expensive operation within a loop (say, a database query while parsing the results of an API call, or vice versa).
cosmic_quanta · 2025-04-17
My favourite thing about Haskell concurrency is that there are no colored functions [0]. Writing code in IO, or Async, or the next big thing (asychronous higher-order effect system of the future??), doesn't require language support like Python or Rust.
The one construct that unlocks this lack of colored functions, STM, did require runtime support (as opposed to language support), which at least is transparent to downstream developers
[0]: https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
poidos · 2024-07-02
Reminds me of the tool Bob Nystrom wrote to help himself out when working on the physical edition of Crafting Interpreters: https://journal.stuffwithstuff.com/2020/04/05/crafting-crafting-interp…
Whole article is worth reading, but if you want the relevant bits search for “ I wrote a Dart script that would take a PDF of the book”.
thomastay · 2024-06-18
Whenever iterator design comes up, I always have to refer to munificent's excellent article: https://journal.stuffwithstuff.com/2013/01/13/iteration-inside-and-out…
tldr: The gold standard is if your iterator syntax / syntaxes can support these two types of iteration:
1. Interleaving two sequences
2. In-order tree traversal
miohtama · 2024-03-25
Also there is the extra software development and maintenance cost due to coloured functions that async/await causes
https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
Unless you are doing high scalability software, async might not be worth of the trade offs.
sporkland · 2024-03-25
I don't know how the challenges with cooperative (no-preemptive) multitasking keep needing to get rediscovered. Even golang, which I consider a very responsibly designed language, went with cooperative at first until they were forced to switch to preemptive. Not saying cooperative multitasking doesn't have its place, just that it's gotta have a warning sticker or even better disallow certain types of code from executing statically.
Also great time to plug a related post, What color is your function:
https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
mananaysiempre · 2024-02-26
Bob Nystrom makes this argument best, I think, in his two-parter on loops and iteration[1,2]. Looping over data structures is of course only one example of how one can apply coroutines, but a very established one. The canonical problem requiring coroutines[3] is also essentially about doing that.
Or for those who want something different there’s the elevator (and elevator-userbase) simulation from TAoCP volume 1, also an essentially concurrent problem with little to no parallelism or I/O to it.
[1] https://journal.stuffwithstuff.com/2013/01/13/iteration-inside-and-out…
[2] https://journal.stuffwithstuff.com/2013/02/24/iteration-inside-and-out…
[3] https://wiki.c2.com/?SameFringeProblem
Vinnl · 2024-02-10
That allows other code to run while e.g. files are being moved. It indeed can be somewhat painful ([1] is the classic criticism) and in shell scripts is not as beneficial. I think there are even sync alternatives (i.e. equivalent functions that don't need `await`) for most of them, but again: these are the APIs I'm already familiar with, which is the entire point - and thus the await-stuff comes naturally for me, because I intuitively know those APIs are async.
[1] https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
bostik · 2023-12-29
Code reformatting is, apparently, surprisingly hard. This classic article has popped up on HN a few times over the years: https://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-… (one reappearance at https://news.ycombinator.com/item?id=30566111)
So I can understand why such a feature remains behind an experimental flag. "But you are not touching code, only reformatting comments!" - well, not just thta. Adding whitespace and N+1 effectively empty lines will at some point cascade into whatever logic the wider code formatter will have to consider. The number of edge cases must be non-trivial.
iKlsR · 2023-03-19
From the author of Crafting Interpreters and Game Programming Patterns, some interesting stuff here about how he went about his two books which are excellent quality http://journal.stuffwithstuff.com/category/book/
Dzugaru · 2023-03-18
Async/await in C# is a leaky abstraction though. There is a great writeup on this here https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
no_wizard · 2023-02-14
I still think this is one area Rust missed the mark. Go concurrency is quite amazing. Its fast and easy to reason about. Every language can learn something by how goroutines work here. Most importantly, it feels like you're just interacting with synchronous code. There is no "what color is your function?"[0] problem.
The fundamental primitives Rust decided to adopt are just not ergonomic by comparison, and suffers from the aforementioned "What Color Is Your Function?" problem.
An otherwise great language decided to adopt an old hand grenade in regards to async primitives
[0]: https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
cratermoon · 2022-10-07
The article that is the inspiration for the title here is worth reading. https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
It's been mentioned on HN before.
bestinterest · 2022-08-31
I think this post has the best information on it as I am also learning here https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
It is not just `magic` syntax imo, it is viral to your codebase. The blog post does way more justice than I can explain.
michael-go · 2022-06-23
Dear Bob, in case it helps FYI both the book's website http://craftinginterpreters.com/ and your blog https://journal.stuffwithstuff.com/ seem down right now.
And if anyone was curious like me to see the book's website, here is a archive link: https://web.archive.org/web/20220616005500/http://www.craftinginterpre…
Pr0ject217 · 2022-02-07
EDIT:
Paste this hacky snippet into your browser's console to save all of the links into your clipboard:
(() =>
{
let result = [...document.querySelectorAll('td a')]
.map((link) =>
link &&
!link.href.includes('ycombinator') &&
!link.href.includes('javascript:void')
? link.href
: ''
)
.filter(Boolean);
result = [...new Set(result)];
result.sort();
copy(result.join('\n\n'));
})();
Just to help, here's a compiled-list of all of the links shared here so…
pamoroso · 2022-02-07
Here are some great but lesser known blogs:
- Brian Robert Callahan https://briancallahan.net/blog
- Austin Z. Henley https://austinhenley.com/blog.html
- Robert Nystrom http://journal.stuffwithstuff.com
- poor.dev https://poor.dev/blog
- Simon Willison’s Weblog https://simonwillison.net
chubot · 2021-11-12
Yup this is a great article about it that I coincidentally re-read yesterday:
https://journal.stuffwithstuff.com/2013/01/13/iteration-inside-and-out…
I find it easier to think of as "push-pull" though. In Python and Go, you "pull" from iterators. In Ruby, JavaScript, and Rust, you're "pushed" upon. You can do both styles in any language, but there's one way that's favored.
To break the dilemma, you need 2 call stacks, which means threads / coroutines / generators.
(There was a recent blog post about writing an iterator to do the powerset calculation, which is a bit tricky, and made me think of this post)
red2awn · 2021-05-27
Awesome technical and programming related blogs:
https://eli.thegreenplace.net/
http://journal.stuffwithstuff.com/
smlckz · 2021-02-13
I don't know if it is good or bad, but, think about the following metric: the number of lines written but eventually deleted divided by the number of lines of code retained.[1] [2]
[1]: http://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-e…
[2]: https://www.folklore.org/StoryView.py?story=Negative_2000_Lines_Of_Cod…
svieira · 2020-12-04
A couple of excellent articles on the different ways of thinking about the choice (of when to yield) vs. color (virality of choice) problem:
* Choice is bad: https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…
* Choice is good: https://glyph.twistedmatrix.com/2014/02/unyielding.html
alblue · 2020-11-23
Some really good observations in here about why libdispatch suffered from scalability issues (in that it created to many threads) and the dichotomy of having to sprinkle async everywhere even if it didn’t make sense because it needed to be used from an async function elsewhere.
Related; the difference between “red” and “blue” functions is worth a read:
https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-funct…