Live data from Hacker News

How to design a replacement for C++

apenwarr.ca

21–30 of 75 posts

Re: How to design a replacement for C++

#21
post #5

I figure closures would be hard to do in a programmer-friendly way without GC.

The C++ closure library we use internally at Google has you specify whether the callback is permanent or not. If it isn't permanent, its deleted right after executing. It is a little painful maintaining the memory of your arguments, but people have generally converged to packing them all into a heap allocated struct and deleting when appropriate.

Re: How to design a replacement for C++

#23
post #14

"(Talking about C++ macro) [...] Well fuck you. If you take it out, I can't #include stdio.h, and I can't implement awesome assert-like macros. End of discussion." This statement is simply wrong, and saying "End of discussion" is useless, if not plain stupid. It's like saying: 1+1 = 3, End of discussion.

I honestly can't begin to contemplate how you expect stdio.h to work (without writing extra wrappers) if you don't support macros and a preprocessor. Some of the "functions" in there are macros.

import_c

You can import C headers without your language being a superset of C.

Re: How to design a replacement for C++

#24
The recently-revealed "Rust" appears to be your salvation: http://wiki.github.com/graydon/rust/language-faq

Written by Mozilla employees, and very much like Go, except that shared state is immutable by default, no global GC, and no null pointers. It does have fine struct layout control, RAII always, and type-parametric user code (purely structural too!).

It does have a real module system for grownups, which even if it doesn't preclude your fetish for #include, it will at least make you feel bad about it.

Re: How to design a replacement for C++

#25
post #6

An immediate issue with the article: the author takes issue with the liberal attitude taken by C++ in adding features and then proceeds to state: Maybe you like [lambdas], maybe you don't, maybe you think they're God's gift to programming and any language without them is an infidel. But adding them would be harmless, anyway. Well I agree on this point, it seems like a poor argument. You can't just declare a feature h…

If your language isn't completely terrible, then you can choose to use a named function anywhere an anonymous function will do. The libraries can never force you to not give your functions a name or not put them in a global context. That's why it's a harmless feature. Templates might have been harmless if there was a way to do basic obvious stuff (callback functions, strings) without using them.

I'll hazard the guess that hazzen is interpreting 'lambdas' to involve closures.

Re: How to design a replacement for C++

#26
> But there will always be programs that have to be written in a language like C and C++. That includes kernels, drivers, highly performance-sensitive code like game engines, virtual machines, some kinds of networking code, and so on.

Thank you. I am not looking forward to the day when people begin to advocate Java or something like that for these applications, and I am glad to see this explicitly acknowledged.

Re: How to design a replacement for C++

#27
If I recall correctly, D allows you to disable garbage collection and do your own memory management, and it does give the programmer a lot of power over how memory is managed, up to and including literally using C's malloc and free. I think it's more accurate to say that D has optional, on-by-default garbage collection. I still wouldn't write a kernel in it, and I can't agree more about D 2.0, but it's a bit misleading to say that D "requires" garbage collection.

Re: How to design a replacement for C++

#29
post #5

I figure closures would be hard to do in a programmer-friendly way without GC.

If you implement closures as thunks, you can just free them when done, no need for GC.

    closure int foo(int x) {return x + y;}
    int(*foo_p)(int) = malloc(sizeof(foo));
    memcpy(foo_p,&foo,sizeof(foo));
    return foo_p;
So, you can add working closures in one keyword (and possibly a special case for function pointer decay).

Re: How to design a replacement for C++

#30
post #23

Earlier quoted context omitted.

I honestly can't begin to contemplate how you expect stdio.h to work (without writing extra wrappers) if you don't support macros and a preprocessor. Some of the "functions" in there are macros.

import_c You can import C headers without your language being a superset of C.

Yes. Many a time I have wished to import a library's symbols without importing its macros. Or better yet, import its symbols under alternate names. "namespace x = import" anyone?
Post reply on HN