Someone on Medium Just Said C++ Was Better Than C (medium.com)
Developer David Timothy Strauss is publishing a call to code "straightforward, easy-to-reason-about approaches" -- in an essay titled "Choosing 'Some C++' Over C". (Alternate title: "C++ for Lovers of C."
The problem with just picking C++ is that most criticism of it is legitimate. Whether it's the '90s-era obsession with object orientation and exceptions or the template errors that take up an entire terminal window, there have been -- and remain -- rough edges to C++. But, these rough edges are avoidable, unlike the problems in C that get worse with modern event and library programming.
The opinionated essay calls for "adopting a subset of C++ to smooth out C's rough edges," arguing that C++ offer a better, type-safe approach for event-driven design (as well as destructors to avoid memory allocation leaks). Are there any readers who'd like to weigh in on the advantages of C versus C++?
What particularly don't you like about C syntax? I've always thought that the main security problem with C are caused by the lack of a decent buffer processing library, and a lousy string processing library. Fix those two things (and any person can do it in their own code!) and you've fixed the vast majority of C security bugs.
"First they came for the slanderers and i said nothing."
In the 1990s I worked on a complex device driver for OS/2 for ATM networking (asynchronous transfer mode). The driver was around 100K lines of C++ code however only a subset of C++ was used. Surprisingly the use of C++ worked out quite well. We had an equivalent driver for Windows NT that was written in C that was over 300K lines of code. The C++ codebase was a lot more reliable and easier to work on, despite all the work that was done to make C++ work in kernel mode under OS/2. The C++ driver actually had more functionality than the C driver and it was faster as well with a smaller binary. Also, as I said, it was a subset of C++, especially in the performance critical code. The driver in question included the entire ATM signalling stack and implemented full LAN emulation support with both Ethernet and Tokenring plus it could emulate multiple networks (ELANs, equivalent to VLANs) simultaneously. When I implemented multiple ELAN support I was afraid it was going to be a nightmare, but due to the way it was architected in C++ I ended up only having to change a few lines of code, changing a pointer to the LANE class to an array of pointers.
For the signalling stack and ILMI C++ worked out especially well due to the event and message based nature of it and the various state machines. For LAN emulation it made it easy to support both Ethernet and Tokenring by having a few virtual functions in the main LANE class.
There was no exception handling support and none of the more complex C++ features were not used. It used templates but that was also somewhat limited.
Having destructors was also quite nice, making it easy to clean up resources.
Despite being C++, debugging wasn't too bad though at the time the OS/2 kernel debugger basically ran at the assembly level.
If the infrastructure is in place I can certainly see using C++ in the kernel and device drivers.
This post is encrypted twice with ROT-13. Documenting or attempting to crack this encryption is illegal.
You are quite correct. Everyone uses different subsets of C++. The consequence of this should be obvious. Do not use C++ in any circumstances where code has to be maintained. The next maintainer maybe totally unable to deal with it being an expert (and using) a different subset of C++.
WTF, I have to escape less and greater inside of a code tag?
There are no pointers involved, nor objects.
The whole thing is for some strange reason "undefined".
But actually it is pretty clear, why the C community made it "undefined" is beyond me, well: they did not want to impose a rule. But that is mere stupid.
int s = 1;
int b = 2;
s < b; // true // true ... usually, because here it starts, it is actually undefined, facepalm
s++ < b++
s++ < s++; // ok, here we have a point, obviously "it should be false" but it is undefined, and somehow makes sense to be undefined -- for me it makes no sense, in Java this is false
s++ < s; // undefined in C, false in Java. // the original question // is only undefined because some guy thought, using the same variable in an expression involving ++/-- more than once is problematic. // actually they should simple have defined the behaviour. E.g. evaluate from left to right and be done with it
C++ > C;
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.