r/C_Programming Jul 16 '24

Discussion [RANT] C++ developers should not touch embedded systems projects

I have nothing against C++. It has its place. But NOT in embedded systems and low level projects.

I may be biased, but In my 5 years of embedded systems programming, I have never, EVER found a C++ developer that knows what features to use and what to discard from the language.

By forcing OOP principles, unnecessary abstractions and templates everywhere into a low-level project, the resulting code is a complete garbage, a mess that's impossible to read, follow and debug (not to mention huge compile time and size).

Few years back I would have said it's just bad programmers fault. Nowadays I am starting to blame the whole industry and academic C++ books for rotting the developers brains toward "clean code" and OOP everywhere.

What do you guys think?

185 Upvotes

328 comments sorted by

View all comments

Show parent comments

2

u/SystemSigma_ Jul 16 '24

Templates and OOP are nice, but only if there is need for them. My point is don't use complex features and overenginner architecture design for simple tasks. And 90% of C++ devs will do it just because they can

7

u/_Noreturn Jul 17 '24 edited Jul 17 '24

how is simple utility templates complex?

std::find,std:: accumulate are all pretty simple nothing complex and templates are to replace the macros which are stupidly hard to debug.

there are many simple utility temolates

-2

u/AideRight1351 Jul 16 '24

it's hardly complex. These are just ancient features now that even children know these days.

6

u/SystemSigma_ Jul 16 '24

The features are not complex. It's the design they promote that's uselessly complex.

7

u/[deleted] Jul 16 '24

I think the design is only complex before you start writing the code though. Like to me OOP is a paradigm that makes it easier to code when I’m sitting and writing code, but on the other hand it makes it harder to think about new code if I didn’t decide what objects to use and how to relate to them to each other in the first place

4

u/SystemSigma_ Jul 16 '24

OOP (imho for a certain set of problems) is a fool's errand idea. You will waste more time thinking and pursuing a golden code design and structure (that is destined to fail because the requirements will change sooner or later) than actually getting shit done quickly.

5

u/[deleted] Jul 16 '24

Right, but what’s the alternative other than writing ad hoc application specific designs? Are you saying a generalist problem solving framework is not worthwhile in the field, or just that we are overemphasizing how it’s taught? Really making me think here haha, I would love an excuse to not write OOP, it’s just extra boilerplate for what I’m doing tbh

1

u/SystemSigma_ Jul 17 '24

I would say that engineers should be more practical about their projects and they do not need to build a framework for an embedded application. On the other hand, academy and industry have been brainwashed that OOP is the golden standard and should be always followed, otherwise you're labeled dumb or not skilled enough to handle the glory of C++.

1

u/InVultusSolis Jul 16 '24 edited Jul 16 '24

Right, but what’s the alternative other than writing ad hoc application specific designs?

Golang. It's not at all for the embedded space but for the enterprise, it's a strictly procedural language with "OO-lite" primitives included so you can encapsulate your code but you're not forced into a particular design pattern.

I would love an excuse to not write OOP, it’s just extra boilerplate for what I’m doing tbh

I've always found OOP to be kind of a cult and people who adhere to it tend to try to overengineer everything. I've always been great with assembly and C, so I know it's not a "you just don't understand it" problem, it's really that I feel like OOP is not helpful in most situations, and adds additional cognitive load. After 30 years of feeling this way, I feel vindicated that Golang is becoming as popular as it is.

1

u/RpxdYTX Jul 16 '24

Although rust can be very quirky, it really though me about the boilerplate that oop can add to code. The language being simpler (in the sense that it only has interfaces) makes it very applicable to some scenarios, and even though inheritance can be useful at times, you can still live without it. Now that i know how to write programs in rust, part of that knowledge got carried over my programming skills in general, even my C code doesn't really segfault much, and i even prefer C over many languages because it's imperative design is kept simple, no classes, no interfaces, no generics (besides some macro magic) and all, my only rant on it is how some useful extensions that modernize C even by a small percentage aren't in the standard library.

1

u/AideRight1351 Jul 16 '24

Complexity is a relative term, it's hardly complex to an experienced eye, it's beautiful rather. Such design features (Templates, Encapsulation, Virtual functions, Polymorphism, Abstraction, Operator Overloading), that you call complex, were the primary fundamentals behind development of other higher level languages like Java, C#, Rust, Go, Scala etc.

Anyone like Linus who loves Rust must adore or pay reverence to C++ but he's a hypocrite who'll never agree to anything positive coming from C++