C++0x Finally Becomes a Standard 398
Samfer writes "On Friday August 12th 2011, the results for the final ISO ballot on C++0x came in, and the ISO C++ Standards Committee were unanimous in favor of approving the new C++0x (for now unofficially known as C++11) object-oriented programming language standard which is intended to replace the existing C++ standard. The new standard is to offer new and improved features such as lambda functions, concurrent programming functionality, direct data field initialization, and an improved standard library to name but a few."
Although I haven't heavily used C++ in years, it is nice to see a decade long effort finally come to fruition. Especially nice is the support for type inference which should save quite a few people from RSI and make refactoring code a bit less obnoxious.
After... (Score:2)
nice, but still missing... (Score:3)
List of missing features:
- coroutines
- multi-stage/active library programming (i.e., something that fixes the syntactical mess of most template libraries)
- precise garbage collection (not that I'm missing it)
- fully opening up of the memory model (allowing libraries to implement complex memory handling such as garbage collection or persistence)
Re:nice, but still missing... (Score:4, Insightful)
You lazy, spoiled punks with your Java and C# garbage collection. Back in my day, we collected our OWN garbage. It was a miserable task, but we were ignorant and didn't know any better. AND WE LIKED IT!
Re: (Score:3)
Re:nice, but still missing... (Score:4, Interesting)
After a month of coding Java and never having to worry every time I typed "new" I never looked back.
Modern C++ programmers don't need worry about typing "new" either; they use smart pointers to handle the "garbage collection" for them. Works great, and avoids the unpredictability, overhead, and performance problems of a garbage collection thread.
(yes, I know it's possible for reference-counting to leak if you introduce a cycle into the graph. That said, in the last ten years of C++ program, that problem has bit me exactly zero times)
Re:nice, but still missing... (Score:4, Informative)
- precise garbage collection (not that I'm missing it)
What is the matter with everyone wanting a garbage collector? Personally, I find smart pointers to be far superior to garbage collection and the new standard now incorporates them in the STL (strongly influenced by BOOST)! With them, the sole idea of garbage collection in C++ is somewhat useless and obsolete.
Re: (Score:3)
Re: (Score:2)
If you can't be bothered/figure out how to free memory when you're done with it do the rest of us all a favor and stop programming.
Indeed. Garbage collection solves a few problems by creating a huge pile of new ones, like objects staying around when you thought they'd gone because someone somewhere still has a reference to them, or randomly disappearing because you forgot to keep a reference to them.
Re: (Score:3)
What is it with lazy/shitty programmers and superfluous references?
If you can't be bothered/figure out how to keep track of your objects do the rest of us all a favor and stop programming.
Re: (Score:2)
If you are able to reliably track your objects then why do you need garbage collection at all? If you are so sure you won't need that object from that point forward, why don't you insert a free() or delete instruction at that point?
Re: (Score:2)
With smart pointers and RAII, that's in fact what most C++ coders do.
The reason why some want GC is become for small applications, it can speed development and runtime performance (saving you from optimizing). This is one of the things with many Java benchmarks whereby they purposely attempt to create the false illusion that Java is so much faster than other languages - in that they purposely attempt to defer object destruction. Its true a tiny subject of applications will benefit from this but of course, t
Re: (Score:2)
Re: (Score:2)
"or randomly disappearing because you forgot to keep a reference to them"
Really? That's an example why GC is bad? I think losing track of your data is poor programming, no matter which language you use.
"creating a heap of new ones" fixed by adding pun
But really, memory leaks with a GC is much easier to debug. There's very few corner cases to "leak" with a managed language.
Re: (Score:2)
everything in moderation, of course (Score:2)
Re:nice, but still missing... (Score:4, Interesting)
Early on, the C++0x spec had "opt-in" garbage collection, which was perfect! You'd declare a pointer as a garbage collected pointer if you wanted that, but otehrwise no GC. That was useful for cyclic data structures, and otherwise you could ignore it.
Sadly, missing from the final spec.
I'm just disappointed... (Score:2)
They didn't call it C++0b
Oh and didn't include garbage-collection outright ( though they did design it with gc in mind ).
oh hell... (Score:2, Funny)
...the 11th plague of Egypt has arrived a little bit late.
C++0x (Score:2)
How do you pronounce that? It's like they want to advertise that this is a baroque language.
Re:C++0x (Score:4, Informative)
C Plus PLox
Re:C++0x (Score:4, Funny)
Wanted: A 'cocks' programmer. With seventy years experience.
Sadly, tragedy struck (Score:3, Insightful)
and WOOSH there goes my karma...
Re: (Score:2)
No, that was the sound of the reverse psychology ploy. Declarations of doomed karma give karma!
Re: (Score:2)
I was thinking the same thing. The orignal white book was only 228 pages. C++ made C into a huge language that makes Ada look compact! Some of the additions are handy but so much of it seems to be just tricks.
Smaller and simpler seem to be a better way to go.
Re:Sadly, tragedy struck (Score:5, Insightful)
Smaller and simpler seem to be a better way to go.
Nobody is stopping anyone from using plain old C, if that's what they want.
Of course, many people just end up re-inventing portions of C++ when they do that.
Random links? (Score:2)
Re: (Score:2)
Have you ever browsed around c2.com? It's great. Wikipedia is good as a generic "fail-safe" resource, but I'd rather see a deep subject-matter wiki being cited where appropriate.
I imagine the Intel article was referenced due to its examples of syntax. It's more specific than a general encyclopedia entry on lambda functions.
At this rate (Score:3)
Re: (Score:2)
Perl 6 has been around for years now. You can even run it in a browser [rakudo.org] if you're too stupid to operate synaptic.
Nice, but maybe irrelevant. (Score:4, Interesting)
It's nice that they finally got the standard done. But there's so much junk in there. The C++ committee was dominated by people who wanted to do cool things with templates.
Some years ago, someone figured out that it was possible to abuse the C++ template system into doing arbitrary computations at compile time. This developed a fan club. That fan club has dominated the C++ standards committee, because nobody else cared. So now we have a standard for C++ which supports template-based programming a little better.
Current thinking seems to be that,while template programming is too hard for ordinary programmers, the templates will be written by l33t programmers and then be used by the lower classes. Unfortunately, if anything goes wrong, the end user has to look at the innards of the template to find the problem. We went through this with LISP decades ago. Check out the MIT Loop Macro [cmu.edu], That finally became stable about the time LISP died out.
Note what isn't in the new C++. There's no more memory safety than in the old one. (Fans will say that it's safer if you only use the new features. Now try to call some library that doesn't use them.) So the buffer overflow attacks and crashes will continue.
C++ is the only language to offer hiding without memory safety. Hard-compiled languages from Pascal through Go have hiding with safety, as do all the major scripting languages. C has neither hiding nor safety; the pointer manipulations are right there in the source. There have been safe, hard-compiled languages without garbage collection, most notably Ada and the Modula family. Safety and speed are not incompatible.
Re: (Score:2)
I think you hit the problems with templates nicely. While they were sitting around arguing over concepts, they could have been including support for multithreading. The new move semantics are nice, as are "official" smart pointers, though I am kind of cringing thinking about how much of a pain dealing with incompatibilities with boost smart pointers or other smart pointer libraries might be.
With the exclusion of concepts, the latest standard just moves C++ farther into an experts-only language. The whole st
Re:Nice, but maybe irrelevant. (Score:5, Informative)
While they were sitting around arguing over concepts, they could have been including support for multithreading
Actually, they did add some support for threading. C++11 has support for a thread-local storage qualifier and a rich set of atomic operations. These are both also in C1x. There is also now a std::thread class, and various synchronisation primitives, and even support for futures / promises.
Much as I dislike C++, the latest version does have a subset that is much nicer than any subset of previous versions.
Re: (Score:3, Informative)
While they were sitting around arguing over concepts, they could have been including support for multithreading.
They did include support for that. That's been a well-known piece of the new standard for nearly 2 years now.
Re: (Score:2)
Wow, you are right. I thought that got dropped from the final version of the standard. I haven't seen anyone write about those features in a long time.
Re: (Score:2)
The loop macro is, in essence, part of the compiler or the standard library. It is code that processes code during compilation. I'm not surprised that it's nontrivial.
Re:Nice, but maybe irrelevant. (Score:4, Informative)
Lisp programmer here.
The loop macro actually has access to all the innards of the compiler and gives reasonably useful error messages, at least when compared with standard issue C++ error messages. The loop macro is in fact a lisp program with full access to everything. It can and does produce error messages through the same mechanism than the compiler. C++ templates is a horrendously perverted shadow of what lisp macros are.
Try Common Lisp some day. It so superior to C++ - it is amazing.
(...and there goes my karma)
Re: (Score:2)
Some years ago, someone figured out that it was possible to abuse the C++ template system into doing arbitrary computations at compile time. This developed a fan club. That fan club has dominated the C++ standards committee, because nobody else cared. So now we have a standard for C++ which supports template-based programming a little better.
Current thinking seems to be that,while template programming is too hard for ordinary programmers, the templates will be written by l33t programmers and then be used by the lower classes.
You're thinking about Template Meta-programming, not the everyday templates I use.
Re: (Score:2)
Well, that's typical sectarian. "If it doesn't work for you, it is you who did something wrong".
C++ imposes a massive burden on the programmer. You have to be a lot smarter than with other, better programming languages just to get something done reasonably well. There are a million rules with a million exceptions, and things keeps constantly going wrong. Of course, it is your fault every time they go wrong.
Since I do not p
Hell continues to get colder (Score:5, Funny)
First DNF, then a HURD kernel, now C++0x... Remind me to send some parkas to hell.
Mandatory Lisp observation... (Score:2)
So C++ takes another step closer to Lisp (lambda functions) whilst completely missing the most important part (closures and higher order programming).
I look forward to C++ 2031 when they implement garbage collection but still require you to place and remove locks on memory ;)
*Ducks and runs for cover*
Re: (Score:2)
*facepalm* C++0x has closures. For example, here [informit.com] is an article talking about them in C++0x. Hell the article is 3 years old at this point.
Submitter FAIL (Score:2)
Because surely, the hard work of writing code is in all that typing.
and make refactoring code a bit less obnoxious
Because yeah, refactoring is all about continuously retyping your variables.
I haven't heavily used C++ in years
Re: (Score:2)
Because surely, the hard work of writing code is in all that typing.
No, but when you use a lot of for loops with iterators being able to type, for example, auto i = ivec.begin(); instead of vector::iterator i = ivec.begin(); makes things a lot less tedious and, for me, makes things more readable with less noise obscuring the intent of the code.
Re: (Score:2)
That was meant to be vector<int>::iterator. And obviously in my example this isn't as bad, but say you are dealing with a more complex container declaration and the type of the iterator can expand out like crazy.
Re: (Score:2)
Unofficially, ours increments up to eleven!
Re: (Score:2)
Re:Congratulations! (Score:5, Funny)
Wrong thread dude, think you were looking for:
http://developers.slashdot.org/story/11/07/28/1758221/Oracle-Announces-Java-SE-7 [slashdot.org]
Re: (Score:2, Troll)
I have the same impression. A bunch of useless, error prone, legibility degrading changes to save a little bit of typing. In my opinion this is the worst standards committee ever.
Re: (Score:2)
OK, so you consider concurrency useless? And lambda functions? And type inference? And strongly typed enums? And static assertions? And Unicode support? And variadic templates? And move semantics?
The only pity is that concepts didn't make it in.
Re: (Score:2)
OK, so you consider concurrency useless? And lambda functions? And type inference? And strongly typed enums? And static assertions? And Unicode support? And variadic templates? And move semantics?
Of course they don't. But they can't troll and sound like they have a legitimate grip is they actually spoke to reality.
Re: (Score:3)
I think you mean
in that first example.
And you're being ridiculous. Anyone who types that is an idiot and deserves everything they get. The actual nice thing about "auto" is that you can type
instead of
without having to faff about with typedefs all over the place.
Re: (Score:2)
I hadn't thought of that, but your right, it IS damn funny!
Re: (Score:3, Funny)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
You can do objects via C but its hard to read, debug, error prone, frequently inflexible, and nowhere near as powerful as C++. Other than that, objects in C are a really good idea.
Re: (Score:3)
There are some mature libraries like GObject [gnome.org] (and Vala, Genie) that do objects for C.
Re: (Score:2)
Re: (Score:3, Interesting)
Re: (Score:2)
What?! Reasonable and sane discourse? With a valid counter point even? You must be new here!
Re: (Score:2)
That's not particularly true. Actually, C++ makes life, perhaps, slightly easier because you can do:
class X;
class Y { X * var; };
vs. C where you'd have to write (note the repetition of naming the the word "struct"):
struct _X;
typedef struct _Y { struct _X *var; } Y;
In either language, you only need to include the typedef where you're actually using it (i.e. not just a pointer), and so only have to rebuild those parts if you set up your headers sanely. Sure, in C you can throw a function prototype in a .c
Re: (Score:3)
Not really. The main advantage of objects is the loose coupling.
No, the main advantage of objects is namespace hygiene.
Re: (Score:2)
2) Operator overloading: because TimeCard + MoveTicket + WorkOrder is so much more readable
3) Virtual destructors: because the concept is so easy to explain.
Errrr. Give me a minute. I'm sure I'll think of something.
Re: (Score:3, Insightful)
Correction:
2) Operator overloading: because
Matrix A, B, C, D;
A = A+B*C + A*D;
is so much more readable than
Matrix A, B, C, D;
A.equals(A.plus(B.mult(C)).plus(A.mult(D)));
.... oh wait, it is! This is why Java sucks and C++ rocks for scientific programming.
Re:Clean cool crisp refreshing (Score:4, Interesting)
(+ A (* B C) (* A D))
Filter error: Don't use so many caps. It's like YELLING.
Re: (Score:2)
Shouldn't it be:
(+ A (+ (* B C) (* A D)))
or did you mean this:
(+ (+ A (* B C) ) (* A D)))
Filter error: Don't use so many caps. It's like YELLING.
You lose the Lisp war! (Score:2)
(+ x y z) is perfectly valid in Lisp
So (+ A (* B C) ( * A D))
is better style.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:3)
C++ is a powerful and pragmatic, but ugly and dangerous language. No doubt about it. I'm a game developer, so I'm either working on C++ in engine code (and a subset of C++ at that), or in higher-level languages such as C# or Python for tools.
And of course, C++ is definitely a language that requires a significant amount of programmer discipline - more so than other languages, at least from what I've seen. At a personal and a company level, you need to develop some guidelines that keep you from walking int
Re: (Score:3)
I guess I'll put it this way. I've never really seen a compelling reason where it should be necessary to do that where a saner design wouldn't suffice. I haven't had to break this rule during my career (at least, not that I recall - certainly not recently). Anytime I've gone down that path design-wise, a bit of thought usually leads me to a more elegant design anyhow.
My rules may not be the same as other rules - hence, why I would never suggest they be codified into the language rules. To me, that's par
Re: (Score:2)
You probably posted that comment using software written in C++.
nyah! (Score:2)
You probably posted that comment using software written in C++.
And you probably posted the comment using software written in C.
Re: (Score:2)
K&R C? Like the one where parameter types are listed after the function declaration? I'll take C99, please.
Otherwise, I agree. C++ and object oriented programming in general are a backwards way of programming that introduces a lot of mess and anti-patterns for the platform you're actually programming. Allocating global memory for local scratch space and string operations, for example, blows my mind.
That said, there are nice points to C++. Templates offer some capabilities and a lot of readability o
Re: (Score:2)
RAII is the main thing. It lets you make all code exception safe, and never have another memory leak or file handle leak, with none of that annoying garbage collection. Code becomes so much more readable (and secure) when errors are dealt with as exceptions, instead of every damn function call being an if block.
Re:Clean cool crisp refreshing (Score:4, Insightful)
Encapsulation
Polymorphism
Productivity
To name a few....
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Yup. Long compile times certainly make me more productive. Posting on Slashdot while a big C++ project takes 10 minutes to recompile because I added a field to one class in a header and triggered a complete recompile definitely makes me more productive.
So compile using ccache, or more jobs in your make, or move those frequently changing headers to a private class so other code objects don't know when there is a change.
Re: (Score:2)
So compile using ccache,
ccache only skips recompiling if the preprocessed output is the same. It makes no difference in this case.
or more jobs in your make,
The C++ compiler uses 500MB-1GB of RAM in each instance on nontrivial C++ code. Increasing the number of jobs is more likely to cause swapping and make it even slower than to give a real speedup.
or move those frequently changing headers to a private class so other code objects don't know when there is a change.
Sure, refactor 500,000 lines of (mostly) someone else's code. Good solution.
Re: (Score:2)
Who the hell has 16 cores and one gig of ram? These days, unless your application is extremely exception in compilation demands, most people easily have the resources to allow for concurrent compilation. Hell, people were compiling the Linux kernel with -6 and far more a decade ago.
Blaming a language for underpowered woes is pretty sad. There's a reason why people constantly tell you to use the right tool for the job.
Re: (Score:2)
Encapsulation
You mean like how C encourages you to use opaque types in the header and hide implementation details, while C++ requires you to use the Pimpl pattern to do the same thing and forces you to expose implementation details in the header by default?
A C++ class header is not the same thing as a C header - an interface is the same thing as a C header. It's one of the many tricky aspects of C++ if you think it's an extension to C.
Re: (Score:2)
If I have to recompile everything that uses a class because that class now has one more PRIVATE member variable, that means I don't have compile time encapsulation.
No language I'm familiar with has thta encapsulation in its 'class' implememtnation - what you're looking for is 'interface'. An interface has no private anything, no implementation, fixes the dependency issues that the pimpl patttern fixes, etc. You don't need an 'interface' keyword for this in C++ (though 'struct' is often used that way in recent code) because of its support for multiple inheritance.
The C++ 'class' keyword (and 'struct', too) can be used to declare either a class or an interface. It's
Re: (Score:2)
Hm, no. There are significantly better languages that get this kind of thing (and many others) right.
Actually, the guy you replied to showed critical thinking and the ability to adequately judge a claim. What was your contribution again?
Re: (Score:2)
C is basically portable assembly. C++ should be portable OO assembly... but it has ballooned to the point that its strengths have become weaknesses.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
The ability for idiots who shouldn't be programming in the first place to use something *easier* at the cost of society at large.
The ability of arrogant jerks who don't realize that trivial nonsense is not a neat trick (but it does trespass on others' attention span) to complicate trivial tasks, to ignore solutions to problems which have been around for 20+ years, to take pride in their ignorance a la 1990... meh... why do I bother is the question. You deserve you.
Re:Clean cool crisp refreshing (Score:4, Insightful)
It took about 45 minutes to write and test (and I'm not a Ruby expert by any means) and it's less than 100 lines, compared with the 1000+ line C program. I call it a win for Ruby
Challenge accepted! I bet I could rewrite that program in less than ten lines of Perl code. Any takers?
Seriously now, I've tried nearly every language I can put my hands on. I still use C when the going gets tough. One of the reasons is that C is not likely to change.
I've done a lot of small systems in Python lately and, yes, for a small system I can get it going faster than in C. HOWEVER, now comes Python 3. They tell me now that I should have used "from future import division". Apparently I'm too stupid to read the proper documentation, it was clearly stated in PEP 947, or something like that, that the behavior of the division operator would change. It seems that I should read carefully every single one of those thousands of PEPs to make sure they won't pull the rug from under my feet.
If I ever have to go through every division operation in a program to check which ones can stay as '/' and which ones have to be changed to '//' I will take the opportunity to rewrite that program in C, as, I can see it clearly now, I should have done from the start.
Re: (Score:2)
Nice way to troll Python, which is completely unrelated to the topic at hand, with completely irrelevant and misleading information.
You do realize that Python 3.x purposely broke capability with 2.x? And you complaining that a program which was written against 2.x *might* require some minor changes to run against an incompatible version 3.x? What is wrong with people...
Re: (Score:2)
Re: (Score:2)
...unlike C# which Microsoft seems to enjoy having confusion surround (see the HTML/JavaScript fiasco)
It is not confusing. Microsoft used HTML/Javascript for Active Desktop. They used HTML/Javascript for Windows Explorer folder views. They used HTML/Javascript for Windows Sidebar. And they will use HTML/Javascript for the tile interface of Windows 8. It doesn't mean that .NET will disappear, just like .NET did not spell the demised of the standard Windows API.
or Java, which Oracle seems intent on bringing confusion, branding, and licensing to
It has always had branding and licensing, long before Oracle came on the scene. Look at how they went after Microsoft for license and trademark viola
Re: (Score:2)
Say what you will but I've recently decided to go back to my roots and work in C and C++ just for that reason -- there's never a loud outcry that the languages will die a horrible death or go anywhere.
Amen, brother! I've just presented the same argument here [slashdot.org]. After Python 3 came out, for me it's just C or C++ for programs that need to last for an indeterminate time.
Re: (Score:2)
Seriously? People are still confused about that?
They showed off their new tile interface for Windows 8 and Microsoft did not say anything about .NET _or_ C++. Clearly, this means that .NET is being kicked to the curb.
Sure, their bet in the mobile space depends on .NET. Their browser extension, which recently just got a major revision depends on .NET. And they are rumored to
Re:Speaking of obnoxious (Score:5, Informative)
Re: (Score:3)
Someone who actually gets it. Garbage collection is a crappy hack that caters to shitty, incompetent programmers. The kiddies should look up RAII. They might learn something.
Re: (Score:3)
> The problem seems to be Java-Programmers who
> don't understand the concept of RAII.
Don't worry, most of them probably don't understand garbage collection, either. They just think it's a magical black box that does magic things... and then look bemused when they have a core leak.
Re: (Score:3)
Which is why many of them still write code that leaks memory even with a garbage collector. One of the worst offenders are the .NET programmers who write software that leaks GDI handles like crazy and cause all sorts of crashes and bizarre behavior because they didn't bother to learn anything about managing memory and realizing that *gasp* even in a GC language you still need to make sure to be careful that all your resources are being properly released. This is further compounded because there have been
Re: (Score:2)
Given the new pointer types: unique_ptr [att.com], shared_ptr, and weak_ptr, I'd say that the spec actually disagrees with you. You practically never actually need to call delete if you use them.
It even provides the basis for implementing a garbage collector within C++ (ABI [att.com]), although one is not required to meet the spec.
It's quite fair to compare and contrast C#, Java, and C++ as long as you realize they each offer benefits, with trade offs. Not to mention, Java nor C# are truly interpreted. They are both compiled l