Lambda the Ultimate

inactiveTopic C++ FAQ LITE
started 11/30/2001; 6:42:26 AM - last post 12/4/2001; 2:41:10 AM
Ehud Lamm - C++ FAQ LITE  blueArrow
11/30/2001; 6:42:26 AM (reads: 2785, responses: 9)
C++ FAQ LITE
(via www.keithdevens.com)

Well, sometimes you just need to understand the dark corners of C++...

I like the anti-control freak approach to programming: sometimes it is just more sensible to put a comment saying the a class is final, than to use some coding trick to inhibit inheritance.

Also check out the entries on reference and value semantics and pointers to member functions, a common C++ concern (let's all say closure together now..).


Posted to OOP by Ehud Lamm on 11/30/01; 6:44:07 AM

Frank Atanassow - Re: C++ FAQ LITE  blueArrow
12/1/2001; 5:02:16 PM (reads: 1648, responses: 0)
closure

Happy? :)

Dan Shappir - Re: C++ FAQ LITE  blueArrow
12/2/2001; 1:25:50 AM (reads: 1664, responses: 1)

While I do most of my development using C++, during the past two years I've also been using JavaScript quit extensively (interesting combination, no?) When switching from JS to C++ one of the features I miss most is proper closure implementation. As Ehud has pointed out, closures can be emulated to an extent using pointers to member functions. A more common technique however is the one employed by STL algorithms, which involves function objects. In any event, both leave much to be desired (even when you join both using something like mem_fun).

BTW, C#'s delegates are yet another hack to emulate closures. As delegate support is provided by the .NET infrastructure itself one can only hope that somebody uses this feature to implement some programming language with proper closures for that platform (Arc.NET ? :). Jscript.NET maybe a candidate, but given everything else MS has done to this language, I doubt it :(

Ehud Lamm - Re: C++ FAQ LITE  blueArrow
12/2/2001; 9:09:50 AM (reads: 1715, responses: 0)
The CLI (or was that CLR) is supposed to include features needed for modern languages like tail calls.

andrew cooke - Re: C++ FAQ LITE  blueArrow
12/3/2001; 9:20:16 AM (reads: 1616, responses: 3)
A whole bunch of languages were (alleged to be) ported to .NET when it was first announced - there's a post somewhere on this site from a year or two back where I listed them if you fancy playing with the search.

I've been trying out C++ in a new project - it's exhausting! This FAQ might be useful (although I'm considering switching to a different language if I can get some idea of what the effect of GC is on real-time performance). Incidentally (for Ehud) I also considered Ada, but when I realised it didn't have GC either (hope I'm right on that) it seemed like a lot of extra effort to learn something new for little gain (I already know the basics of C++). But after rubbing my nose in C++ for a few weeks I'm starting to wonder whether I made the right call.

Noel Welsh - Re: C++ FAQ LITE  blueArrow
12/4/2001; 1:43:58 AM (reads: 1622, responses: 1)
The CL[IR] doesn't include closures but it does have tail calls. The MS definition of modern languages isn't as modern as one would like. You can hack closures in .NET but they aren't directly supported so they won't be particularly portable (i.e. my closure hack probably won't match yours). Last time I looked at the .NET languages the interesting ones were all beta.

To achieve real time garbage collector performance you need a real-time garbage collector! :) Erlang and Squeak are two GCed languages that claim to have real time GC though real time means soft real time which means no guarantees at all. There are probably some Java VMs that have the same.

andrew cooke - Re: C++ FAQ LITE  blueArrow
12/4/2001; 2:41:10 AM (reads: 1685, responses: 0)
Thanks for the pointers. I'm currently lookit at MLkit, which appears suitable for what I want; I'll have a look at Erlang too.

Ehud Lamm - Re: C++ FAQ LITE  blueArrow
12/4/2001; 5:28:18 AM (reads: 1677, responses: 2)
Well, C++ doesn't have built-in GC either.

I understand you are primarily interested in functional languages, so I'll be very brief about Ada.

You can use an Ada compiler that tragets the JVM (like JGNAT). In this way you get the VMs GC. If you use a real-time JVM, you should probably be ok.

I am not sure why you are so interested in GC. In many real time situations people prefer to do manual memory management. Now obviously this is not great fun, but some programming language features can help.

Ada's Controlled types allow you to provide finalization routines (a.k.a destructors) which can be used for memory reclamation.

Another Ada feature of interest is storage pools. These allow you provide user coded memory allocation and deallocation routines. These should be useful if you want to provide rudimentary GC facilites.

If you want a functional language, you must rule out C++ as well as Ada. If you decide to reconsider C++, you might also check out Ada.

Ada doesn't provide you with GC, but it does have interesting and useful features that are not part of standard C++ (for example, Ada has builtin multi-tasking facilites, that can be useful for the kind of application you seem to have in mind).

andrew cooke - Re: C++ FAQ LITE  blueArrow
12/4/2001; 7:50:49 AM (reads: 1745, responses: 1)
My choice was C++ or "something else" where the pros for C++ were that it's fairly popular (I'm moving in a month or two and will be looking for a job) and would interface directly with other code. Looking at suitable "something else" I knew Ada was used in realtime apps but - naively in retrospect - thought it would also have GC (& closures). After skimming some docs I was surprised at how much it resembled C++ and decided that, because of the job thing, C++ was probably the way to go.

After using C++ for a while, it's driving me nuts having to worry about all the low-level detail and I can see that Ada might indeed be better. Not having used any language apart from C or C++ that has manual memory management I doubt that I can separate memory management from all the other tiny details and conventions - so my desire for GC might, in practice, be simply a desire for a higher level (or at least simpler) language.

So I'm interested in GC because any less detail to worry about seems like a Good Thing. OTOH, it appears that (most) GC and real time code don't mix (I have no desire to code real-time software for the sake of it, it's just what this application requires). Really, I just want to do as little work as possible to get somethng that works...

[PS My original comment wasn't meant to be any kind of criticism of Ada, just a passing comment]

Ehud Lamm - Re: C++ FAQ LITE  blueArrow
12/4/2001; 8:21:10 AM (reads: 1827, responses: 0)
I agree that in general GC is a Good Thing.

I also agree that doing a little as possible to get things done is the usually the right approach...

Notice that though I like Ada I don't think it is the perfect language (as this is an impossible goal), and I have my own criticism of Ada. I don't fancy holy wars (both on technical issues, and the regular kind), but I do enjoy reasoned debates.