Live data from Hacker News

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

250bpm.com

11–20 of 170 posts

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

#11

Earlier quoted context omitted.

My understanding: Pick zmq if you want something safe and battle-tested with good client library support. Pick nng if you want to be at the forefront of new tech or need some of its unique features over zmq ( https://nanomsg.org/documentation-zeromq.html ). Performance-wise nng still seems like it's inferior to zmq because it's not as heavily optimized. There are lots of performance-related unresolved Github issues.…

Would you say either is something you would put in a decently scaled production system?

zmq is used in a many large-scale production systems. It's definitely safe to use and has been stable for a long time.

nng is relatively new. Personally I have not had any issues with it. I'd look through the open Github issues and see if you can find any dealbreakers. The deciding factor may be language/library support. I would also classify it as "safe to use in production" though.

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

#12
This article is simultaneously both obsolete and completely current.

Obsolete in that the C++ committee has addressed almost all of the issues raised (e.g. constructor semantics, xception semantics et al) though the discussion of site-of-error/handling-of-error continues unabated.

Later versions of C++ (17and 20) are powerful and expressive systems programming languages that aren’t like the object-oriented messes of old.

The reason that this article remains completely current is that I suspect the majority, and likely vast majority, of C++ is still written in C++03/C++11 and full of dreadful issues like the ones in the article.

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

#13
I was trying to figure out if this was satire.

C++ gives you strictly more tools, particularly for guaranteeing reliability, and they're all optional.

What particularly laughable here is the split ctor/init pattern is allegedly driving them towards C, whereas C doesn't even give you dtors! If you're forgetting your init calls, are you really telling me you're not going to forget your destructor call? There are plenty of approaches besides split-init anyway, but it feels like the author feels pulled towards C for other reasons, and is looking for reasoning after the fact. C is not a magic bullet for simpler code!

C is useful for solving social problems with deciding what features and patterns of C++ to use, if you've given up on code review and style guidelines. If you decide that's you, good luck! You'll need it.

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

#14
post #13

I was trying to figure out if this was satire. C++ gives you strictly more tools, particularly for guaranteeing reliability, and they're all optional. What particularly laughable here is the split ctor/init pattern is allegedly driving them towards C, whereas C doesn't even give you dtors! If you're forgetting your init calls, are you really telling me you're not going to forget your destructor call? There are plenty…

One good alternative to ctor+init() is a static factory method with a private ctor. It's just as simple as in C.

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

#15

When I did C++ I always ended up using a very small subset of it. No exceptions, no inheritance besides a few interfaces. But in general I agree with his point. There are a few things C could improve though. One would be a way to automatically clean up resources. Maybe something like “defer” in Go. I wonder if templates would fit into C. STL is super useful. A real string type would be good too.

That new dialect of C exists, and it's called C++!

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

#17

When I did C++ I always ended up using a very small subset of it. No exceptions, no inheritance besides a few interfaces. But in general I agree with his point. There are a few things C could improve though. One would be a way to automatically clean up resources. Maybe something like “defer” in Go. I wonder if templates would fit into C. STL is super useful. A real string type would be good too.

[deleted]

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

#18
Author asserts that "The decoupling between raising of the exception and handling it, that makes avoiding failures so easy in C++, makes it virtually impossible to guarantee that the program never runs info undefined behaviour." (and all the woes he encounters afterwards stems from trying to avoid exceptions due to that assertion). But that is not my experience at all. Exceptions are much more reliable than error codes - there will always be a case where you forget to propagate an error you got, but you cannot "forget" to propagate an exception... (and if you do, you can always run a debugger post-mortem to get a nice stacktrace of where the exception was thrown - `coredumpctl gdb` is a super nice tool for that on Linux systems with systemd). And languages without exceptions just end up with a galore of `if err != nil { panic(err); }` or similar horrors...

Also, regarding "compiler is likely to produce more efficient code.", benchmarks have shown that exceptions are generally faster : http://nibblestew.blogspot.com/2017/01/measuring-execution-p...

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

#19

When I did C++ I always ended up using a very small subset of it. No exceptions, no inheritance besides a few interfaces. But in general I agree with his point. There are a few things C could improve though. One would be a way to automatically clean up resources. Maybe something like “defer” in Go. I wonder if templates would fit into C. STL is super useful. A real string type would be good too.

Yeah, I know what you mean by using a small subset of C++.

To be perfectly honest (and I'm just a hobbyist who writes simple tools for myself... so I can get away with this a little easier than a professional could) but I got really frustrated when I was learning C++ and almost decided it wasn't worth it. Then I decided that I'd basically just treat C++ as C with strings, classes, and a few nifty, ready-made containers and useful algorithms. And doing this allowed me to enjoy the language quite a bit and do some very fun and useful things in it, all without becoming overwhelmed by its size/complexity. But again... this is as a hobbyist, nothing more.

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

#20

When I did C++ I always ended up using a very small subset of it. No exceptions, no inheritance besides a few interfaces. But in general I agree with his point. There are a few things C could improve though. One would be a way to automatically clean up resources. Maybe something like “defer” in Go. I wonder if templates would fit into C. STL is super useful. A real string type would be good too.

There was a language called clay that was basically C with templates, operators, destructors and move semantics (with better syntax). It produced C ABI compatible compilation units and could pretty much slide into a C project. It used llvm but has been defunct for a long time. It is a shame because I think a lot could have been learned from people at least looking at it before coming up with their new llvm based native languages.
Post reply on HN