布尔值可以容纳多少种选项?
How many options fit into a boolean?

原始链接: https://herecomesthemoon.net/2025/11/how-many-options-fit-into-a-boolean/

这篇帖子详细介绍了作者最近对“Paged Out!”的贡献,这是一本实验性的一页技术杂志。在收到邮件邀请后,作者迅速撰写了一篇文章,结合了Rust知识和Google Slides。文章现在可以作为PDF查看,作者欢迎反馈。 除了杂志的贡献,这篇帖子还分享了一些个人近况:作者将从欧洲中部搬迁到西雅图,从事另一份人工智能相关的工作。他们对这次搬迁感到兴奋,理由是现有的联系、积极的先前访问经历以及充满活力的当地文化。 最后,作者提到了大量未完成的写作项目,涵盖了内存安全、人工智能,甚至是一些冷门电子游戏等主题,强调了一种轻松的博客方式,并优先考虑个人乐趣而非严格的截止日期。

## 布尔型能容纳多少选项? 一篇由[herecomesthemoon.net](herecomesthemoon.net)引发的Hacker News讨论,探讨了一个令人惊讶的复杂问题:一个布尔型数据类型能容纳多少状态。虽然表面上仅限于真/假,但对话揭示了在某些情况下需要更多选项——并且已经实现。 用户分享了在政府合同中使用四态逻辑(是/否/未回答/未提问)的经验,以及对“也许”选项的常见需求,通常通过枚举或Rust的`Option`优雅地处理。一个特别有趣的点是微软的`MsoTrioState`,尽管名称如此,但它可以容纳*五个*值,利用“利基优化”——利用字节内未使用的位模式。 这种优化允许多达254个嵌套的`Option`实例容纳在一个字节内,打破了每一层都需要额外空间的预期。讨论涉及内存布局的复杂性以及即使是简单类型也并不总是像它们看起来那样简单。最终,该帖子表明,对超出简单布尔型的需求很常见,并且存在巧妙的编程解决方案来适应它。
相关文章

原文
A lot of them, apparently.
A lot of them, apparently.

Toggle original/dithered image

Hello!

Not too long ago, a friend of mine told me about Paged Out!, a “free experimental (one article == one page) technical magazine”. (Yes, that means that you can read them online right now. In fact, you might even want to consider contributing).

I thought “Huh, that’s cool.” and then neglected to follow up on it in any meaningful capacity whatsoever, since it’s notoriously hard to remember to sit down and look at a random tab in your browser, especially if it is slowly being buried beneath other tabs.

About halfway through August I suddenly received an e-mail by someone named Aga, asking me if I’m interested in contributing a one-page article to this funny magazine thing they are running.

I was like “Huh, that’s cool… Wait, I’ve heard of this. Screw it, why not.” and hammered out an article over two evenings, combining my knowledge of random Rust trivia with the full power of the modern tech infrastructure stack (which is to say, Google Slides) to create a funny little one pager:

    / [pdf]

A few notes:

  • If you see any errors, reach out! Preferably before the next issue is published.
  • If you want to contribute to Paged Out!, you can! Just check out their website. If whatever this page here is inspires you enough to hand something in, let me know.
  • One page is not a lot of space to work with. It certainly helped me keep the scope small, though.
  • On the note of empty space, the space at the bottom exists to leave enough space for the Paged Out!-footer.
  • I can’t say I like that syntax highlighting color scheme, but it’s the best I could get (using an extension) without manually coloring every token.
  • This is a slightly-updated version of the article. When writing the first draft I wasn’t sure why Result<bool, bool> takes up more than one byte. Someone on Reddit let me know why. In hindsight this one feels obvious, but (in the spirit of the challenge) I didn’t want to get sucked into research over what I assumed to be an optimization detail. It turns out it isn’t: It’s just that (duh) the value in the result has to have a valid memory representation, so we can’t use the remaining bits to optimize.
  • If you’re not much of a Rust user, you might be horrified by the size_of::<type>() syntax. This looks weird at first, but makes perfect sense. The ’turbofish’ syntax (::<T>) allows us to specify the type passed to a generic function without needing to pass a value. It’s just a function (albeit one backed by a compiler built-in). In C/C++ sizeof requires a special keyword.
  • Embedding this PDF wasn’t cheap (in terms of Javascript dependencies), and it unfortunately broke the page size counter at the bottom. Oh well, I’ll try to fix it soon.

If you don’t care about what’s going on in my life, you can leave now! This is just a few notes about what I have been up to.

tl;dr: It looks like I’ll be moving from Central Europe (working on AI) to the Seattle area (working on AI, very funny, I know).

This is objectively one of the funnier times to do that. So far I’ve not regretted decisions like this, and I hope that that pattern continues. (2+ years ago I moved from Germany to Warsaw. Warsaw is nice. The local language barrier is a drawback, though.)

As for Seattle, I am looking forward to it. I know people there. I visted a few months ago. I liked the local scene. I liked the random encounters you’ll get around Cal Anderson. I liked the $1.50 Costco hotdog. I liked the drinks served at the local furry-owned cider company. I liked the events, whether it’s local fighting game tournaments, literal Labubu raves, or random people meeting in the middle of the park to ’eat pudding with forks'.

I’ll find out. It helps that I know a surprising amount of people in the area.

As far as writing goes, I have a whole bunch of half-finished drafts that I’ll surely get around to one of these days.

There’s a lot of random things on my mind: Hot takes about memory safety, thoughts on software licensing, AI, and social contracts, thoughts on GAP, random takes on obscure video games I enjoyed, LLVM, whatever Uiua is.

Maybe I’ll finish some of those and put them here.

I don’t want to stress out too much over it, honestly. A blog is something you do for yourself, stressing out too much over it is a bad idea. I have a backlog, and that’s fine. That’s a list of potential fun projects I can pick up and work on whenever I feel like it.

Besides, If I can’t figure out how to put something into words, that’s generally a good sign that I need to take a step back and let it rest for a while (or that I need to spent some time on more in-depth research).

Anyway, have a good one!

联系我们 contact @ memedata.com