Why should I have written ZeroMQ in C, not C++ (2012)
91–100 of 147 posts
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#92Earlier quoted context omitted.
If you read part II (the link to it is near the end of the post), you see that one of the things he wanted was intrusive linked lists. From what I have read so far, implementing intrusive lists is not easy in Rust. (If you know of a working intrusive doubly linked list implementation in Rust 1.0 that does not invoke undefined behavior, please tell me; I'd like to know how it should be done.)
I have one here: https://github.com/dschatzberg/intrusive It can be used in a freestanding (nostd) environment such as a kernel. It uses unsafe code but provides a safe interface. The primary technique is to embed the type that is iterated over in a larger struct which contains the links. This way I can give out references to the inner type without fear of invalidating the iterator.
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#93This seems to be a failure to understand when exceptions and when error codes are to be used. I'm just starting a big infrastructure project that needs to be high uptime and distributed across a large number of machines, and I'm doing it in C++ because I know I'd never get it working in anything else. Let's take one specific example -- connecting to a remote host. The loop that goes through the DNS returned IP number…
E.g you have function called connect() then it should return something like a state object with a connection instance or an error indicator such as {err:dns_fail, dns_servers:[..],hostname:".."}
Otoh, if you were writing a one-of script for scraping a web site then you don't care about fault tolerance and then connection failures are exceptional events so throwing on them becomes ok.
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#94As usual, this guy doesn't understand how to use C++. Nobody with any significant C++ experience puts error generating code in constructors. Once I saw that I stopped reading.
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#95Earlier quoted context omitted.
The pitfalls of C++ that I've seen are mostly the things people build with the safe alternatives.
Could you give an example?
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#96Exception throwing is the goto of 21st century. The article's examples aren't the worst, it's common seeing exceptions for business rules in Java/.NET land.
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#97As usual, this guy doesn't understand how to use C++. Nobody with any significant C++ experience puts error generating code in constructors. Once I saw that I stopped reading.
How does a proper C++ constructor report errors?
First I can think of: don't create situations where error can happen. Compile with exceptions turned off. Out of memory? Terminate the process/thread.
Another: create your objects using some factory, make constructor empty and initialize class by said factory once instance is already created (perhaps recursively instantiating its members). This way all error generating code will be moved outside of constructor.
See how Google approach it: https://google-styleguide.googlecode.com/svn/trunk/cppguide....
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#98Earlier quoted context omitted.
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.)
EDIT: Said Wikipedia page was sufficiently detailed for me to implement a Brainfuck -> MSIL compiler without additional external references, which I was able to verify worked with a Mandelbrot renderer.
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#99Earlier quoted context omitted.
How does a proper C++ constructor report errors?
Several solutions. First I can think of: don't create situations where error can happen. Compile with exceptions turned off. Out of memory? Terminate the process/thread. Another: create your objects using some factory, make constructor empty and initialize class by said factory once instance is already created (perhaps recursively instantiating its members). This way all error generating code will be moved outside of…
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#100Earlier quoted context omitted.
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.
"Number of pages in specification" is a rather useless metric to use to compare languages, since there are so many variables. And not just things like point size or margins or what have you, but the contents themselves vary. Some specifications include an EBNF grammar, others may try to describe it via natural-language rules, and others may just say "see the reference implementation". Some specifications include docu…
How would you prefer to compare language sizes? Gut feel? Surely that's even worse.
I'll certainly admit that - like LOC measurements - it's a metric one can't take too seriously on it's own. On the other hand, it's a useful starting point for discussing said variables.
For example, when I was eyeballing the Javascript standard (I've already read the C++ standard a decent bit), I saw it (like C++'s) defines a grammar, and includes some core library bits (e.g. the Object type.) On the other hand, I didn't see the full browser DOM API you'd use when writing most Javascript - but then again, you don't see any modern graphics or UI widget APIs in the C++ standard either.
This was enough to convince me that they were comparable enough for an orders-of-magnitude comparison, at least. My gut reaction was that C++'s standard might be more detailed - but that'd be biased in my favor, further undermining the argument that Javascript is significantly smaller than C++.
> I can write a 10,000-page standard for Scheme if you hire me to.
But can you find a 10,000 page standard, for any language? Eventually everyone hits a limit to what they consider worthwhile to write, short of perverse incentives.