Live data from Hacker News

Why should I have written ZeroMQ in C, not C++ (2012)

250bpm.com

41–50 of 147 posts

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#41

Earlier quoted context omitted.

Good luck finding a language out there that doesn't have pitfalls.

To be fair I think most languages don't have pitfalls as defaults in the C++ sense :D

The amount of things in C++ to avoid practically constitute a language by itself.

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#42
post #35

These and many other pitfalls are all discussed in detail in the C++ FQA Lite: http://yosefk.com/c++fqa/exceptions.html#fqa-17.1 http://yosefk.com/c++fqa/ctors.html#fqa-10.17 http://yosefk.com/c++fqa/exceptions.html#fqa-17.3 The FQA helped my crystallize a lot of the reasons I hated C++. Even if you like C++, it's a good idea to understand the FQA's arguments, for the same reason people play devil's advocate.

And even so, a lot of very senior C++ users will disagree with the FQA's recommendations.

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#43
From my experience, if you need to write many exception handlers then you have a problem in your design as you are using exceptions where you should have used explicit control flow. There is nothing fundamentally wrong with the exceptions and they are used in most modern languages, not only C++.

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#44
post #24
post #13

Earlier quoted context omitted.

Multiple return values is now handled in C++ with tuples and std::tie.

While it works, it would be better if multiple return types were supported natively by the C++ language precisely because of this: #ifdef _WIN32 # ifdef EXPORTING # define DECL __declspec(dllexport) # define STORAGE # else # define DECL __declspec(dllimport) # define STORAGE extern # endif #else # define DECL # define STORAGE #endif // For every return tuple type actually used: STORAGE template class DECL std::tuple…

> "which STL did this shared object link against"

This alone makes exporting STL objects pretty much impossible in a sizable cross-platform project, in my experience.

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#45
post #20

Earlier quoted context omitted.

Yes, it shares that 'feature' in common with JavaScript.

No, actually, it doesn't. C++ is a huge language, javascript is a relativly small one. I know it's funny to compare the size of "Javascript the good parts" with "Javascript the definitive guide", but that's can be attributed to writing style more than percentage of language covered.

> No, actually, it doesn't.

Perhaps less in what features to avoid, but there's plenty of hidden gotchas to avoid in JavaScript still.

https://www.youtube.com/watch?v=et8xNAc2ic8 https://dorey.github.io/JavaScript-Equality-Table/

> C++ is a huge language, javascript is a relativly small one.

C++'s ISO/IEC 14882:2003 weighs in at 786 pages, compared to ECMA-262 (5.1 Edition)'s 258 pages (measuring by PDF reader). A ~3x difference, but not quite the order of magnitude I'd expect from huge vs small.

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#46
post #35

These and many other pitfalls are all discussed in detail in the C++ FQA Lite: http://yosefk.com/c++fqa/exceptions.html#fqa-17.1 http://yosefk.com/c++fqa/ctors.html#fqa-10.17 http://yosefk.com/c++fqa/exceptions.html#fqa-17.3 The FQA helped my crystallize a lot of the reasons I hated C++. Even if you like C++, it's a good idea to understand the FQA's arguments, for the same reason people play devil's advocate.

And even so, a lot of very senior C++ users will disagree with the FQA's recommendations.

Even though I disagree with many of the FQA's recommendations, at least it describes their rationale. Providing the arguments behind the alternative viewpoint allows for an informed choice.

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#47

Interesting article. So, more confirmation C++ is inferior for writing predictable or high performance applications. I actually see an opportunity for a C-compatible or C-competitive systems language here to beat C++ at its own game. Zero-cost abstractions plus solving C++'s specific problems, painless C FFI, and compilation to C (or LLVM) to leverage their compilers. Might make a nice combo. I doubt we'll see much t…

While it's not a C-like language, Nim [0] is an interesting take on how to do a "systems" language, with a very interesting GC story (and a way to turn it off altogether or manually manage memory when required) and amazing C FFI -- I'm not much of a C programmer, but even I've managed to integrate C libraries into Nim. Still not quite what you're after though; I think more something like Go, with manual memory management would be nicer. A "modern C", that takes learnings from C++'s successes and failures, but keeps C's strengths.

Rust [1], basically!

[0] http://nim-lang.org/

[1] http://www.rust-lang.org/

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#48
post #4

This actually sounds like an argument for why he should've used a smaller subset (or different) of C++. For example: make all constructors private and empty and use public static factory methods for manufacturing new instances. Now the factory can fail, and return an error to boot. Similarly, ditch C++ exceptions and introduce the notion of a status object that methods return. You always have the option of C-style se…

And so I will continue to avoid C++ because I'm not a master and will not avoid the many pitfals, and I want to get things done, not become a master of C++.

C with classes is undervalued, and templates are overvalued, IMO.

Just switching compilers makes the C code more robust.

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#49

Earlier quoted context omitted.

No, actually, it doesn't. C++ is a huge language, javascript is a relativly small one. I know it's funny to compare the size of "Javascript the good parts" with "Javascript the definitive guide", but that's can be attributed to writing style more than percentage of language covered.

> No, actually, it doesn't. Perhaps less in what features to avoid, but there's plenty of hidden gotchas to avoid in JavaScript still. https://www.youtube.com/watch?v=et8xNAc2ic8 https://dorey.github.io/JavaScript-Equality-Table/ > C++ is a huge language, javascript is a relativly small one. C++'s ISO/IEC 14882:2003 weighs in at 786 pages, compared to ECMA-262 (5.1 Edition)'s 258 pages (measuring by PDF reader). A ~3…

And we share 50% of our DNA with a tree...

That's not meant to be snarky, but what's is the minimum size of a language spec? I don't know the answer, but I'd think the delta over that would be the better comparison. For example if you can't really spec a language in less than 200 pages then C++'s spec is more like 10 times as big as JavaScript.

Re: Why should I have written ZeroMQ in C, not C++ (2012)

#50

Interesting article. So, more confirmation C++ is inferior for writing predictable or high performance applications. I actually see an opportunity for a C-compatible or C-competitive systems language here to beat C++ at its own game. Zero-cost abstractions plus solving C++'s specific problems, painless C FFI, and compilation to C (or LLVM) to leverage their compilers. Might make a nice combo. I doubt we'll see much t…

D.

It exists already, only needs more libraries and more users.

Yes, they are removing the GC dependency from the standard library.

Post reply on HN