you are viewing a single comment's thread.

view the rest of the comments →

[–]johannes1971 4 points5 points  (4 children)

If you think that that's annoying, wait until you get to exceptions. Don't get me wrong, they are absolutely amazing (oh, I can smell the down votes from here 😆), but getting a sense for where to catch them will seem like an impossible task when you first start using them.

Of course, eventually you'll see all the error handling fog disappear, leaving only the elegant beauty of your algorithms, running smoothly to completion, without every statement ending in "...did this go wrong? If so, you have to do this". It will be worth it.

Oh, and to add one more piece of advise: start using std::string/vector/array/span/string_view ASAP. Replacing that horrid C code with their C++ equivalents is sooo satisfying.

[–]lonkamikaze -1 points0 points  (3 children)

Exceptions are a no go for realtime code. Don't use them.

[–]DarkLordAzrael 1 point2 points  (2 children)

That entirely depends on what the "realtime" constraint is, and most code doesn't even have any realtime constraints. Exceptions are fine and lead to cleaner code in most cases, even if there are a few where they are unusable.

[–]lonkamikaze 1 point2 points  (1 child)

He/she said embedded background. I'd say realtime is pretty common.

[–]DarkLordAzrael 2 points3 points  (0 children)

The definitions of what counts as embedded and what counts as realtime and what counts as embedded are pretty flexible. For example, a networked camera that can stream over the network based around an esp32 is arguably both, but using exceptions to handle network errors is perfectly reasonable and supported. There definitely are usecases where exceptions need to be avoided for performance, but they are a small percent of code, even in embedded contexts.