News for hackers. Stuff that matters.
Re:Ask HN: Good C++ code bases to read? by kentonv on Wednesday October 28, 2020 @05:27PM (#24924325)
Again, I'm not arguing that operator* should check for nullness, I'm arguing that it shouldn't exist.

With `kj::Maybe` and `KJ_IF_MAYBE`, using the syntax I demonstrated above, you check for nullness once and as a result of the check you get a direct pointer to the underlying value (if it is non-null), which you then use for subsequent access, so you don't end up repeating the check. So, you get the best of both worlds.

> it's likely ~30 loc to wrap std::optional

It's even easier to replace std::optional rather than wrap it. The value of std::optional is that it's a standard that one would hope would be used across libraries. But because it's flawed, people like me end up writing their own instead.

Re:Ask HN: Good C++ code bases to read? by jcelerier on Thursday October 29, 2020 @05:26AM (#24928630)
> So, you get the best of both worlds.

I would really not call code that looks like this "best of both worlds"

    KJ_IF_MAYBE(value, maybeValue) {
      use(value);
    } else {
      handleNull();
    }
when compared to

    if(!value) 
      handleNull();
    use(*value);
Re:Ask HN: Good C++ code bases to read? by kentonv on Thursday October 29, 2020 @08:50PM (#24937942)
Kind of unfair that you didn't include the `else` or the braces in your version, just to make it look shorter.