4 ms·
Can you explain why exceptions and operator overloading are "idiotic" things? Are you from the Go school of boilerplate-error-checking-code design, or something
by pmarreck 9y ago
Can you explain why exceptions and operator overloading are "idiotic" things? Are you from the Go school of boilerplate-error-checking-code design, or something?
- adrift 9y agoSum types are the new trend.
- dmitrygr 9y agoexceptions because in embedded contexts they may not always be a good idea (and C targets such contexts). overloading because it is too easy to abuse and as such it gets abused a lot by those who do not know better. The rest of us are then stuck decoding what the hell "operator +" means when applied to a "serial port driver" object
- UncleMeat 9y agoExceptions work great in garbage collected languages. Reasoning about exceptional control flow w.r.t. manual memory management is a total nightmare.
- sedachv 9y ago> Reasoning about exceptional control flow w.r.t. manual memory management is a total nightmare. Exceptions make manual memory management easier because a proper exception system has unwind-protect[1]. Exceptions are just movements up the stack - exceptions combine naturally with dynamic scoping for memory allocation (memory regions/pools). This kind of memory management was used in some Lisp systems in the 1980s, and made its way into C++ in the form of RAII. By extending the compiler you can add further memory management conveniences like smart pointers to this scheme. Now if you want to talk about something that actually makes manual memory management a total nightmare, look at the OP's suggestion for adding closures to C. [1] http://www.lispworks.com/documentation/HyperSpec/Body/s_unwind.htm http://www.lispworks.com/documentation/HyperSpec/Body/s_unwi...
- tomsmeding 9y agoC does not have RAII-like memory management in any way. Exceptions work beautifully with memory management like that, but if it's not there, you can't just say it should work because memory management should work like that. So basically you're saying, before adding exceptions, add RAII-like memory management, and then actually add exceptions. I like both features, but am not sure how you'd wedge RAII into C. Any ideas on that?
- BruceIV 9y ago[On the Cforall team] For what it's worth, one of the features Cforall adds to C is RAII. The exception implementation isn't done yet, but it's waiting on (limited) run-time type information, it already respects RAII.
- seabrookmx 9y agoI might have missed this.. but how is Cforall implemented? A new GCC or LLVM frontend, or is it a transpiles-to-C implementation ala. Nim or Vala?
- BruceIV 9y agoTranspiles-to-(GNU-)C -- it was first written before LLVM, if we were starting the project today it would likely be a Clang fork.
- seabrookmx 9y agoClang harks back to 2007 and LLVM 2003.. is this a research project that was recently taken back up? I was curious about the implementation because I've had rough experiences with Vala and Nim's approach. Unlike with "transpiles-to-js" languages, transpiling to C has some tooling gaps (debugging being the big one). I admittedly don't have a ton of experience with either language but I couldn't find a plugin that gave me a step-through debugger for something like CLion or VS Code. You can debug the C output directly but this will turn off newcomers and assumes the C output is clean.
- maxxxxx 9y agoGood point.