Stroustrup Reveals What's New In C++ 11
snydeq writes "Bjarne Stroustrup discusses the latest version of C++, which, although not a major overhaul, offers many small upgrades to appeal to different areas of development. From the interview: 'I like the way move semantics will simplify the way we return large data structures from functions and improve the performance of standard-library types, such as string and vector. People in high-performance areas will appreciate the massive increase in the power of constant expressions (constexpr). Users of the standard library (and some GUI libraries) will probably find lambda expressions the most prominent feature. Everybody will use smaller new features, such as auto (deduce a variable's type from its initializer) and the range-for loop, to simplify code.'"
I mean, it's not, but it makes it sound like C++11 is a minor update. Lambdas, auto, concurrency, are these minor updates? There's a lot of interesting stuff in C++11!
Wood Shavings!
- Godai
That said, as a professional C++ developer working in HPC, this is exciting.
Stop pretending and get back to your FORTRAN!
S-expressions, continuations, hygenic macros...
Comment removed based on user account deletion
Don't wonder, hover your mouse cursor over the variable and behold the glory of tooltips.
Now what happens when you change the name of a return type from a commonly used function? Have fun with your maintenance nightmare. If you are lucky the compiler will complain, if you are unlucky you break existing code without knowing it.
-1 overrated isn't the same thing as "I disagree".
Prohibiting use of "var" is gross over-kill.
There are times where it's use is not recommended, certainly. But even in those cases, it can lead you to the point that there's a "bad code smell" where methods aren't named well, variables aren't named well, classes aren't named well.
var x = foo(); is definitely less readable.
But var x = new ComplexObject(); is every bit as readable, if not more so, because you don't have a redundant "ComplexObject" in the declaration. You always know exactly what type "x" is. It's also very useful in cases where the return type is a complicated generic. it saves a lot of typing, and is definitely more readable.
Here is a very good discussion on the benefits and uses of "var":
http://resharper.blogspot.com/2008/03/varification-using-implicitly-typed.html
- Spryguy
There are three kinds of people in this world: those that can count and those that can't
In some ways, a lot of what is being added to C++ makes me think of Scala, just less readable.
While the additions and extensions certainly make things more interesting and potentially more powerful/easier for the *individual* programmer, I look forward to seeing what sort of interesting train wrecks happen when larger teams try to make use of these features. I certainly hope the debuggers are being updated to be useful when someone's written a template that uses a #define'd macro to specify a closure that is passed through an anonymous function, etc.
This strikes me as the next generation's 'multi-threading' -- where almost every programmer claims they can handle multi-threaded programming, but very few actually do it well. Particularly in teams when interactions require coordination. Going to take a whole new round of winnowing the wheat from the chaff when it comes to finding developers who can actually use these features well without driving their coworkers insane.
which is in the new standard
No it's not. Vendors have always been allowed to tack on GC. None of the big ones do.
-1 overrated isn't the same thing as "I disagree".
That's way to verbose. I overloaded the ;
I don't think you'll see a lot of people flaming C++, there just aren't that many people that care one way or the other anymore.
I think some of the new features look nice but mainstream use has been shifting away from C++ for a while and I'm not sure I see these new features drawing many back...
"There is more worth loving than we have strength to love." - Brian Jay Stanley
In general I agree.. but for some stuff (iterating through a collection for instance) I think it is acceptable. When you start dealing with collections of collections, iterator types become a nightmare!
in Java of course you can just use the foreach syntax (Kitten kitten : kittens).
chances that oracle will see the light? :-)
Last time they saw the Sun, it did not end well...
I don't agree. auto (or var) very rarely hide any information which is not immediately visible. For example there are trivial cases where auto (or var) just save extra typing:
var my_object = new my_class();
v.s.
my_class my_object = new my_class();
Here using var just saves a few key struck (or a lot, in case my_class happens to be a type with a particularly long name). In any case the type of my_object is perfectly known and quite visible so I think using auto is just fine.
There are however cases that a complex type is used while we actually DO NOT care for the type per se. For example in C++ consider the case for a lambda function:
auto my_fun = [](int i) { return i * i; };
Here I actually don't care about the exact type of my_fun. All I care is that it take an int and returns an int which I can see clearly. Finally, another case could be situations in template programming where insanely complex types are used/generated and we don't want to (or even cannot) type them again and again. Also I guess in Java or C# you might get away by cheating and using an object (I hate it when people do that!) but we don't have that luxury in C++.
This is a C++ thread. We don't have the fancy refactoring tools that C# has.
-1 overrated isn't the same thing as "I disagree".
I guarantee you will quickly come to hate the new "narrowing" errors, for example any time int converts to float inside initializer curlies, or double to float. As a language feature, this lies firmly in the category of wanking.
That said, my code is all full of lambdas now, thankyou. On the other hand, lambda syntax is uglier than sin. While a lambda can do anything a lexically scoped nested function can, it is not pretty. Now obviously, there is no reason not to support proper lexically scoped nested functions, as GCC already does. Arguing that they are now unnecessary because of lambdas is, again, wanking. The practical fallout is that when you move a lambda-style helper function to global scope or to member status, you have a bunch of editing to do, to remove the ugly auto/lambda bits.
Another big disappointment is, nothing was done to address the good features C99 has that C++ does not. Designated initializers and variable size array parameters, to name two. Wanking again.
On the whole, there is too much wanking going on in the C++ stewardship process. Guys, you need to remember, C++ does not exist only as a means of compiling the STL.
Have you got your LWN subscription yet?
Here's a construct that I used today:
If I want to iterate through this, I need to create a variable of type
. Since I'm not totally sure of the exact type of my map, I need to find out where it's declared and copy that. If I then change that vector to a list, I need to change every iterator that uses that. Okay, I should probably use a typedef, but since I'm going to be using it in a statement along the lines of
It should be pretty obvious from context what the type is. We know begin() returns an iterator.
Can see this being useful inside templates as well, and for splitting up complex calculations.
I was amused by the comment "If that incr(0) were allowed either some temporary that nobody ever saw would be incremented or - far worse - the value of 0 would become 1. The latter sounds silly, but there was actually a bug like that in early Fortran compilers that set aside a memory location to hold the value 0. "
Back then, I wrote Fortran subroutines which took computed dimension arrays by declaring the arrays with crazy bounds, numbers I hoped would never be used as constants, and then "assigning" the real bounds to the "constants".
Those were the good old days.
I think he either forgot his LSD today, or took too much. Not sure which yet.
Support the EFF and Creative Commons. The war is coming, and they're supporting you...
Because var still works within the type system and gives you compile-time errors, and casting to object is a massive sledgehammer that delays errors until runtime (with all of runtime error checking's glory, like only failing some of the time, which you can basically read as "never on a developer's machine, sometimes on TQA's machine, and always on a customer's machine (unless support is on the phone with them)"), and a stupid idea in general (I'm looking at you, Objective-C!).
<xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
(object) ~= (void*)
I mean that in spirit, not in actual details. Yes, I know there's about a billion, trillion ways they're different.
<xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
It is easy to refute your argument on memory safety and auto with a single line of code:
auto obj = make_shared( arg1, arg2 );
lambda expressions can only be assigned to an auto, because the actual type is compiler defined.
auto some_callable_type = []( float f ){ return f * f; };
Currency isn't supported? What more do you want apart from: threads, mutexes, atomics, thread local storage, concurrency safe memory model, futures, promises, async tasks and thread exception transfer?
The majority of it is implemented. http://gcc.gnu.org/projects/cxx0x.html
<xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
> But C++11 describes a standard that absolutely nobody has ever got anywhere close to, so I don't imagine that there's going to be a lot of drive to adopt it.
All popular C++ compilers already implement large parts of C++11, so the chance of seeing widespread C++11 adaption in the not so distant future is pretty high. Also this wasn't really any different with C++98, which essentially no compiler supported on release and which then took a few years to gain widespread adoption.
Auto in K&R was a storage class, not a request for compiler type inference.
Wait, there is an object oriented version of C?
Theses are days of miracle and wonder.
This sig is not paradoxical or ironic.
C with classes is a derogatory term used to describe programmers and code which wraps C-style code and various bad practices with classes. You end up with things like custom string and array classes, using memcpy instead of std::copy, printf instead of std::cout, FILE* instead of std::fstream, copy paste instead of inheritance and void* everywhere.
-1 overrated isn't the same thing as "I disagree".
Now be careful, because inheritance was not really intended for code reuse. If it does help with code reuse, that's a positive consequence, but it's not what inheritance is for, first and foremost. See Liskov substitution principle and all that jazz.
A successful API design takes a mixture of software design and pedagogy.
in Java of course you can just use the foreach syntax (Kitten kitten : kittens).
Which is also a C++11 feature, now. Except they call it a "range-based for loop."
for ( Kitten& kitten : kittens )
Using a reference is optional, I think, but is probably the better way to go in the general case (so you can modify the object instead of a copy).
"auto" was always implemented, since the very first version of C, it just had a different meaning - it means that variable has an "automatic storage class" (as opposed to "static storage class" etc). Because automatic was the default, it was almost always redundant, but it did have a meaning.
It actually goes way back to B, which only had a single data type - machine word. Variable declarations looked somewhat like C, but, for the lack of type, they started with the storage class instead, i.e.:
In C, we've got types, so you'd normally write "static int y" for a static local, and just "int z" for an automatic one - "auto" being implied. However, C inherited some of B's semantics as "default int" - i.e. if the declaration is clearly a variable, but it omits the type, assume that type to be "int" (i.e. machine word). So in C the above code snippet from B is actually valid, and declares x, y and z to all be ints.
Then "auto" got inherited by C++, which dropped the "default int", making auto completely redundant - you couldn't write "auto x" in C++ anymore, and in all other cases where you could use "auto", like "auto int x = 123", it was always redundant. So when they appropriated it for type inference in C++11, it was technically a breaking change - it just wasn't ever used by anyone in production code in the old way, so nobody noticed.
Garbage collectors only manage memory. Smart pointers, on the other hand, can manage any kind of resource - whatever you release in your destructor.
That's why languages like Java and C# still need stuff like Closeable and IDisposable, and syntactic sugar for them to avoid writing try/finally ladders. Whereas in C++, resource management has always been done right, and memory is treated as just another kind of resource.
Exactly. I even use it in the var x = foo() case, but that's because much like the honey badger I just don't give a shit. ctrl-space and hover over tells me everything I need to know.
The main purpose of "auto" is to allow for (auto p = arr.begin(); p != arr.end(); p++) {... } without worrying about the type of arr.
No, it's not. The above is written as follows in C++11:
And, of course, you can just as well use the actual element type there instead of auto.
Comment removed based on user account deletion
I gave up on C++ years ago. It has really become a 'geek cred' language with a constantly changing 'right' way an aesthetic, perfect for figuring out if a fellow geek is from the same snapshot of teaching you came from, but that is about it. It has become overly complex with redundant language features that one needs to keep relearning in order to understand other people's code.. and of course with complexity comes the ability to show off your knowledge through doing things in 'clever' ways.
Good for showing off.. bad for getting actual work done, esp for projects that last more then a year or two.
Maybe because pure C++ with all its advances looks worse than random perl code or assembly.
Im not asking for cobol like scheme, but come on, enough of the !@#$%^&*(){}|} magic
Liberty freedom are no1, not dicks in suits.
So what? STL isn't suited for all possible uses, sometimes you need your own string and container classes.
Don't be a zealot, pragmatic programmer should find the right trade-off between reusing code and writing an optimal one for a specific problem/area. Nothing can be optimal in all cases - sometimes you need to be as close to hardware as possible at the expense of unreadable/inflexible code (for me, those are the most interesting and challenging areas), and sometimes you only care about maintainability of your code by a disposable programming drone.
Coding etudes
In one corner we have memory, which is 99% of the "resources" needed to be managed
Go ahead, count the number of calls to "Close" and "Dispose" in a real world C# or Java app. Then get back to us with some solid number for that 99% claim.
Simple example, open a file, write to it, let the dtor flush and close. If flushing fails, you won't know, because dtors can't return anything, and exceptions in dtors is a big no-no (because, incidentally, there's no GC to free the stuff). That's _wrong_.
Suppose you're right, and you detect that flush failed during close. What are you going to do?
Suppose furthermore that you have an exception in flight, and you've just had flush fail in your finally-block (assuming C#/Java). What are you going to do now?
If you want exception safety, you need RAII, period. If you have RAII, you might as well use it for memory.
Smart pointers are a lousy GC scheme that does memory badly (ref counting is inefficient, especially on MP systems, and cannot handle cycles)
Those claims that refcounting is inefficient are old, but somehow they only show up in synthetic tests. In real world apps, something written in C++ is invariably faster and more responsive than alternatives written in managed languages. That's precisely why C++ is still used far more widely for desktop apps, and is used almost exclusively anywhere perf really matters (like games).
And there's weak_ptr for cycles.
For anything but the highest performance computing, Java gives the same performance. In fact, for service code, Java gives better performance. I've benchmarked a prime sieve with the same algorithm in Java, and C++ (with and without the -g flag). It's a good test of integer arithmetic+basic language performance because the compiler cannot optimize away loops. Java is only 5% slower than stripped C++. Java is significantly faster than C++ with the -g flag. But Java actually retains all the symbol and frame information. So, in case of a crash, you often have even more to go on than you would in C++ with -g.
Any guest worker system is indistinguishable from indentured servitude.
>Time to join the 21st century grandpa. FILE* leaks.
Hell no. And get off my lawn.
printf() isn't typesafe, but it's a fuckton more readable than all that cout formatting stuff. Also, the fact that it's not typesafe isn't really an issue if you don't suck - trivial unit testing will pretty much show any problems immediately. Besides, gcc/g++ is nice enough to warn you about egregious ones now.
FILE* leaks? I assume by this you mean when sloppy programmers fail to close their files and you start burning through file descriptors. Sounds like a bug to me, and again, stop sucking. Or do what we do - throw an object with a destructor containing fclose() around it. Then you get all the awesomeness of of FILE* (including those awesome formatting commands like fprintf and fscanf) without the danger of your file staying open when something goes nuts.
Why on earth would you want memcpy() to call anything? It's a low level byte move. Anybody with five minutes of familiarity with it should know that. If you wanted something different, use the assignment operator.
void* have all sorts of applications, most recently to me in writing architecture neutral VMs where really all the native machine knows is that it's moving around some sort of pointer.
Now the custom string and array classes? That I'll agree on. Troll on.
So what?
I think he simply claimed that you have to deal with C++ written by C programmers all too often. That's my experience, too.
STL isn't suited for all possible uses, sometimes you need your own string and container classes.
I don't see what that has to do with the above. I suppose there are some rare cases where the standard library isn't appropriate, but are you arguing this is an excuse *never* to use it?
By the way, your reference seems severely dated. Some of its complaints are still valid, but seem based on the state of STL support ten years ago.
(Not arguing with your broad point that these new addirions to C++ will be useful.)
Goto is no way sufficient for modern programming. You also need some way to manipulate whatever passes for the (effectively stack) constructs that allow nested parameters and locals. And you need some way to hide the bulky extra code (as in text macros and such).
I got bit on this when I should have known better, back in '97 or so -- using a Fujitsu CoBOL, forgot that the old CoBOL PERFORM was kind of like the old BASIC GOSUB. Found myself trying to use recursive calls in some UI code, and the variables I was expecting to be local to the procedures were, of course, global, and my fancy UI screen would keep blowing up.
I'd have had to implement effective stacks all over that code to keep it from blowing up. Gave up and reverted to the older, much harder to understand UI.
Computer memory is just fancy paper, CPUs just fancy pens with fancy erasers; the 'net is just a fancy backyard fence.
Dante's Inferno. Sample quote:
Obscure, profound it was, and nebulous, So that by fixing on its depths my sight - Nothing whatever I discerned therein.
All popular C++ compilers already implement large parts of C++11, so the chance of seeing widespread C++11 adaption in the not so distant future is pretty high. Also this wasn't really any different with C++98, which essentially no compiler supported on release and which then took a few years to gain widespread adoption.
C++98 was worse. There was extern templates, which was a major mistake (read the proposal to remove it from C++11 for some amusement). There was Microsoft, who lost interest in C++ around that time, and condemned a generation of Windows programmers to Visual Studio 6 and a weak standard library implementation. And yet gcc was usable around 1999 or so. I started using the std namespace in late November that year.
Oh, and before you mention weak references (to be totally honest, I am not even sure if there is a standard weak reference in C++)
std::weak_ptr in C++11. Been there for 7 years now (originally as std::tr1::weak_ptr), and for a few years before that in Boost.
I'll mention that very few C++ programmers know what they are.
That's the problem with those programmers, not the language. C++ is powerful and fast by design; that, unfortunately, also makes it complex by design. It's not a language for everyone, and Java and C# certainly have their very large niche. But C++ is a very powerful tool when used right.
The syntax of C++ is so crowded that the language is only used for low level stuff where the extra 5% performance boost is a big deal.
That's emphatically not true. I've repeated it several times already in this thread, and I'll repeat it again: most desktop software today is written in C++. Heck, even a fair bit of OS X software is written mostly in C++, especially if you look at the size of it (MS Office, Photoshop). The reason for that is that perf boost (relative to Java/C#) is more like 20% for common tasks; but, more importantly, there is a marked responsiveness improvement due to lack of GC. And responsiveness is some really subtle stuff - it's not quite the same as "fast", but it's very sensitive to stutter on the order of tens of ms (a delay over 100ms is already noticeable by the user).
You can write good UI software in managed languages, but then you need libraries that are themselves written in native code, at least rendering and input layer. Otherwise you end up with a clumsy pig like Swing.
I think he simply claimed that you have to deal with C++ written by C programmers all too often. That's my experience, too.
I'm probably one of those C programmers. I use C++ features when I feel they are appropriate, but my definition of "the right thing" changed over years. I started to value custom-tailored solutions, often hardware- and problem-specific. No longer I'm trying to find (or create) code that would fit all (or even the most) cases, and micro-managed security is of lesser concern to me.
I don't see what that has to do with the above. I suppose there are some rare cases where the standard library isn't appropriate, but are you arguing this is an excuse *never* to use it?
There are always multiple tradeoffs involved, that's why I am very wary of saying "never". STL is no silver bullet, this is what I'm saying.
E.g. STL is bad at managing memory, it's hard to make it NOT allocate it dynamically - yes, you can write a custom allocator for it, but STL allocators are inflexible and also - for some poorly thought reason - manage object construction, not just memory allocation, making this unnecessarily hard. STL is a template library, and templates produce separate implementation for every type used - whereas you can have a single void *-based container for all your POD types, with templates providing just minimal wrapper. Also, STL makes it hard for you to control how often memory (object instances) is copied - there's no way to influence its behavior if memory copying tops your profiler results.
If you are developing primarily for desktop computers which are quite beefy (and also vague in terms of hardware), this may matter less (although it will never cease to matter - just think of all that slow code running on our desktops which eats the performance improvements we still (marginally) get, making desktop performance appear flat since 2004), but if your target is well-defined hardware-wise and if you know/set "upper bounds" for all the practical problem sizes your program is designed to handle, you can think of more optimal solutions for your case. This is one of reasons why you can still play the newest games on 2005 hardware (XBox 360) which hasn't even got an out-of-order CPU, while running the newest desktop software (not games!) on PC of the same era is problematic.
To sum up, I'm not saying "never use STL", but I would not say "always use STL" either. People claim that using "standard" code helps you create more secure, robust, performant programs - but in my experience, you will end up running a lot of custom tools (all kinds of profilers and validators) anyway before shipping your binary, that makes the point of "performant/secure code by design" moot. When profiler tells you that some code in an STL container underperforms, reimplementing it - or even understanding why that happens - is harder than fixing/improving your own implementation, yet you'll probably have to do that anyway. And no one starts "from scratch" these days, each "low-level" programmer I know has their own set of STL-alike classes.
By the way, your reference seems severely dated. Some of its complaints are still valid, but seem based on the state of STL support ten years ago.
Well, it is perhaps improving with new "move" constructors and whatnot, but that's actually a problem: it's better to have cross-platform code with predictable behavior than code that is supposedly optimal everywhere, but which depends on highly varied implementations. What good is it for me to know that some compilers (e.g. gcc), on some platforms (e.g. x86), handle new, C++11-ready STL well - gcc isn't particularly good at optimizing code even for x86, and another compiler that is a good optimizer may not support the newest features and make my STL-heavy code suck.
P.S. Also, STL (in implementations I saw) is written in quite unreadable, convoluted style - I always wondered why. This is of course less rele
Coding etudes
I'll mention that very few C++ programmers know what they are.
That's the problem with those programmers, not the language. C++ is powerful and fast by design;
Not really. Most Java programmers know about the weak references in Java. And in Java they are less necessary than they are in C++ (because the C++ gc model steaming from smart pointers is based on reference counts). If a necessary tool goes underused in a certain context, then it is the problem with how the context is presented to its audience -- not with the audience.
But C++ is a very powerful tool when used right.
Any tool is only as powerful as it is useful. It is not reasonable to judge tools only by the peak performance achieved by its most committed users.
The reason for that is that perf boost (relative to Java/C#) is more like 20% for common tasks;
And I posted a fairly simple benchmark which shows otherwise.
there is a marked responsiveness improvement due to lack of GC.
Only for a certain class of problems. Btw, I would say that mark-and-sweep is a type of gc -- not that it is gc. Reference count is also a gc method. But that's a semantic argument. And I am more than willing to admit that it is a matter of opinion.
You can write good UI software in managed languages
All application languages are managed.... by the operating system.
Otherwise you end up with a clumsy pig like Swing.
Swing is only clumsy because it attempts cross-platform functionality (which necessitates that it supports only the least common denominator of features). It's not clumsy for any kind of inherent performance design issues in the Java language.
Any guest worker system is indistinguishable from indentured servitude.
#warning rant coming
"printf instead of std::cout"
I love c++, but it definitely has some dark spots, even still the long overdue c++0x update (c++11 whatever). Thank deity we finally have standard smart pointers, better templates in various ways, move semantics, etc. It was really necessary to finally have that, even if it was a decade late (I'm sure we lost quite a bunch of good c++ programmers and projects to more newfangled languages in the delay). Even though we often won't be able to use it until all compilers (and developers) in use for a certain codebase are updated, it is a start.
c++ streams... After exceptions the second worst mistake in c++... c++ needs something good for that functionality, but streams and exceptions don't help.
Beware of std::cout, it is not thread-safe and is a gigantic pain in the expletive for outputting formatted text. The utility of overloading the shift operator for interfacing with streams is overrated. std::endl is a curse word. streambuf is an ugly hack.
while std::string is usually an improvement over the plain 'char *', it also is as often overkill as it often is underpowered. Why else would so many people have their own string class? Why would Qt have QString? It's because std::string and fstreams are severely lacking... standard c++ needs more syntactic strength in tokenizing, parsing, formatting, transforming, combining, and type-converting of string content. What is there, in the standard, is, well, imho kludgy. I'm not saying that I have the answer to what exactly it needs, it just needs something better.
c++ still has a lot of catching up to do. Libraries like boost should really only have their sandbox and legacy code left, and libraries like qt shouldn't need to redo/replace basic functionality. It should be possible to get a proof of concept implementation (aka badly optimized but mostly functional and not too many bugs for a demo or trial) working quickly as easy in c++ as it does in certain other languages. Until then, it should work hard to catch up before we lose most programmers to other languages.
--- Hindsight is 20/20, but walking backwards is not the answer.
They need to just start from scratch and create a limited subset of features that doesn't pretend to be C and doesn't lug around all of the past mistakes in the standard, and call it C+++.
They did. Check out the D Programming Language.
Just because the U.S. is a republic does not mean it is not a democracy. Democracy/republic are not mutually exclusive.
printf() isn't typesafe, but it's a fuckton more readable than all that cout formatting stuff
Readable? Meh. Localisable? Now that is an important attribute. Consider this trivial bit of code:
You want to localise this, so you wrap each string in a function that returns the localised version (by the way, gcc and clang have an attribute that you can put on functions that says if the output is safe to use as a format string in any case where the input is). So now you have something that looks like this:
Okay, no problem. Now let's consider the C++ equivalent:
Harder to read? Maybe, but the tokens are all in the order that they'll appear in the output, so I'll give C++ that one. Now let's localise it. How about something like:
That's fine, right? No more complex than the C version. Well, almost. Let's make French the target language. We want to turn 'the black cat' into French. Now we have a problem. In French, the word order is different. The result we want has the colour after the noun. No problem in the C version, the format string is just translated as "Le %2$s %1$s". The arguments are reversed (well, it's a little more complex because you also need agreement between the noun and the article, but I'll skip over that for now - it can be solved in the same way). What about the C++ version? Well, because the word order is in the code, not the data, you need different code paths for English and French. And that's just with a three-word sentence. Now consider the kind of sentence that actually appears in a typical UI. Consider German word-order rules. Your simple C / Objective-C strings file has to be replaced by a huge tangle of C++ code.
I am TheRaven on Soylent News
My example is a trivial example. Go and look at some real code. In big applications, we use this pattern in Objective-C all the time. It's a trivial way of constructing localised strings. Now go and look at the mess of template metaprogramming that people use to do the same thing in C++...
I am TheRaven on Soylent News
Operator overloading is to address the ambiguity of having by-value and by-reference passing of objects being possible via different semantics in the language.
If I have a pointer and write:
ObjType* pObjRef =
then it's pretty obvious I have an object reference.
But but what does
ObjType Obj2 = Obj1;
actually mean?
C++ defines this type of transaction as always being a copy operation. But an object is a complex datatype - doing a straight copy of all it's memory doesn't necessarily give me sensible behavior. So you need operator overloading to let you enforce sensible behavior.
That you can also use it to create syntactic sugar or completely illogical behavior doesn't make it bad though. And absent a garbage collector, I'm not sure it actually makes sense to do what C# does and try and treat all object variables as references (in that when would you deallocate things?)
In real code, you localize based on entire messages, not individual words. How do you localize an English word that, with one spelling, may be a noun or verb and, in the latter case, may be of different tenses? You would need the context of the entire message and a natural language processor to translate the word. (Localizing the common word "The" in isolation as you do is fraught with errors.) Consequently, it's better (and quicker and easier) to translate entire messages rather than individual words.
That's fine, right? No more complex than the C version. Well, almost. Let's make French the target language. We want to turn 'the black cat' into French. Now we have a problem. In French, the word order is different. The result we want has the colour after the noun.
It seems like it would be a lot easier to just change the word order of the offending languages than to screw up perfectly good C++.
C with classes is a derogatory term used to describe programmers and code which wraps C-style code and various bad practices with classes. ...
"C with classes" was the name given to the language before it was named C++.
Prohibiting use of "var" is gross over-kill.
Gross overkill is, of course, the main point of most coding standards.