Live data from Hacker News

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

250bpm.com

51–60 of 147 posts

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

#51
post #36

Earlier quoted context omitted.

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++.

Actually avoiding C++ pitfalls is not that difficult as most of them come from C: manual memory management, macros, varargs, unsafe casts. In fact C++ provides safe alternatives to many of the unsafe C constructs, so if you stick to them you are fine.

The pitfalls of C++ that I've seen are mostly the things people build with the safe alternatives.

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

#52
post #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 manage…

I saw it a while back and thought "another toy language that won't deliver." Reading the FAQ, the author quoted as inspiration every alternative language I mentioned in this thread lol. He's done his homework. And the features and compatibility have gotten quite impressive since first release... likely due to him using it to build itself (productivity advantage). And under a MIT license.

I appreciate you bringing it back to my attention. It's worth someone evaluating thoroughly against C and C++ for systems programming (incl OS) in terms of performance and maintenance. Not sure if I can squeeze time in but I'll suggest that to others at least.

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

#53

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…

[deleted]

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

#54

Earlier quoted context omitted.

> 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.

Scheme has the smallest (useful) language specs that I know of. For example, R5RS is 48 pages (44 if you exclude the back matter.)

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

#55
post #20
post #16

Earlier quoted context omitted.

What a strange language, that so much sage wisdom involves what parts of it you shouldn't use. (Former C++ programmer, a long time ago, before the "don't use these parts" advice became a thing.)

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

The big thing javascript has going for it are the browser's dev tools, though.

I've done both and hunting things down in chrome's dev tools is orders of magnitude easier than figuring out what is going on in your c++.

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

#56

Earlier quoted context omitted.

> 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.

The scheme R5RS standard is 50 pages, and is considered quite small for any real language. The Haskell 2010 Language Report is 239 pages. The Forth ANSI standard is 220 pages and is a seemingly simple language.

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

#57

Earlier quoted context omitted.

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.

Another amusing part is that it's a moving target - some parts of the language actually got better with implementations and spec improvements - so there's a large number of people avoiding useful features on outdated practices (they learned "don't use X" without the reasoning behind it :) )

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

#58

Earlier quoted context omitted.

Objective-C: "You messaged?" I believe that Objective C is a pretty good (yes, it's getting old) combination of C compatibility with object oriented features as well. The 2 big downsides IMO are: (1) essentially restricted to Apple ecosystem and (2) the syntax keeps a lot of developers away.

My quick perusal of online links show that Objective-C is slower than C++, maybe due to its dynamic typing. It has the C compatibility and basic OOP. Yet, my idea was a language like this which is faster than C++. Maybe a statically typed version of Objective-C would do?

The OO parts of Objective-C will likely be slower than the OO parts of C++ in many cases. There are a few places where ObjC can help even the score on performance. Typically ObjC objects are not copied (cloned). Normal usage (within a collection, ivars, etc.) is with reference counting. Prior to C++11 (shared_ptr, unique_ptr, etc.), there wasn't a good way within the language itself to track object ownership without having to make object copies.

Since C++ and ObjC are both (essentially) supersets of C, you can always mix however much (or little) of plain C that you want. Everything about OO in ObjC is very dynamic. It allows you to do some very cool/flexible/unsafe/unwise things.

In my opinion, that where the tradeoffs start showing up. Flexibility, runtime speed, nice abstractions, development speed, code complexity, etc. Really difficult, if not impossible, to have them all at once.

Despite the unusual looking OO syntax of ObjC, overall it's a pretty simple language given the power it provides. Once you get acclimated to looking at its syntax, I'll even dare say that it's much easier to read and understand than many other languages.

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

#59
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.

I was really struggling to pick up c++, and when I read the FQA I had a 'it's not me, it's you' moment.

I don't detest the language the way he does, but the FQA really resonated with me. There's no one feature that kills the language, but it seems like everywhere you go you run into a feature that feels like it was designed to trip you up, and it gets tiring after a while.

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

#60
post #36

Earlier quoted context omitted.

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++.

Actually avoiding C++ pitfalls is not that difficult as most of them come from C: manual memory management, macros, varargs, unsafe casts. In fact C++ provides safe alternatives to many of the unsafe C constructs, so if you stick to them you are fine.

[deleted]
Post reply on HN