News for hackers. Stuff that matters.
Re:C++ Frequently Questioned Answers by Hexstream on Monday May 11, 2009 @11:19AM (#603612)
I agree with your first point.

However, I'll have to very strongly disagree with "C++ has damn powerful meta-language facilities no other language of any level has". C++ actually has terrible support for meta-language facilities.

It is inconceivable in my mind that C++'s support for that is anywhere near something like Common Lisp, so forget about it being the best in that respect. I'd love to know what parts of C++ are great meta-language facilities. If you say C++ macros I'll have to laugh. Hard.

</smuglispweenie>

Re:C++ Frequently Questioned Answers by william-newman on Monday May 11, 2009 @12:09PM (#603710)
Stepanov (i.e., Mr. C++ Standard Template Library) has said some comparably strong things about the expressiveness of C++ templates for the kinds of things expressed in STL, and he doesn't seem to be guilty of not investigating Lispy alternatives.

e.g., http://www.antiquark.com/escape/public_html/stepanovusa.html

There are various gnarly problems with C++'s model, some of which show up as gnarly problems in STL, even in fundamental stuff like implementing collections of refcounting pointers last time I looked. But as far as I can tell, every language which tries to get this correct within the language has some serious limitations or issues, arguably at least as bad, especially if like Stepanov one of your top priorities is eliminating every last bit of runtime overhead in the generated code. (E.g., implementing arrays of objects only as arrays of fixed-size pointers into variable-sized objects on the heap, as in typical CL and Java, is a no-go given STL priorities, and thus STL constantly wrestles with a bunch of problems that lots of other implementors have dodged by giving up on them.) As far as I know, no one has a comprehensively satisfactory solution for metalanguage facilities within the language.

Getting metalanguage correct by stepping outside the language and upstream from the compiler, writing a separate program to generate the target program, has been a solved problem as long as we've known how to write compilers in Turing-complete languages. That approach is sometimes used for app code in conventional languages, as in FFTW, and to some extent it's what Lispy macros do. But for some applications, including STL as I understand it, stepping upstream is unsatisfactory. Sometimes what you'd really like to do is have your code generator query the compiler about what the compiler knows. STL in particular, IIRC, wants to have its code generation depend on what the compiler knows about types and typedefs and so forth. In an ideal world it would be routine for code generators to be able to ask the compiler about other things, too, like dead code, namespaces, and safety and other pragmas.

Re:C++ Frequently Questioned Answers by mojuba on Monday May 11, 2009 @12:17PM (#603727)
Templates, the implicit ctor/dtor paradigm coupled with scoping, to name a few. I know Lisp has a unique feature - let's say, unity of code and data, but hey, there are plenty of languages with unique features not found in C++; nevertheless I think my statement still applies, that no language compares to C++ in terms of power of meta-language facilities. I think I understand Lisp and I'd be happy if we could avoid Lisp wars in this context.
Re:C++ Frequently Questioned Answers by anamax on Monday May 11, 2009 @02:30PM (#603966)
Templates, the implicit ctor/dtor paradigm coupled with scoping, to name a few. I know Lisp has a unique feature - let's say, unity of code and data, but hey, there are plenty of languages with unique features not found in C++; nevertheless I think my statement still applies, that no language compares to C++ in terms of power of meta-language facilities.

Umm, lisp macros can implement all of C++ meta-language facilities and more, so how are said meta-language facilities more powerful?

And then there's the meta-language protocol....

Re:C++ Frequently Questioned Answers by mojuba on Monday May 11, 2009 @03:02PM (#604043)

  {
    X x, y;
    if (x > y)
      return;
    // some code ...
  }
where X has a destructor. I'm curious if you can do this in Lisp without explicitly calling the destructors (for x and y) in proper places - two places in this example.
Re:C++ Frequently Questioned Answers by anamax on Monday May 11, 2009 @08:11PM (#604594)
unwind-protect handles this case. (Note that most lisps have GC so if freeing memory is the only reason you're calling the destructor, you don't need to do anything.)

http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec...

There's a reason why PG refers to non-lisps as "blub".

http://www.gigamonkeys.com/book/beyond-exception-handling-co... http://www.lisp.org/mop/index.html

Re:C++ Frequently Questioned Answers by mojuba on Tuesday May 12, 2009 @03:54AM (#605042)
unwind-protect is not the same. Destructors in C++ are part of custom data types, and unlike unwind-protect, they are "implied", which makes your code safer and more succinct. And no, it's not necessarily memory clean-up, of course.

C++ destructors are a powerful tool, you can create data types that otherwise would require support on the compiler's side.

Re:C++ Frequently Questioned Answers by anamax on Tuesday May 12, 2009 @09:23AM (#605314)
> unwind-protect is not the same.

You're right - they're more powerful, but bringing that up didn't seem necessary.

> And no, it's not necessarily memory clean-up, of course.

Never said that they were. However, C++ programmers spend a fair amount of time worrying about/writing code for memory cleanup and destructors is where a lot of that time/code goes.

Folks using languages with GC don't do that nearly as much.

Destructructors are only implied for scope-allocated variables. By tying value lifetime to variable scope, C++ gets to do certain things, but as a result, programmers have to do certain work.

Lisp values are not tied to variable scope, so complaining that lisp doesn't have mechanisms for values that are tied to scope is sort of like complaining that a hovercraft doesn't have a parking brake.

> C++ destructors are a powerful tool, you can create data types that otherwise would require support on the compiler's side.

Actually, they're just a mechanism for calling code when a value "goes away". That's almost required for a language with manual memory management but unnecessary for languages with GC.

However, destructors are also the only way that C++ has for automatically calling code. Other languages have other, more general, mechanisms.

Re:C++ Frequently Questioned Answers by mojuba on Tuesday May 12, 2009 @10:31AM (#605414)
I see what you are saying, but unfortunately garbage collectors in their present form are more evil than good. They are fine in some situations, but may turn to a problem in others. For example, you may get very undesirable effects if you are creating and destroying a large number of objects in a time-critical application (a game, etc).

So, languages that provide no way of controlling allocation have relatively limited application compared to those that do provide full control over memory allocation.

By "relatively limited" I mean just relatively, that is, the reason Python, Ruby, Perl, PHP, Java, C# and Lisp with their GC facility exist is that it works most of the time, but there are certain areas where you have no choice other than C/C++. Kernels, compilers (including Lisp compilers), game engines, everything that deals with hardware, image, audio and video processing, etc etc.

This is an endless list where you really have no choice. Try to write a VST plug-in in Lisp, for example, that would add a reverb and will be able to do it on 8 audio channels in real-time on a 3GHz CPU.

Re:C++ Frequently Questioned Answers by anamax on Tuesday May 12, 2009 @02:06PM (#605873)
> I see what you are saying, but unfortunately garbage collectors in their present form are more evil than good.

Wrong

> They are fine in some situations, but may turn to a problem in others.

Correct.

> For example, you may get very undesirable effects if you are creating and destroying a large number of objects in a time-critical application (a game, etc).

Not if you're using a reasonable real-time GC.

If allocation and reuse is occuring, memory management code is being executed.

GCs tend to run a bit slower, but you get faster development. Sometimes that's a good trade, and sometimes it isn't. (My real-time friends are correct when they say that late answers are wrong answers. However, it's also true that wrong answers are wrong answers.)

> compilers (including Lisp compilers)

Wrong again.

> everything that deals with hardware, image, audio and video processing

Wrong again. (Yes, lots of such systems are built with C/C++ but folks have done them with GC languages.)

And, our python friends have figured out that one can use C/C++ as an extension language for the heavy processing, where very little memory management occurs, and python everywhere else, getting the benefit of both worlds.

This is important because, when you get down to it, most of the applications that have lots of signal processing and the like are actually a couple of time-critical small kernels surrounded by lots of other code. Said other code dominates development time so GC for it is a big win.

> game engines

Yes and no, because "game engine" covers a wide range of things (from physics and rendering through high level "AI") and it depends on the available processing power.

Re:C++ Frequently Questioned Answers by anamax on Tuesday May 12, 2009 @06:31PM (#606212)
I remember seeing exactly the same argument wrt assembly language vs C.

One interesting thing about the "performance is everything" crowd is how many of them use gcc even though there are other compilers for many ISAs that deliver significantly better performance.

Re:C++ Frequently Questioned Answers by mojuba on Tuesday May 12, 2009 @05:04AM (#605087)
> There's a reason why PG refers to non-lisps as "blub".

Where exactly did PG say that all non-Lisps are "blub", whatever that means?

Re:C++ Frequently Questioned Answers by anamax on Tuesday May 12, 2009 @01:49PM (#605828)
I mis-spoke. He actually said that blub programmers found it hard to see certain things.

http://www.paulgraham.com/avg.html