Linked by Eugenia Loli on Sun 19th Nov 2006 18:26 UTC, submitted by Esther Schindler
General Development The C++ standardization committee has set 2009 as the target date for the version of the language standard. And a lot will change. C++09 will include at least two major core features -- rvalue references and type concepts -- and plenty more relatively minor features.
Order by: Score:
Not much of an update
by rover on Sun 19th Nov 2006 19:09 UTC
rover
Member since:
2005-08-07

This is mostly the inclusion of some of the boost libraries in the standard library. Saying that "a lot will change" is a serious overstatement. Even with the new concepts type checking C++ templates are still paleolithic.

If you are interested in a substantial reengineering of C++, in something that actually fixes its major shortcomings, try the D programming language.

http://www.digitalmars.com/d/comparison.html

Incidentally, D is scheduled for its gold release January 1, 2007.

Reply Score: 3

RE: Not much of an update
by Sodki on Sun 19th Nov 2006 19:24 UTC in reply to "Not much of an update"
Sodki Member since:
2005-11-10

If you are interested in a substantial reengineering of C++, in something that actually fixes its major shortcomings, try the D programming language.

I second that. D is a very nice language with a clear focus. My first impression was that it has the best of Java, the best of C++ and none of they're major weaknesses.

Reply Score: 2

RE[2]: Not much of an update
by luzr on Sun 19th Nov 2006 19:44 UTC in reply to "RE: Not much of an update"
luzr Member since:
2005-11-20

I second that. D is a very nice language with a clear focus. My first impression was that it has the best of Java, the best of C++ and none of they're major weaknesses.

Adds one major weekness - its memory model is based on conservative GC, which makes it unpredictable and in reality unusable for some important applications (like cryptography or any other software that deals with noise-like data).

Reply Score: 5

RE[3]: Not much of an update
by rover on Sun 19th Nov 2006 20:19 UTC in reply to "RE[2]: Not much of an update"
rover Member since:
2005-08-07

its memory model is based on conservative GC, which makes it unpredictable and in reality unusable for some important applications

Not really, automatic memory management is not mandatory in D. You can handle memory manually just like in C++. So if C++'s memory model serves your purposes well so does D's.

Reply Score: 4

RE[4]: Not much of an update
by luzr on Sun 19th Nov 2006 20:45 UTC in reply to "RE[3]: Not much of an update"
luzr Member since:
2005-11-20

Not really, automatic memory management is not mandatory in D. You can handle memory manually just like in C++. So if C++'s memory model serves your purposes well so does D's.

Well, in theory yes. In practice, all D libraries will use GC, so not using conservative GC means you are excluded from any library use.

Reply Score: 3

RE[2]: Not much of an update
by GreatBunzinni on Mon 20th Nov 2006 08:56 UTC in reply to "RE: Not much of an update"
GreatBunzinni Member since:
2005-10-31

My first impression was that it has the best of Java, the best of C++ and none of they're major weaknesses.

Well, except for the fact that D includes unnecessary stuff in the core language instead of delegating it to a library. Where is the need to bloat the core language with stuff which is perfectly well achieved with the basic constructs?

Reply Score: 2

RE: Not much of an update
by GreatBunzinni on Mon 20th Nov 2006 09:04 UTC in reply to "Not much of an update"
GreatBunzinni Member since:
2005-10-31

If you are interested in a substantial reengineering of C++, in something that actually fixes its major shortcomings, try the D programming language.

http://www.digitalmars.com/d/comparison.html


That comparison chart is at least dubious, not to mention dishonest. The chart's author opted to ignore simple facts about the C++ language, claiming that it doesn't have certain elements (garbage collection, resizeable arrays, built-in strings, etc..) that it certainly has. If the D programming language is that great why do the people behind it try to spread incorrect information and ignoring simple C++ facts about basic stuff just to add a couple of plus signs in the comparison? Moreover, how come that comparison chart is still up even after the author himself, while trying to spam C++ newsgroups about his new wonderful language, was shown time and again that he incorporated false information about C++?

Reply Score: 1

RE[2]: Not much of an update
by phgt on Mon 20th Nov 2006 11:35 UTC in reply to "RE: Not much of an update"
phgt Member since:
2006-09-16

Last time I checked, C++ did NOT have a Garbage Collector.

Reply Score: 1

RE[3]: Not much of an update
by sp222 on Mon 20th Nov 2006 12:26 UTC in reply to "RE[2]: Not much of an update"
sp222 Member since:
2006-08-17

C++09 will have GC.

Reply Score: 1

RE[4]: Not much of an update
by MORB on Mon 20th Nov 2006 12:38 UTC in reply to "RE[3]: Not much of an update"
MORB Member since:
2005-07-06

Do you have a link to the proposal for that? Don't remember to have seen this.

Reply Score: 1

RE[3]: Not much of an update
by GreatBunzinni on Mon 20th Nov 2006 12:59 UTC in reply to "RE[2]: Not much of an update"
GreatBunzinni Member since:
2005-10-31

There are quite a few C++ Garbage Collector libraries which anyone can choose, which is the right way of doing things. After all it enables those who really want GC in their C++ projects to use it and those who don't to not use it. At least to me that is the right way of doing thins, instead of mandating what you can and cannot do.

Claiming that there aren't GC in C++ is similar to the claim that C++ doesn't have resizeable vectors or even strings. It is a claim which is only made by those who are ignorant of C++ or wish to ignore the facts to be able to make some other product look better than it is. Where is the need to lie about such trivial things? Isn't D capable of standing up on it's own without having to resort to misleading jabs and dishonest alegations?

Reply Score: 3

RE[4]: Not much of an update
by clayasaurus on Mon 20th Nov 2006 14:40 UTC in reply to "RE[3]: Not much of an update"
clayasaurus Member since:
2006-11-20

Quote -> "Claiming that there aren't GC in C++ is similar to the claim that C++ doesn't have resizeable vectors or even strings. It is a claim which is only made by those who are ignorant of C++ or wish to ignore the facts to be able to make some other product look better than it is. Where is the need to lie about such trivial things? Isn't D capable of standing up on it's own without having to resort to misleading jabs and dishonest alegations?"

If you read the http://www.digitalmars.com/d/comparison.html page, you'll realize we are talking about /core/ language features, not features implemented as library add-ons.

Quote from the comparison page...
"
The Hans-Boehm garbage collector can be successfully used with C and C++, but it is not a standard part of the language.
"

Another quote from the comparison page...
"
Part of the standard library for C++ implements resizeable arrays, however, they are not part of the core language. A conforming freestanding implementation of C++ (C++98 17.4.1.3) does not need to provide these libraries.
"

In addition, there is a lot to be gained by implementing these features in the /core/ language rather than as a library add-on. For reason's on this, I point you to this page http://www.digitalmars.com/d/cppstrings.html

Reply Score: 1

RE[5]: Not much of an update
by MORB on Mon 20th Nov 2006 15:26 UTC in reply to "RE[4]: Not much of an update"
MORB Member since:
2005-07-06

Not having a standard GC forced on me is an advantage as far as I'm concerned.

As for the second part, it seems irrelevant. Whether or not the standard specifies that a comformant C++ implementation should include std::vector, all C++ compilers include it.

Why do the D people have to try so hard to argue against C++ that they have to resort to dissecting obscure details of the spec to try to get their point across?
Please argue purely on technical merit. If your language is really that good, it should be enough.

Here are some facts for you D apologists:

- Standard containers are part of all relevant C++ compilers.

- The standard library ships with all relevant C++ compilers.

- Exception handling in C++ doesn't involve setting up special stack frames (at least on good compilers, which exclude visual c++)

It is used as part of an argument as to why D, using GC, is faster than C++ - which is, as always when it come to discussing the GC issue, not supported by any kind of benchmark anyway.

Oh, and the builtin string in D help concatenating strings. Nice.
This bit of syntactic sugar doesn't justify switching to a different language.

While this could be improved in C++, this is not an issue one runs often into, and if it does you can live with constructing a temp string object.

Reply Score: 4

RE[6]: Not much of an update
by clayasaurus on Mon 20th Nov 2006 23:48 UTC in reply to "RE[5]: Not much of an update"
clayasaurus Member since:
2006-11-20

1) D doesn't force you to use the GC. If you are a competent enough programmer, you can disable the GC and use the C runtime malloc/free to do your memory management with. Walter Bright (language author) wrote his entire Empire game in D without a garbage collector.

2) It is not dishonest to say that C++ does not have a re-sizable array implementation built into its core language spec, because it doesn't. It is implemented as a part of the C++ standard library. This is mentioned on the comparison page. It is much nicer to have resizable arrays in the /core/ language rather than as a library add on. If the D language author _was_ trying to be dishonest, he wouldn't create a link on the comparison chart that goes to explain that vectors are implemented as part of the C++ standard library.

3) If you looked at the link, there _is_ a benchmark to support that garbage collection does give you better performance.
http://www.digitalmars.com/d/cppstrings.html
Look at the word count example.

Resistance is futile... you will be assimilated.

~ Clay

Reply Score: 1

RE[7]: Not much of an update
by rayiner on Tue 21st Nov 2006 04:38 UTC in reply to "RE[6]: Not much of an update"
rayiner Member since:
2005-07-06

The fact that GC performance can beat manual memory management performance is something not enough people realize. The same people who in 2006 bitch about the performance cost of GC have probably never written their own memory allocator. They think malloc() and free() are magic instructions implemented in the CPU. They don't realize that both usually involve the processor traipsing merrily around non-localized list structures looking for blocks and doing coalescing.

Reply Score: 1

RE[7]: Not much of an update
by MORB on Tue 21st Nov 2006 09:41 UTC in reply to "RE[6]: Not much of an update"
MORB Member since:
2005-07-06

2) It is not dishonest to say that C++ does not have a re-sizable array implementation built into its core language spec, because it doesn't.

It's dishonest because it's irrelevant. Whether it's in the language or in the library is an implementation detail.

Reply Score: 1

RE[7]: Not much of an update
by MORB on Tue 21st Nov 2006 10:08 UTC in reply to "RE[6]: Not much of an update"
MORB Member since:
2005-07-06

By the way, with the code in that benchmark, you essentially get the difference of time to cleanup after executing the program.

The D version will actually never run through an actual GC cycle (because nothing is ever discarded in the example during the execution) and just discard the heap, whereas the C++ version will have to delete the map.

Once again, it's a situation chosen carefully to advantage D.

Give me a benchmark for a real world application manipulating a lot of objects, including both creating and discarding them, and whose execution does involve garbage collection cycles to actually be performed.

Reply Score: 2

RE[5]: Not much of an update
by GreatBunzinni on Mon 20th Nov 2006 17:20 UTC in reply to "RE[4]: Not much of an update"
GreatBunzinni Member since:
2005-10-31

So in one issue (the GC) the D apologist claimed that he listed C++ as not having because it isn't included in the standards but in another issue (string, vector) he claimed that he listed C++ as not having because, although it is very much part of the standards, it isn't part of the core language.

Don't you find it a bit dishonest that the author of the comparison arbitrarily claims that C++ doesn't have something that it indeed has just because the author feels like it? And what does it say about the D programming language itself if the D authors are only capable of pushing it by lying about C++'s capabilities?

Reply Score: 1

RE: Not much of an update
by vsmi on Mon 20th Nov 2006 09:12 UTC in reply to "Not much of an update"
vsmi Member since:
2006-08-21

why you all start to glorify your favourite/own language by saying c++ is bad? in fact java and c# and whatever else just copied most features of c++ and added some marketing... if you cannot write good portable code this is not problem of c++...

Reply Score: 2

RE[2]: Not much of an update
by luzr on Mon 20th Nov 2006 10:47 UTC in reply to "RE: Not much of an update"
luzr Member since:
2005-11-20

why you all start to glorify your favourite/own language by saying c++ is bad?

Well, I think this is because C++ is still the most relevant language for its application domain.

Reply Score: 1

RE: Not much of an update
by MORB on Mon 20th Nov 2006 09:57 UTC in reply to "Not much of an update"
MORB Member since:
2005-07-06

I'm not really sure about D.

C++ has the very useful property that you don't pay what you don't use. The language is entirely designed around that idea.
This is why it doesn't, for instance, include a garbage collector.

D obviously isn't designed around that concept, so whenever I use one of the D features, how do I know if it's expensive or not? Anything that has a runtime cost associated with it in C++, like dynamic_cast, virtual functions, exceptions and so on are clearly indicated as such.

Also, in C++ there is a clear rational as to why a feature is present in the language, ie what real-world, common problem it solves.

D seems a random mishmash of "cool" features without clear explanation as to why they have been implemented.
For instance, the static_if thing: in which situation would you want to use this?

Also, why would I want unit testing to be part of the language? What does it achieves? C++ gives you the freedom of choosing whatever implementation of unit test framework you want.

I also find their D/other languages comparison to be a bit disingenuous.
First column: name of feature XXX as found in D. Other columns: No, even though different but god solutions may exist to achieve the same thing in these languages.

Finally, I bothered reading their rationale for including a garbage collector, and in addition to repeating the same argument twice, some of them are also either plain wrong or dubious.

If I were to nitpick, I'd also mention that the poor grammar at some places in their documentation is a bit of a turn-off too. They should at least fix that.

By the way, that article doesn't mention every change in C++09. It omits some other very interesting things like vararg templates, static assertions and automatic type inference in declaration.

It might not look very useful features, but along with concept checking it will make template much more useful. Currently, one of the big problem with templates is not what they can do, it's that doing complicated stuff can very quickly result in nightmarish compilation errors.

Reply Score: 5

Delegate constructors are nice
by malkia on Sun 19th Nov 2006 19:11 UTC
malkia
Member since:
2005-07-17

Finally something that makes sense.

On the other hand, I wish C++09 contained specification where the compiler can generate more runtime information about the classes themselves (something like what Objective C does). Off course not required, and option switchable, but better than going through OpenC++ for doing a reflection/introspection system.

Reply Score: 4

RE: Delegate constructors are nice
by vsmi on Mon 20th Nov 2006 09:06 UTC in reply to "Delegate constructors are nice"
vsmi Member since:
2006-08-21

iirc currently there are tools that generate class info based on sources - this is not necessarily compiler's task...

Reply Score: 1

rayiner Member since:
2005-07-06

Yes, this is the compilers task, at least if you want to do it right. The compiler is the one that's actually parsing the code, building the class hierarchy, etc, so why should you depend on some half-assed external tool to do it?

The Open Dylan compiler (www.opendylan.org) is absolutely phenomenal in this regard. The compiler is structured as a library, which the IDE or CLI links to. The library exposes methods for getting at everything from the parse tree of the sources, to notes from the optimizer.

This is the only sensible way to structure things, especially in a language like C++, for which writing a proper parser is a multi-man-year project.

Edited 2006-11-20 21:40

Reply Score: 1

containers of references
by CaptainPinko on Sun 19th Nov 2006 19:13 UTC
CaptainPinko
Member since:
2005-07-21

it bothers me that you need to use pointers in your STL containers instead of refernces. it means you need to cast and check for null every time. It'd be nice if they could do some magic for you.

Reply Score: 3

threads
by lawina on Sun 19th Nov 2006 19:41 UTC
lawina
Member since:
2006-01-20

Will thread support be built into the language?

Edited 2006-11-19 19:41

Reply Score: 1

RE: threads
by grfgguvf on Sun 19th Nov 2006 20:14 UTC in reply to "threads"
grfgguvf Member since:
2006-09-25

I very much hope not.

Reply Score: 1

RE[2]: threads
by luzr on Sun 19th Nov 2006 21:09 UTC in reply to "RE: threads"
luzr Member since:
2005-11-20

I very much hope not.

Actually, there are many levels of thread support and C++ would need at least the minimal one. At the moment, any multithreaded code has undefined behavior by C++ standard.

We are not speaking here about language constructs to start threads, but very basic stuff like library code for locking, which cannot be (at least in theory) correctly implemented in C++ (because compiler is allowed to perform optimizations that broke many of multi-threaded algorithms).

Reply Score: 3

RE: threads
by GreatBunzinni on Mon 20th Nov 2006 13:10 UTC in reply to "threads"
GreatBunzinni Member since:
2005-10-31

Aren't threading platform-dependent? Why would a language which aims to be platform-independent adopt platform-dependent features?

Moreover, there are already plenty of threads libraries for C++. As far as I know even boost has a threading library. As I see it, there is no need it in the standard library and even less on the core language.

Reply Score: 1

RE[2]: threads
by luzr on Mon 20th Nov 2006 13:24 UTC in reply to "RE: threads"
luzr Member since:
2005-11-20

Aren't threading platform-dependent? Why would a language which aims to be platform-independent adopt platform-dependent features?

Once again, the problem is that many thread safe algorithms depend on specific order of operations performed, which is not guaranteed by C++ standard.

Therefore, according to standard, any multithreaded code in C++ is broken.

Of course, there are existing libraries that work - but they are not _guaranteed_ to continue working when compiled with another C++ compiler or even newer version with better compiler (with e.g. different optimizer).

Reply Score: 2

Not much of an update
by Terminal.Node on Sun 19th Nov 2006 22:38 UTC
Terminal.Node
Member since:
2006-11-19

D libraries do indeed use the GC; D is capable of using any kind of GC that can be "plugged in". I think most developers know that, in most cases, using a GC is sufficient for a very wide range of applications -- the majority of them in fact.

Software that absolutely cannot use a GC still have the option of implementing whatever memory model that seems necessary -- it's not just theoretical: practical examples are available in a couple of D kernel projects. The fact that most D libraries will go the GC route is a matter of choice and convenience. For those that need custom fits, D libraries may be developed to fit those rare occasions.

True, such projects may not have the advantage of using /all/ of the standard D library, but these applications are likely specialized enough that they will warrant custom coding anyway. And it's an advantage to know that it's absolutely possible for someone to develop a manual memory management library in D, if they feel the need for it. Also remember that D interfaces just fine with C, so at the very least, the whole range of C libraries are available to D.

C++, along with every other language, has trade-offs. Some peole consider the C++ tradeoffs to be too significant these days, including the very issue of memory management. (D has some tradeoffs too, but, thankfully, without sacrificing flexibility; most D tradeoffs are there to fix many glaring C++ problems) People might notice that /many/ C++ programs don't really need to do all the memory management that they do -- most of the task could be managed automatically. Memory management in C++ has become a finicky and repetitous task, and likely an expensive one from a business perspective, for programmer's developing software: that's a lot more lines of code, a lot more complexity, and a lot more possibility for bugs and memory leaks! GC's certainly have an advantage in this area. To pick out a narrow class of applications that cannot use a gc and then to use that as an argument (an invalid one) against D, is not an objective approach, I think.

Furthermore the D template system will likely allow for many features and tools that work in a memory-model agnostic way -- that's just one of the many advantages of compile time features. By the way, if anyone has a look at D, you'll see that the template system is far surpassing C++'s in numerous ways now too.

:)

Reply Score: 4

RE: Not much of an update
by luzr on Mon 20th Nov 2006 09:10 UTC in reply to "Not much of an update"
luzr Member since:
2005-11-20

D libraries do indeed use the GC; D is capable of using any kind of GC that can be "plugged in".

I can be missing something, but from examples given by Walter in either D website or in C++.lang.moderated it is obvious that D can work with conservative GC only (otherwise examples given would be broken).

Memory management in C++ has become a finicky and repetitous task, and likely an expensive one from a business perspective, for programmer's developing software: that's a lot more lines of code, a lot more complexity, and a lot more possibility for bugs and memory leaks!

Yes, but that is just matter of wrong library design. In my C++ world (http://www.ultimatepp.org/www$uppweb$overview$en-us.html) any kind of _resource_ leaks (not only memory) are non-existent. GC would make things only worse.

By the way, if anyone has a look at D, you'll see that the template system is far surpassing C++'s in numerous ways now too.

The problem of templates in C++ is not templates themselves, but STL...

Edited 2006-11-20 09:10

Reply Score: 4

Too late
by JohnMG on Mon 20th Nov 2006 01:09 UTC
JohnMG
Member since:
2005-07-06

I suspect that C++ may have missed the boat. Just my opinion.

These days, it makes a lot of sense to use a higher level language (like Perl, Python, or Ruby, for example), and then rewrite the performance-critical parts in C, if necessary.

C++ is fine, but if you make use of too many of its features, it becomes very difficult to deal with. Again -- that's just my opinion. C++ is complex, and it's easy to write incomprehensible stuff with it.

D would be interesting, except (my impression from looking at it a while ago) the author is basically saying, "Here's a great language, here's my free (as in beer) implementation of it -- which by the way rocks [as I'm sure it does]; maybe the free software community will want to re-implement themselves a copy? Whaddya say, eh??". Thank you kindly, but we've already got a free (as in libre) C++ implementation, and as of just a few days ago, will now have a free (as in libre) Java implementation.

If I were transitioning some company's future projects from C++, it would only be to another platform with a mature and free (libre) implementation. Now, if Digital Mars wants to GPL their implementation (which would likely require a change in their business plans), I think they might stand a chance of getting some real adoption. Currently though, I think you're going to see a lot of free software C++ devs moving to Java thanks to Sun's doing the right thing with Java's licensing.

Edited 2006-11-20 01:13

Reply Score: 3

RE: Too late
by MORB on Mon 20th Nov 2006 10:28 UTC in reply to "Too late"
MORB Member since:
2005-07-06

It's easy to write incomprehensible stuff with any language.

Perl? I don't think it needs any example of this.

Python? It can, and willl get horrible in the wrong hands. I had to maintain a 3000+ line python script. And despite the fact that python goes out of its way to discourage you from using global variables (one of the rare things I appreciate in that language), the guy who wrote that script used hundred of them.
Regardless of the language, there are dumbasses out there that WILL manage to write hopelessly awful code with it.

I don't know about ruby, but I don't see how it would be different. And I'm suspicious of languages throwing all their eggs in the OO basket like if it was the single only good programming paradigm in existence.

Edited 2006-11-20 10:46

Reply Score: 2

RE: Too Late
by Terminal.Node on Mon 20th Nov 2006 02:10 UTC
Terminal.Node
Member since:
2006-11-19

I think that your impression of D is quite outdated :-); however this is understandable: some people that checked D out in its early days were intrigued but figured it was just a toy and never gave it much time. Unfortunaely, mention of D sometimes brings that old recollection to mind in those people, a a memory that is now quite innacurate.

Thankfully, D has matured much over the last couple of years and its future is stabilizing. It deserves another serious look for those of you who didn't give it much thought the first time around.

That said, D DOES have a GPL implementation -- and for some time now -- called GDC (based off of gcc). It works on many platforms including, interestingly enough, SkyOS. ;)

Have a look here:

http://dgcc.sourceforge.net/

There are binary packages for multiple OSes; there's even a mingw and Mac OSX version available. Quite a few people support and depend on this compiler for their day to day use of the D language.

Edited 2006-11-20 02:18

Reply Score: 3

RE[2]: Too Late
by reduz on Mon 20th Nov 2006 06:38 UTC in reply to "RE: Too Late"
reduz Member since:
2006-02-25

I myself am very and extremely interesed in D. However, unless the D frontend is included into official GCC, developing and distributing apps mase with it will be a big hassle, since you have to install a special patched version of the compiler to make stuff with it...

Reply Score: 2

Wow
by rayiner on Mon 20th Nov 2006 03:08 UTC
rayiner
Member since:
2005-07-06

Ah, more changes to make C++ even more difficult to implement. It's been 8 years since C++ '98, and today there is still no correct and complete implementation. When the next version of C++ comes out in 2009, it will be 2015 before you can expect high-quality implementations.

And the whole concept of the template mechanism as an embedded functional language is really getting out of hand. First they made it Turing-complete, now it has a type system? What's next, object orientation? It is, for all intents and purposes, a glorified macro system, so why not just bite the bullet and let you use regular C++ code to do code generation? IMHO, the metafunction proposal was a much better, saner, and more usable thing to add into C++ than extending the pointy-bracket sub-language from hell.

Reply Score: 3

RE: Wow
by axilmar on Mon 20th Nov 2006 15:47 UTC in reply to "Wow"
axilmar Member since:
2006-03-20

Ah, more changes to make C++ even more difficult to implement. It's been 8 years since C++ '98, and today there is still no correct and complete implementation. When the next version of C++ comes out in 2009, it will be 2015 before you can expect high-quality implementations.

And the whole concept of the template mechanism as an embedded functional language is really getting out of hand. First they made it Turing-complete, now it has a type system? What's next, object orientation? It is, for all intents and purposes, a glorified macro system, so why not just bite the bullet and let you use regular C++ code to do code generation? IMHO, the metafunction proposal was a much better, saner, and more usable thing to add into C++ than extending the pointy-bracket sub-language from hell.


You could not have said it in a better way. I couldn't agree more!

And with all these changes, C++ will not have garbage collection!

And the fact that they are introducing yet another reference type makes C++ even more difficult to use...

Reply Score: 1

Yay
by Phuqker on Mon 20th Nov 2006 05:33 UTC
Phuqker
Member since:
2005-07-17

Although I realize that C++ is actually a very small, simple language at its core, it somehow ends up being overcomplicated and bloated in actual usage. While C++09 is nice, I don't see the added features reducing that tendency too much.

For hobby coding and mental workouts, I've moved on to Haskell and Ruby. (Haskell is an incredibly elegant language. Wow.)

Edited 2006-11-20 05:33

Reply Score: 1

RE: Yay
by GreatBunzinni on Mon 20th Nov 2006 13:07 UTC in reply to "Yay"
GreatBunzinni Member since:
2005-10-31

Although I realize that C++ is actually a very small, simple language at its core, it somehow ends up being overcomplicated and bloated in actual usage. While C++09 is nice, I don't see the added features reducing that tendency too much.

Your code can only start to get bloated and overcomplicated if you intentionally wish that your code becomes bloated and overcomplicated. If you don't want to use features that you consider out of your reach and difficult for you to understand and keep track then don't use it.

And of course that isn't exclusive to C++. It holds true to any other language and it is proportional to your experience and knowledge of it.

Reply Score: 1

D?
by theGrump on Mon 20th Nov 2006 06:47 UTC
theGrump
Member since:
2005-11-11

i see comments here advocating D. i looked into D but its licensing seemed vague. is it open? i can't really say.

Browser: ELinks/0.11.1-1-debian (textmode; Linux 2.6.17-2-686 i686; 91x34-3)

Reply Score: 1

The D spec is not free (as in libre)
by silicon on Mon 20th Nov 2006 15:27 UTC
silicon
Member since:
2005-07-30

The subject says it all. The official D spec is copyrighted by the author. Also nothing prevents him from filing a patent application (maybe he already has one). Large scale adoption of D is risky until these issues are resolved.

Reply Score: 3

Pointers / References
by stodge on Mon 20th Nov 2006 15:30 UTC
stodge
Member since:
2005-09-08

One of the things that constantly annoys me about C++ is pointers and references. I admit I'm not a great (nay, good) C++ programmer. I wish there were one or the other. Actually I would prefer references as I'm tired of dealing with pointers.

I would also like more runtime typing - reflection? I currently define macros that you can use to generate code for class typing. I could expand it to include more queries but I don't need it right now.

When I think about it I guess I keep wanting something more akin to Java. That may be my next logical step, though Java isn't a solution for all my problems.

Reply Score: 1

The importance of standardization
by rayiner on Mon 20th Nov 2006 21:43 UTC
rayiner
Member since:
2005-07-06

Great Bunzinni: You're missing the very major benefit of including features in the language standard, instead of depending on third-party libraries: standardization. Tolerable memory management in C++ is possible, but the problem is that everybody does it differently! There are probably dozens of smart pointer classes in use, for example. And good luck using GC in a library, because if another library decides to use a different GC, you're boned. These things make code integration very difficult, and people are often forced to program at a lower level than desired just for the sake of code portability and reusability.

Reply Score: 1

GreatBunzinni Member since:
2005-10-31

Tolerable memory management in C++ is possible, but the problem is that everybody does it differently!

And tell me, if there isn't a consensus to what is the best GC or more appropriate method out there, isn't it better to let the user choose whatever GC is best suited for the task at hand instead of imposing the same generalized component that may not suit anyone's needs? If everyone does things differently then the best thing that anyone can do isn't avoiding the imposition of the one and only solution?

Reply Score: 1

rayiner Member since:
2005-07-06

People don't all do different things in C++ because its necessary for the task at hand, they do so because they have no other choice. Hundreds of different ad-hoc memory management schemes don't exist because they're really necessary (most are variations on a few basic schemes), but because lack of standardization means that there is no mechanism for picking common methods.

For almost every task for which "modern C++" is useful, a GC is the right memory management scheme to use. The hit of a GC is a lot less than the hit of smart pointers or the large amount of copying involved in STL collections, for example. Entertainingly, these fancy "move semantics" are largely necessary to make up for the over-use of copying semantics in the STL, which are necessitated by C++'s lack of GC.

There are problem domains for which GC is not appropriate, though they are getting smaller as collectors become more advanced. In any case, the majority of those problem domains aren't appropriate for C++ anyway, at least not in its modern incarnations. If you're on an embedded platform, for example, and can't tolerate the extra memory usage of a GC, you're not going to do very well with the massive memory increase imposed by template code either. If you're doing hard-real time computation, you can't use things like smart pointers, because they're very non-deterministic as well with common data structures (lists, graphs).

Reply Score: 1

luzr Member since:
2005-11-20

For almost every task for which "modern C++" is useful, a GC is the right memory management scheme to use. The hit of a GC is a lot less than the hit of smart pointers or the large amount of copying involved in STL collections, for example. Entertainingly, these fancy "move semantics" are largely necessary to make up for the over-use of copying semantics in the STL, which are necessitated by C++'s lack of GC.

I disagree (and I have one million lines of codebase to prove this point;).

I agree that STL's copy semantics IS THE PROBLEM, but GC is not the solution. The solution is to simply design container library WITHOUT copy semantics requirement, which is completely possible.

In such design, move semantics is still useful, but plays role similar to "break" statement in structured programming (and you do not need language extension to achieve this).

BTW, the main architectural trouble with GC and C++ is that it is impossible to match GC and destructors. You can have GC or destructors, but never both. I vote for desctructors (GC would not close my files).

As for performance claims, many GC advocates do not realize that often old malloc/free implementation are compared to cutting edge GC's. In the end, famous Boehm's GC, which is used in most opensource projects, has its tiny (and very smart) "malloc/free" in its sweep algorithm, so it is not cost free either.

You can implement manual allocator based on similar idea as is used in Boehm's GC - what you get MUST be faster than GC, because it is basically the same code without the sweep phase. Indeed, both malloc and free translate to about 15 machine code instructions executed in the "fast" path. (Note: means I DID implemented memory allocator - I spent years optimizing...;)

To be more concrete, you can check the code at http://www.ultimatepp.org (both for memory "non-management" via owning non-copying containers and fast heap allocator code).

Edited 2006-11-21 08:43

Reply Score: 1

axilmar Member since:
2006-03-20

BTW, the main architectural trouble with GC and C++ is that it is impossible to match GC and destructors. You can have GC or destructors, but never both. I vote for desctructors (GC would not close my files).

No, it is not impossible.

First of all, if C++ ever had GC, it would not be obligatory to allocate objects on the heap. Objects could happily live on the stack, as it is right now, therefore RAII would work as it is right now.

But let's say you have heap objects that you want to clean up after a specific operation...The RAII pattern works with garbage-collected objects too, using Lock<T> classes on the stack, where T is the type of garbage-collected objects. For example:

RAII<File> r1(new File());
//...bla bla bla process file
//r1 destructor closes the file.

Reply Score: 1

luzr Member since:
2005-11-20


First of all, if C++ ever had GC, it would not be obligatory to allocate objects on the heap. Objects could happily live on the stack, as it is right now, therefore RAII would work as it is right now.


The real question is: Should GC call destructors?

You will find a lot of reason why it should and a lot of reasons why it shouldn't - but in both cases something gets broken.

Reply Score: 1

axilmar Member since:
2006-03-20

The real question is: Should GC call destructors?

Why not? I do not see the reason why.

RAII is programmable and not hardcoded in the compiler, and therefore RAII classes like 'Lock' can use a function other than the destructor to clear resources.

I think it is a mistake that C++ does not have optional garbage collection. There are many programmers driven away from it due to its complexity and sheer number of 'gotchas'...in the end, C++ will become a niche language.

Reply Score: 1

rayiner Member since:
2005-07-06

I agree that STL's copy semantics IS THE PROBLEM, but GC is not the solution. The solution is to simply design container library WITHOUT copy semantics requirement, which is completely possible.

There is a reason so much of the C++ world has embraced the STL style. It makes memory management in C++ an order of magnitude less painful. The cost of this is copying objects around everywhere, because sharing semantics would immediately negate that convenience.

BTW, the main architectural trouble with GC and C++ is that it is impossible to match GC and destructors. You can have GC or destructors, but never both. I vote for desctructors (GC would not close my files).

It's not impossible to match GC and destructors, you just have to approach "destructors" in a different way. Leave memory management to the GC, and handle releasing resources when you leave lexical scopes using with-* macros (or something equivalent --- if the metafunction proposal had been accepted, C++ could do it too). The solution is largely equivalent, and you get the flexibility of GC.

As for performance claims, many GC advocates do not realize that often old malloc/free implementation are compared to cutting edge GC's. In the end, famous Boehm's GC, which is used in most opensource projects, has its tiny (and very smart) "malloc/free" in its sweep algorithm, so it is not cost free either.

Boehm GC is hardly the best you can do, and is hampered by having to be conservative. Moreover, while its true that there is something like a malloc()/free() in the heap manager of every garbage collector, you're ignoring that its used in a very different way. First, its invoked far less often. In a generational collector, the normal path is a simple sequential allocation. The heap manager is invoked to handle allocations only when survivors need to be copied out of the young generation. Second, in a moving GC, it can be far more callous about memory fragmentation than a good malloc()/free(). It can handle allocations/frees at a page-level granularity, because the copying/compacting process will ensure you don't end up with lots of partially empty pages.

You can implement manual allocator based on similar idea as is used in Boehm's GC - what you get MUST be faster than GC, because it is basically the same code without the sweep phase.

For the aforementioned reasons, that's not true. Even if you implemented an allocator with shitty fragmentation characteristics that handled things at page granularity, you'd still have to call it on each malloc()/free(), instead of for some (often small) fraction of them.

Indeed, both malloc and free translate to about 15 machine code instructions executed in the "fast" path. (Note: means I DID implemented memory allocator - I spent years optimizing...;)

How many clock cycles is that? When I wrote mine, I was pretty impressed at the brevity of the fast path (though yours is quite a bit smaller) but the cache behavior of accessing list structures is such that one instruction translates to several CPU clock cycles. The fast path of a generational GC, in comparison, can be less than a dozen highly cache-friendly machine instructions. Moreover, the code is so small, it can usually be inlined into the allocation site, saving another dozen cycles of function call overhead.

Reply Score: 1

luzr Member since:
2005-11-20

When I wrote mine, I was pretty impressed at the brevity of the fast path (though yours is quite a bit smaller) but the cache behavior of accessing list structures is such that one instruction translates to several CPU clock cycles.

Obviously, you have to consider this while optimizing and keep cache-lines "hot". And the fragmentation is (for typical patterns) pretty low too (in fact, it has very less than 1 byte of book-keeping info per block and fragmentation for typical usage pattern is constant number of bytes).

You are correct about "GC using memory allocation" in different way and free being much less frequent operation. Anyway, this holds true only as long as total number of reachable blocks is reasonable (e.g. you are creating a lot of temporary objects - this is best scenario for GC). I believe that as number of active blocks increases, GC advantage (if there was any) diminishes - mark/sweep becomes too complex, a lot of memory has to be moved, cache lines are not kept "hot" anymore etc etc....

Therefore IMO GC is acceptable for small datasets and small applications.

To present an opposite argument, GC can sometimes have an advantage in multithreaded environment, as it requires just single lock (world-stop) for the whole sweep phase. All depends on how much locking or TLS (for per-thread cache of blocks in non-GC) are expensive on the platform.

BTW, I mention Boehm's GC because it is what D language, discussed here as better alternative to C++, actually uses.

P.S.: Who speaks about list structures? ;)

Edited 2006-11-21 20:58

Reply Score: 1

rayiner Member since:
2005-07-06

I believe that as number of active blocks increases, GC advantage (if there was any) diminishes - mark/sweep becomes too complex, a lot of memory has to be moved, cache lines are not kept "hot" anymore etc etc...

Well, the same is true to a great extent for malloc(), as well. As the number of small allocations increases, you spend a lot more time traversing increasingly fragmented allocation lists. And GC has an edge in one respect, because it doesn't have to manage individual objects in its heap structure, and can instead can deallocate whole pages of dead objects.

I should also point out that for both GC and malloc(), this penalty comes with increasing number of objects, not increasing amounts of memory. If your program is manipulating a few hundred large matrices, even if your heap is gigabytes, a GC (at least one that has object formats and knows a matrix is a leaf object) isn't going to do a lot of scanning.

Reply Score: 1

luzr Member since:
2005-11-20

Well, the same is true to a great extent for malloc(), as well. As the number of small allocations increases, you spend a lot more time traversing increasingly fragmented allocation lists.

Well, only as long as you are using allocation lists and have to traverse them....

In the heap allocator used in U++, no scanning of blocks (well, we are speaking about "small blocks" up to 1KB here to be exact) is ever performed. Either you go fast path, using hot cache line, then there is "medium" path - up to about 500 machine opcodes (no scanning lists over the heap) and if that fails, new memory chunk has to be obtained from OS.

See, this is exactly what I was pointing at when I claimed that usually, outdated malloc implementation is compared to cutting-edge GC. Of course, if you are going to use malloc based on algorithm described in K&R, GC must win.

P.S.: Note that I agree about your opinions and info about reference counting and even on advantages of GC. Just the truth is not complete...

Edited 2006-11-21 21:26

Reply Score: 1

RE[3]: The importance of standardization
by sanders on Tue 21st Nov 2006 08:35 UTC
sanders
Member since:
2005-08-09

People don't all do different things in C++ because its necessary for the task at hand, they do so because they have no other choice. (...) lack of standardization means that there is no mechanism for picking common methods.

In my experience, there are other reasons as well. I can't count the number of times a junior programmer implemented his own smart pointers or even list structures because he figured he could do better than Boost/STL. I concede that this is partly due to lack of standardization, or perhaps due to programmers thinking they're "expert C++ programmers" after finishing chapter 1 of their C++ 101 course.

you're not going to do very well with the massive memory increase imposed by template code either.

This argument I don't really understand. Templates impose no more code overhead than doing things manually - or do you mean something else?

Reply Score: 1

luzr Member since:
2005-11-20

This argument I don't really understand. Templates impose no more code overhead than doing things manually - or do you mean something else?

Well, this is debatable and relative. E.g. vector<T> instance tends to have about 500 bytes per T.

Now if you would have "Object-based" container system design (like in Java), you would have single container class for use with any T (say 1000 bytes once for any number of element types). It would be slower, but smaller.

Reply Score: 1

RE[4]: The importance of standardization
by sanders on Tue 21st Nov 2006 11:14 UTC
sanders
Member since:
2005-08-09

E.g. vector<T> instance tends to have about 500 bytes per T.

Can you back this up? Which compiler/STL? This seems like an awful lot.

Reply Score: 1

luzr Member since:
2005-11-20

E.g. vector<T> instance tends to have about 500 bytes per T.

Can you back this up? Which compiler/STL? This seems like an awful lot.


Sorry, it is some time I have checked. But it is not at all unreasonable - such implementation will have to have at least code for expanding vector (which is a loop to copy-construct and destruct elements, in many cases with inlined constructors) - say 150 bytes. Then there must be destructor code, another loop calling destructors for elements, say 100 bytes. Throw in 2-3 "advanced" operations (like insert) and you are close to 500 bytes.

Anyway, I guess my original claim holds true even if it was 50 bytes / vector ;)

If size/vector does not bother you, think about map ;)

Mirek

Reply Score: 1

Yay concepts
by bouh on Wed 22nd Nov 2006 02:07 UTC
bouh
Member since:
2005-10-27

Yay finally, concepts are in the language!

No need to use/write enable_if<> checking. That was needed.

Reply Score: 1