4 ms·
> To be fair: very few C++ applications are limited by exception performance, it's a feature that's very much out of favor at the moment. It is distressing tha
by gumby 7y ago
> To be fair: very few C++ applications are limited by exception performance, it's a feature that's very much out of favor at the moment.
It is distressing that Sutter's survey showed that half the respondents had to disable exceptions for part of all the code. I've often heard the argument "well google's coding standard prohibits exceptions" which is bizarre, as google's standard says "exceptions are great but we have some legacy code that can't use them, so we're stuck"
The biggest argument seems to be that they are expensive, which is crazy because there's no cost if you don't raise one and if you do you're already in trouble and generally have plenty of time to deal with it (this is different from, say, Lisp signalling which not only permits continuing (!) but is on theory supposed to be common. Probably a mistake in retrospect). But they allow you to make the uncommon stuff uncommon (as opposed to error codes which must be sprayed like shrapnel through your code).
There are two legit arguments against exceptions: one is when you are constrained in space (e.g. embedded systems) and/or time (hard realtime systems that need predictable timing, even if it is slower). The other is a philosophical argument that it embodies a second, parallel flow of control. Since C++'s exception system is an error system only, and since destructors are run automatically, it's hard for me to find this second argument convincing.
- pjmlp 7y agoSometimes I miss C++'s flexibility from the managed languages that usually use, then I remember that the community is now driven by the performance at all costs crowd, without exceptions, RTTI, STL and let that thought go. That is not the C++ I enjoy using, rather the language I got to love via Turbo Vision, OWL, VCL, MFC, Qt, which is not what drives the language nowadays.
- barrkel 7y agoYeah, when the moderates move out, the hard core that remains swings towards what makes C++ unique, and that's not general purpose application programming and language features that support it.
- pjmlp 7y agoWhich looking from its use in mainstream OS SDKs means drivers, composition engine, shaders and real time audio engines, the SQL of systems programming, kind of.
- gumby 7y agoI wouldn’t characterize that group as “the community”. True there are a lot of such people, mostly clustered In the game industry where superstition is rife. Take a look At C++ (or c++ 20!) as if it were a brand new language you’d never seen before and forgetting that it’s name includes “c”. That language is a pretty clean, expressive and straightforward language IMHO. I like programming in it. It’s not claiming it’s unicorns farting rainbows, but it’s definitely pretty good.
- pjmlp 7y agoIf the community wasn't busy discussing those issues, and constexpr of all things, we would already have reflection, with a concurrency and networking story that isn't put to shame for what Java 5 already had, let alone in modern managed languages. Yeah, if everyone plays ball, it might come in 5 years from now, assuming C++23 gets done on time, plus the compiler support stabilization. Right now SG14 seems to drive some of those decisions, at least from outside.
- gumby 7y agoThose are important issues and people who care about them work on them and come to committee meetings. There is less consensus on the concurrency and networking side which I also find frustrating but as I’m not pushing those balls forward I can’t complain. I do think at least that the direction they’re moving in is a fruitful one. The standard can move quickly: consider formatted output which lingered unchanged with a broken model but was rapidly reformed when someone with a good model and implementation was encouraged to come forward. Admittedly a smaller topic than concurrency or networking!
- pjmlp 7y agoRight now, the way I see it, I rather help the managed languages I work on reach the point where binding to C++ is kind of last option when nothing else helps. The other language communities manage to drive language progress over the Internet, which apparently ISO has yet to get in touch how it goes.
- detaro 7y agoThat seems like a misconception about the driving forces behind C++ today.
- pjmlp 7y agoNot when one looks into the recent ABI discussions.
- gumby 7y agoYou mean a refusal to break ABI?
- pjmlp 7y agoYes, as means to achieve performance improvements that aren't that relevant to average Joe C++ dev. The one doing application stuff in Qt, MFC, wxWidgets. Or those like myself, where C++ only matters as means to implement native bindings to system libraries, or GPGPU shading languages based on C++.
- gumby 7y agoWell I can afford a complete ABI break (complete) given the kind of code I work on. Most people cannot. Binary incompatibilities are very hard for most people to manage. So I would benefit from any number of abi-breaking proposals but can understand the committees reticence.
- ptsneves 7y agoTo be honest it is hard to not break ABI. First you almost surely need to use PImpl and second hope a compiler upgrade keeps the standard library ABI compatible(eg ABI version flags in gcc). For a good look at how hard this is look at breakages in gentoo. This is basically the reason the greater open source community has their libraries in C: stable ABI, and consequently language bindings. Unless i am missing something big the concept of ABI stability in C++ is an art and requires a lot of discipline. At the top of my head only KDE was somehow successful but have a look at their guidelines[1]: again it requires a lot t of discipline. Also I believe that ABI compatibility with binaries compiled with different compilers also is complicated by things like name mangling conventions which are not common between compilers. There are so many things that can go wrong that the people i know that rely on ABI compatibility in C++ make a diff of their objdump output a ci test. Sometimes they get more paranoid and send me an assembly diff when they are suspicious(a compiler upgeade generated different jump prolog:) ). Ridiculous compared to the price of just running the compile again. The fact we control the whole machine's os image even makes it harder to understand... Oh man the pain I have... My apologies if my text is weird but proof reading in a phone is hard. [1]https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B https://community.kde.org/Policies/Binary_Compatibility_Issu...
- keldaris 7y ago> which is crazy because there's no cost if you don't raise one This is just false in the general case. The presence (potential or actual) of exceptions often just serves as an optimization barrier in current compilers. That's not to even invoke bizarre but not infrequent issues like this [1]. I too have had codebases that miraculously sped up upon disabling exceptions despite not throwing anything. Identifying the exact causes of these situations is hard and typically not done, because it's far easier to just add a compiler switch and pretend there are no exceptions in C++ and get back to work. Many people in performance sensitive domains just don't find it remotely worthwhile to care about features that have these sorts of difficult to predict and debug costs. When your workflow already consists of writing highly explicit, simple to reason about code that you frequently inspect in disassembled form, exceptions (and RTTI for a host of obvious reasons) are the last thing you'd want to enable. At best it's just extraneous noise in the assembly, at worst you take a sizable perf hit and have no idea why. [1] https://twitter.com/timsweeneyepic/status/1223077404660371456?lang=en https://twitter.com/timsweeneyepic/status/122307740466037145...
- mehrdadn 7y agoWe need sample code for stuff like this so they can be referred back to as canonical examples. Frequently asserted C++ misconceptions?
- throwaway17_17 7y agoThis description of C++ usage you gave: A workflow consisting of writing highly explicit, simple to reason about code that you frequently inspect in disassembled form Is possibly the most descriptive and succinct description of my coding practice. I really like this formulation and I am going to shamelessly steal it in the future, repeatedly.
- ses1984 7y agoI'm curious what features of c++ you use and like if you would prefer it over c for this use case.
- 7y ago
- fpoling 7y agoWriting exceptions-safe code is not free in itself. Surely one can do it, but it requires more mental energy to write and even more efforts to review the code.
- mratsim 7y agoYou shouldn't use exceptions in cryptography as well. There are constant-time concerns and dumping sensitive data in the heap concerns at the very least.