Putting Thoughts Together
Jun. 18th, 2008 11:56 amSomething that I have said a number of times is that nowadays, there is almost no reason to pick C over C++ for a new project (one of the few reasons that I know of involve writing execute-in-place code for very small embedded systems, so no, GNOME definitely doesn't qualify!). Worst case, you write exactly the same code you'd have written in C, just avoiding using the new keywords as identifiers, and you then get better warnings (remember, no templates would be involved) and stricter type checking (no more silent casting of void* to pointers to random things! No more setting enums from any random integral junk you happen to have at hand! No more forgetting a header and using a function with the wrong parameters!).
But these slides really put it together, from someone who's generally thought of as neither insane or dumb. Doesn't really have much to do with GCC in particular, other than just the general fact that this is becoming so obvious that even GCC might be making the switch...
Edit: This article by Amit Patel is also pretty good on this subject.
But these slides really put it together, from someone who's generally thought of as neither insane or dumb. Doesn't really have much to do with GCC in particular, other than just the general fact that this is becoming so obvious that even GCC might be making the switch...
Edit: This article by Amit Patel is also pretty good on this subject.
no subject
Date: 2008-06-18 04:13 pm (UTC)no subject
Date: 2008-06-18 04:14 pm (UTC)no subject
Date: 2008-06-18 04:18 pm (UTC)no subject
Date: 2008-06-18 04:22 pm (UTC)no subject
Date: 2008-06-18 04:23 pm (UTC)no subject
Date: 2008-06-18 04:26 pm (UTC)no subject
Date: 2008-06-18 04:20 pm (UTC)no subject
Date: 2008-06-18 04:25 pm (UTC)http://www.figuiere.net/hub/blog/?2008/03/23/604-new-gnu-linker
And as for key developers, I meant "other than him", which means a larger inertia. Something required to introduce such a major change in the code base.
no subject
Date: 2008-06-19 01:46 am (UTC)no subject
Date: 2008-06-19 02:22 am (UTC)Incidentally, he's credited with coming up with the "don't be evil" motto. He's also the author of Solar Realms Elite, an awesome classic BBS door game which many of my friends wasted their time on.
no subject
Date: 2008-06-19 02:26 am (UTC)no subject
Date: 2008-06-19 02:55 am (UTC)What I personally like is that if I have a deep Unix question, I could ask Ken. If I have a hard C question, I could ask Brian. If I have a trick AWK question, I could ask any of Alfred, Peter, or (again) Brian. If it's about the inner workings of Mac OS X, Amit's the man, when it's more of a Linux thing, then Andrew's available (although I have to admit that just standing up in building 43 and stating your question out loud works just as well). Jeff Dean and Rob Pike are so smart, if they start thinking hard at the same time, time and space bends. On my second week, someone asked me if I knew whether we did XYZ, and my response was that I don't think XYZ is even possible, but I thought the same about ABC a week ago, and it turns out we've been doing it for a while!
It's just a plain ridiculous place. It's so crazy, they negociated my salary up. That's how wacky it is. Nothing makes any sense here.
no subject
Date: 2008-06-19 02:58 am (UTC)no subject
Date: 2008-06-19 03:09 am (UTC)no subject
Date: 2008-07-15 01:34 am (UTC)I think the real proof that C++ is less than it should be is that its proponents are always dishonest in this way....
no subject
Date: 2008-07-15 02:32 am (UTC)I'm personally not claiming it's a C superset. If it were, obviously, any C program would compile straight off, but it doesn't. It just so happens that the bits that don't compile often are the bits that I didn't want to compile in the first place (any random integral junk passing off for my enum_t? I think not!).
You seem to refer to the bloat of the feature set, and personally, as long as compilation times do not suffer too much (and compiling a C-style program is pretty much the same), I'm personally fine with features I don't use existing. I'm pretty open minded when it comes to allowing difference to exist.
What I do find annoying is your last point. Complexity is bad, and you probably had something like argument dependent name lookup here, which is admittedly kind of nuts. I understand it was borne out of practicality, but eww.
But I have a really hard time believing that there's a significant number of practical programs that can be expressed in C and cannot be expressed in an equivalent way in C++.
The GNOME people, in particular, seem to be extremely hypocritical, as they are in the process of inventing their own object-oriented language that compiles to C. That kind of reminds me of Cfront, personally. Next, they'll be all happy about compiling straight to assembly, and will be talking of adding generics, I can see it right from here. You're quite right in that we could do much better, but if one is going to reinvent a crappy version of C++, bloody hell, C++ is right here, use it and shut up already...
no subject
Date: 2008-07-15 05:24 am (UTC)As to bloat, no, I was thinking of memory consumption. C++ is, contrary to initial expectation, a terrible enemy of code reuse, especially at the object level.
Finally, or perhaps initially, as regards void *: my point was that if you don't want the automatic conversion property, you are free not to code with void *! It's merely a kind of type conversion that is bound to the data instead of to the code, in case you want that. Certainly the language would, in the abstract, be better off without it, but the alternative would be parametric types and a distinct type for slabs of raw storage. That would be yummy, but C doesn't have it and nor does C++.
no subject
Date: 2008-07-15 02:47 pm (UTC)When you get templates in there, though, yeah, it's not pretty.
It certainly is a solid case of "worse is better", but my opinion is that C++ is well within what C can do, plus some other stuff which I can use or not, to my fancy, so it's just like having more tools in the toolbox.
If it doesn't let code that calls a function but forgot to include its header (and therefore lets you call it with whatever you please!) compile as well, then so much the better. There's some compiler flag to make GCC behave in a similar way, but that's just silly.
no subject
Date: 2008-07-15 05:05 pm (UTC)As I say, the real objection to C++ is the extra debugging burden. When my C code compiles clean, it is normally correct. With C++, I haven't found the same thing. Now, maybe you have a point, in that if I were really determined never to use constructors, for example, then I wouldn't get perverse conversion chains. If I were really determined not to use templates, I wouldn't get strange name captures and compiler-specific failures to expand. If I were really determined not to use visibility control, I wouldn't have to deal with the rules about visibility from nested scope. But then, why am I not just using C, which doesn't have these flaws?
The problem is that none of the ways in which C++ extends C is really of high enough quality to motivate its use, and they all seem to introduce exposures in terms of code that does not do what it appears to do, ones that are often really hard to debug. I would rather just not have them present.
Perhaps what it comes down to is this: to me, programming is a sufficiently intellectual activity that I want to minimise the extraneous distractions and unnecessary complexities. The fact that writing C++ requires more non-problem-oriented concentration than writing Perl (and that is my experience) just amazes me, and is just not acceptable.
no subject
Date: 2008-07-15 06:00 pm (UTC)You don't have to be all that determined to not use templates, not use constructors and so on. I find that just sitting in front of the monitor and doing nothing accomplishes that, which is not very much determination at all!
In a way, what I'm saying is related to turning on all the warnings: with GCC, "-x c++" is a fine diagnostic option to turn on for your C code. There's a few valid things that could be spurious (like a variable named "class" or something like that), but that particular cost is minimal compared to the return I get for it.
I've had cases where someone pretty smart had been debugging C code for a couple of days, and I found the problem in minutes that way. They were trivial buglets, but they were also buried in thousands of lines of code, which the compiler is much better suited to groveling over than even the smartest human.
I don't have a problem ignoring extra features, if they have no cost when left unused, I think that's the main difference in opinion that we have.
no subject
Date: 2008-07-15 06:08 pm (UTC)