r/cpp • • Oct 22 '26

These Bees Make the Wrong C++

https://dalerank.github.io/en/articles/wrong-cpp-bees.html
71 Upvotes

15 comments sorted by

View all comments

Show parent comment

12

u/remy_porter Oct 22 '26

The guidelines we were (mostly) using were out of DoD's JSF guidelines and some NASA guidelines, with a splash of MISRA.

I'd argue though that while it expects more of your programmers, it makes fast iteration and refactoring easier: because you've eliminated a huge class of possible side effects and means static analysis can answer a lot of questions for you. Also, at least in our work, we were heavily influenced by robotics frameworks, which means everything was implemented via message passing, which made it really easy to break dependencies between modules. At runtime, you'd pick which nodes you wanted running, and that meant you could swap mocks easily, or even "here's a prototype version of an idea".

We used cFS, but FPrime was similar and more C++ oriented. These days, I'm working on explicit robotics, which means ROS2 for me. It's all basically the same- the stuff that you'd call microservices if you were throwing it in the cloud, that's how you build this kind of low level software: pub/sub message architectures running on top of a lightweight middleware.

4

u/protoloop Oct 22 '26

Thanks, those are great references!

For dynamic allocations you say you use arena allocators. What are the policies you use to determine which allocator to use and when?

For example in games (and I imagine in RTOS) we have immortal objects, per level objects, per frame objects, and per operation objects, each requiring a different arena. An operation (say a cooperative task that runs over multiple frames) needs to decide which arena to use for what. It might end up allocating all of those types of objects, so all the arenas need to be passed to the task. And if it uses the wrong one for something it might be hard to detect.

That's what I mean by extra complexity.

Most of the guidelines out there provide a bunch of do's and dont's, but i haven't found a good reference for idioms/best practices on how to satisfy them.

Does something like that exist? Or is it mostly experience and oral tradition?

4

u/remy_porter Oct 22 '26

I think teams will have their own documents about this, but yeah, a lot of it is experience. And it varies a lot by domain, too. Working on space robots was one set of constraints. I'm working on tomato picking robots right now, and uh... we're way more "whatevs" when it comes to memory allocations (probably to our detriment, though our performance is more bounded by "how fast can we make the arm move" than anything else).

1

u/protoloop Oct 22 '26

Yeah i get it. Similar in games - alot of BPs just aren't documented anywhere. Thanks for the info!

1

u/sheckey Oct 23 '26

Thank you for the references. I’m trying to do very similar things as cFS and FPrime. It’s great to see others coming to similar conclusions. Thank you.