News for hackers. Stuff that matters.
Re:Zed Shaw on C++ by timr on Thursday July 15, 2010 @10:59PM (#1520063)
"There appear to be a lot of good rants against C++....Are there any good passionate pro C++ versus C arguments?"

By definition, the people who write the "entertaining" rants against C++ have an axe to grind. The people who like C++ just silently use it, and feel no need to write advocacy blog posts for the language. Even if they were to blog about it, it would be about as compelling as someone advocating for their favorite brand of screwdriver. Like it or not, C++ is the incumbent, and it's neither interesting nor fun to read someone advocating for the status quo.

Whenever you find yourself arriving at an opinion about a programming language solely from rants that you read on some dude's blog, please keep in mind that you're probably being most heavily influenced by the very people least qualified to teach you anything useful about the language. The internet is filled with useful articles about C++, but you don't remember those. You remember that Zed Shaw couldn't figure out how const works in C++, and once wrote a funny email about it.

Re:Zed Shaw on C++ by gaius on Friday July 16, 2010 @12:52AM (#1520326)
The people who like C++ just silently use it

Indeed. At my last job, working on trading software, we had around 35 maths or physics PhDs working on a C++ application. A few had personal blogs (cats, children, steam engines, etc) but as far as I am aware no-one there argued on the Internet about which language was best. C++ just doesn't attract self-publicists the way Ruby seems to.

Re:Zed Shaw on C++ by bad_user on Friday July 16, 2010 @03:59AM (#1520598)
> C++ just doesn't attract self-publicists the way Ruby seems to.

That's a cheap shot ... Linus Tolvards is definitely not the Ruby-type.

And his arguments are sound ... for system programming, C is a much better language because it's simpler, lacks magic, making the pieces of code easier to understand without the bigger context, and it's more portable.

And for application-level programming, why would you chose a language without a garbage-collector?

Re:Zed Shaw on C++ by gaius on Friday July 16, 2010 @05:27AM (#1520723)
Perhaps you need to run deterministically without a stop-the-world garbage collector? A) the world is bigger than simple web applications and B) some of us have been doing this for a long time.
Re:Zed Shaw on C++ by bad_user on Friday July 16, 2010 @06:54AM (#1520809)
I wasn't talking about web applications, and modern garbage collectors are not stop-the-world.

Not to mention ... stop-the-world garbage collectors have a good reason for doing what they do. They are defragmenting the memory. You get that for free, when in C++ you would have to deal with hell if your app is doing lots of allocations ... see the shit the Firefox devs had to go through to alleviate the problems of heap fragmentation, and its still a problem.

Re:Zed Shaw on C++ by heresy on Friday July 16, 2010 @08:24AM (#1520895)
Ah, but what, you're using both managed code (C#) and unmanaged code (C++) in the same address space, doing memory intensive work using third party proprietary C++ code that does lots of small allocations?

In 32-bit land, it's welcome to OutOfMemoryException because managed code can't allocate a big enough chunk when returning to C#.

No free lunch :)

Either recycle processes often or reserve big enough contiguous chunks in managed code before calling out to the bad C++ code, no amount of good citizenship in managed code will stop the poorly written native code from fragmenting the hell out of your address space.

Re:Zed Shaw on C++ by gaius on Friday July 16, 2010 @09:37AM (#1521073)
Unfortunately we don't all have the luxury of rewriting all our code in the trendy language du jour.
Re:Zed Shaw on C++ by wglb on Friday July 16, 2010 @07:45AM (#1520853)
Can you give an example of stop-the-world garbage collection?
Re:Zed Shaw on C++ by noss on Friday July 16, 2010 @08:42AM (#1520935)
I've experienced problems with java's concurrent mark and sweep collector. It will stop the world, two times, but two much shorter times than a non-concurrent mark and sweep. So it is definitely an improvement in the duration of the stop-the-world.

The problem tends to be that you need to tune it, and even as you have tuned it, you can not promise that under special condition it will fall back to a more primitive collector since the optimality it was tuned for doesn't hold anymore.

I would never argue giving up garbage collection entirely because of these failure scenarios. I would much rather look at moving some critical part of the code out to a language with manual allocation, and let it perform the latency-sensitive bits.

Another mid-ground is to have separate isolate processes (heaps really) that can be stop-the-world collected without blocking each other. Erlang makes great use of this to accomplish "soft realtime", among other things.

Re:Zed Shaw on C++ by bhousel on Friday July 16, 2010 @08:20AM (#1520886)
Javascript... Yes, even V8.

Side rant: it's part of the reason that my Palm Pre will sometimes just hang for a second at the worst times, such as when I go to answer the phone. :(

Re:Zed Shaw on C++ by silentbicycle on Friday July 16, 2010 @08:23AM (#1520893)
A simple mark & sweep or stop & copy GC. Collectors which are incremental (work in small steps, not one full pass at a time) and/or generational (using several smaller generations, which are collected individually) break up GC pauses into something less disruptive.

For a good overview, read "Uniprocessor Garbage Collection Techniques" by Paul Wilson (check google scholar). Richard Jones's _Garbage Collection: Algorithms for Automatic Dynamic Memory Management_ is more in depth.

Re:Zed Shaw on C++ by kenjackson on Friday July 16, 2010 @03:42PM (#1522284)
If you meant actually existing stop the world GC, the server GC in Microsoft's CLR stops all threads on a processor to do GC.
Re:Zed Shaw on C++ by kvs on Friday July 16, 2010 @08:43AM (#1520937)
Try allocating a very large chunk of memory using a high-level language with garbage collector. It's not always about collection.
Re:Zed Shaw on C++ by eru on Friday July 16, 2010 @10:08AM (#1521182)
Why would you allocate a large chunk of memory, when you are using a garbage collected language?

There may be reasons to want to mix manual and automatic memory management. If you want to do that, there are language that support it. Like D.

Re:Zed Shaw on C++ by kvs on Sunday July 18, 2010 @09:50PM (#1527344)
Not necessarily allocating very large chunks in bulk but umm... Allocating nodes for a million nodes of a graph and subsequently processing them. Java JVM fragments memory heavily. En
Re:Zed Shaw on C++ by tbrownaw on Friday July 16, 2010 @08:50AM (#1520955)
> And for application-level programming, why would you chose a language without a garbage-collector?

Because your code uses some finite resources other than memory, and you don't want the ability to forget to release said resources when you're done with them and they go out of scope.

Re:Zed Shaw on C++ by eru on Friday July 16, 2010 @10:14AM (#1521193)
Why should memory management related to managing other resources. Anyway, you might be interested in The Haskell Disciplined Disciple Compiler (http://www.haskell.org/haskellwiki/DDC) which lets you statically encode resource management rules. (And of course spots garbage collection for memory.)
Re:Zed Shaw on C++ by tbrownaw on Friday July 16, 2010 @07:47PM (#1522957)
Your objects contain/use various resources, such as memory, file descriptors, mutexes, etc. The way to reclaim any of these is to destroy the object, which lets you reclaim all of them. So memory management is very much tied to other resource management, since they both involve the same thing (deciding when to destroy objects you no longer need). Unfortunately not all resources can be collected equally lazily, so memory-centric GC schemes that ignore the requirements of other resources tend to get in the way (and make you do using(){...} or try/finally to make sure your files are closed, instead of allowing for RAII).
Re:Zed Shaw on C++ by eru on Sunday July 18, 2010 @02:30PM (#1526368)
> The way to reclaim any of these is to destroy the object, which lets you reclaim all of them.

I asked why one should mix management of resources, and you answer that one should mix management of resources. But I still don't know why?

Re:Zed Shaw on C++ by tbrownaw on Monday July 19, 2010 @09:28AM (#1528553)
It's more that how the hell do you unmix them (any why would you bother, anyway)?
Re:Zed Shaw on C++ by eru on Tuesday July 20, 2010 @11:58AM (#1532421)
How to unmix: Just e.g. close your files explicitly, but let the memory of the data structures that represent your files be garbage collected normally.

For patterns of usage similar to RAII, Common Lisp uses unwind-protect. I already mentioned Disciplined Disciple Compiler that extends Haskell to give static guarantees for following certain rules for resource management.

Why would you bother: RAII only covers some cases for resource management, and most garbage collectors can take an arbitrary long time to collect an object that's no longer reachable. Which is fine for memory, because memory is fungible, but the attached resources, say mutexen, are not necessarily fungible.

Re:Zed Shaw on C++ by aboodman on Thursday July 15, 2010 @11:35PM (#1520152)
For some concrete examples of the above: WebKit, Chromium, Gecko, and V8 are all C++.

My impression is that there is a very high startup cost with C++ to getting it working on the platforms you want to support and picking the subset that isn't going to screw you. Once you get over the hurdle, the improved memory management (I agree with the post Zed is ranting in response to) starts to pay dividends.

Re:Zed Shaw on C++ by pvdm on Friday July 16, 2010 @12:26AM (#1520279)
V8 is hardly a ringing endorsement for C++. Just sayin.
Re:Zed Shaw on C++ by mace on Friday July 16, 2010 @01:01AM (#1520341)
V8 is ringing endorsement for V8. It is just a well-designed JavaScript virtual machine. It's performant because it compiles JavaScript to native code and uses generational garbase collection.
Re:Zed Shaw on C++ by aboodman on Friday July 16, 2010 @12:57AM (#1520336)
Somebody below said just the opposite. Personally, I find V8 really nice to read and work with.

Which part of it do you not like?

Re:Zed Shaw on C++ by pvdm on Friday July 16, 2010 @03:36PM (#1522258)
Just so we are on the same page. I am refering to the V8 codec not the Javascript engine.
Re:Zed Shaw on C++ by zokier on Friday July 16, 2010 @04:30PM (#1522435)
The WebM one? It is called VP8, not V8.
Re:Zed Shaw on C++ by SkyMarshal on Thursday July 15, 2010 @11:20PM (#1520119)
Good advice generally, but what axes do Zed and Linus have to grind? Sounds like both just think C++ enables too much complexity to be worth the benefits.
Re:Zed Shaw on C++ by zedshaw on Friday July 16, 2010 @01:27AM (#1520377)
It's actually possible to make C++ nice, the Grace library is wonderful. If I ever have to C++ again I'm totally grabbing it and using it. The Grace value types and type safe format operations are just the best thing ever.

My problem though is it's not the right tool for the job. Simply having access to C level APIs doesn't instantly mean your language is awesome at making servers and operating systems. Especially if that same language can't quite figure out what the hell really happens on a copy, or during an exception, or can't make decent strings and data buffers.

Re:Zed Shaw on C++ by kaens on Friday July 16, 2010 @09:26AM (#1521045)
I figure they have the axe of "I used this for a while, and really grew to hate it when I compared it to these other things I used" to grind. Sometimes the technologies you use just make you want to get something off your chest, you know?
Re:Zed Shaw on C++ by wglb on Friday July 16, 2010 @09:48AM (#1521110)
Well, lack of advocacy could indicate lack of awareness of other programming languages.

Don't the boost guys say that now C++ is the most powerful programming language?

Re:Zed Shaw on C++ by lanstein on Thursday July 15, 2010 @11:08PM (#1520089)
> You remember that Zed Shaw couldn't figure out how const works in C++, and once wrote a funny email about it.

source?

Re:Zed Shaw on C++ by timr on Thursday July 15, 2010 @11:21PM (#1520120)
Uh...I'm talking about the content of the post to which this thread is attached, so:

http://librelist.com/browser//mongrel2/2010/7/15/c-verses-c+...

Re:Zed Shaw on C++ by lanstein on Thursday July 15, 2010 @11:28PM (#1520134)
"You'll find crap in C++ like const *const char &, and hell if anyone knows what that really means since even though the pointer to a const to a const reference is consted to hell and back, oh look you can still increment it."

I'm still looking for the part where he doesn't understand how const _works_.

Re:Zed Shaw on C++ by tedunangst on Thursday July 15, 2010 @11:50PM (#1520195)
"const *const char &" is not valid C++ syntax, so I'm pretty sure you can't increment it. Therefore, anyone saying you can increment it doesn't understand it. QED.
Re:Zed Shaw on C++ by houseabsolute on Friday July 16, 2010 @12:23AM (#1520275)
There's this thing called a joke . . . I believe that's waht Zed is making here.
Re:Zed Shaw on C++ by zedshaw on Friday July 16, 2010 @01:08AM (#1520350)
You Sir, win a dollar! I think to make the joke really clear I'd have to add a few more consts and some pointers in there.
Re:Zed Shaw on C++ by slpsys on Friday July 16, 2010 @11:13AM (#1521369)
No, that's just what you'd need to make it compile
Re:Zed Shaw on C++ by steveklabnik on Friday July 16, 2010 @02:24PM (#1521992)
You should head over to Reddit and see how bad that one statement managed to keep up your perma-trolling. It's pretty intense.
Re:Zed Shaw on C++ by timr on Friday July 16, 2010 @12:51AM (#1520322)
Yes, of course. When you agree with the rant, the incorrect parts don't count.
Re:Zed Shaw on C++ by GreenMan on Friday July 16, 2010 @12:45AM (#1520313)
Perhaps you could point out the funny bit.
Re:Zed Shaw on C++ by zedshaw on Friday July 16, 2010 @01:39AM (#1520390)
Oh, you have to read that in the voice of The Comic Book Guy. Then it's fucking hilarious. Here try it:

"You sthee const const &const char[const ] is the proper way to make a thruly safe reference to a conthst char array conthst pointer conthst."

See, prime comedy gold there.

Also, 'cause you guys think the internet should be nothing but a massive academic white paper curated by Knuth, so any amount of hyperbole sends you into a literalism hissy fit.

Re:Zed Shaw on C++ by bitwize on Friday July 16, 2010 @10:36AM (#1521253)
Comic Book Guy doesn't lisp like that; although his virtual twin, Go-Bots Guy from Robot Chicken, does.
Re:Zed Shaw on C++ by sgift on Friday July 16, 2010 @01:59AM (#1520420)
He mocks that you can attach const nearly anywhere in c++ and it seems to do something different. (Note: This is a generalization, an important aspect of many jokes)
Re:Zed Shaw on C++ by mfukar on Friday July 16, 2010 @02:40AM (#1520486)
That explanation was so Sheldon Cooper-y. Kudos.
Re:Zed Shaw on C++ by houseabsolute on Friday July 16, 2010 @09:06PM (#1523076)
You'd have to use C++ to understand.