Developer Discussion: Handling Errors

I didn’t see this mentioned in the thread, but something that might be relevant to this overall topic is std::expected that was accepted into c++23. I found an implementation for c++11/14/17 here. I don’t know what the feasibility of just using this (header-only) library is, but it can probably at least inform API decisions / provide more food for thought.

1 Like

Yeah, I’ve been actively looking at std::expected (among other things) for inspiration, which has indeed informed some of the design decisions already. I probably should make explicit mention of that in the PR description. Will do so the next chance I get to work on it.

In general, though, it’s not clear to me that std::expected is a good fit for Blender. Core types like this that intend to end up as a fundamental building block in Blender probably(?) should be kept in-house so we can ensure they work well for our needs and behave the way we need them to. Much like BLI’s Vector and Span types.

1 Like

It is not so much the fundamental nature of types that decides whether something is in BLI or not.

For the Vector there is for some performance reasons, and to align exact behavior on different platforms. Span is there because std::span is not available in C++17.

Things like std::optional or std::string are used directly.

But since std::expected is from C++23 we’d need to have something in BLI.

When it comes to that, my personal belief is that aligning to something that exists later C++ version has a benefit of:

  • People are likely to be much more familiar with the concept already, which, hopefully does not increase entry barrier for new developers (or developers who contribute to Blender in their spare time and can not keep all the Blender specific things in head)
  • There is plenty of documentation, and examples outside of Blender
  • It allows to eventually get rid of many lines of code when we switch to newer C++ standard.

Not saying copying std::expected is the objectively proper way forward, but I think those points is something to keep in mind when making decision. Sometimes it feels we don’t pay proper attention to the entry barrier and ease of external contributions.

5 Likes