News for hackers. Stuff that matters.
Re:We have C++14 by tdees40 on Monday August 18, 2014 @04:17PM (#8194407)
This is totally true. The downside, of course, is just how much code exists that is written in pre-C++11 dialects, and how many programmers are trained to write that sort of code.

I like way more of C++11 than I liked of the prior version, but there's just so much that's accumulated over the years. I wonder if breaking backwards compatibility is the key, but then I look at Python 3 and think, well, probably not.

Re:We have C++14 by wfunction on Monday August 18, 2014 @04:44PM (#8194564)
> The downside, of course, is just how much code exists that is written in pre-C++11 dialects, and how many programmers are trained to write that sort of code.

I do the same thing. Not because I can't write C++11, but because I still encounter systems with older compilers that I want to run programs on. What, is this surprising?

Let's face reality: it's a little unreasonable to expect every system you work on to have a compiler less than 3 years old.

Especially true on older Linux systems, it's sometimes a massive pain or even pretty much impossible to upgrade the existing compiler in a package-manager-friendly way (try upgrading Ubuntu 12.04's compiler to GCC 4.9, for example), so you'd have to compiler the compiler from scratch. Which is a pretty massive PITA and more or less requires a PhD of its own for GCC (Clang is a little better). And on Windows VC++ isn't always exactly following the correct standard. It's not necessarily outright impossible, but it's pretty impractical.

Re:We have C++14 by Guvante on Monday August 18, 2014 @06:35PM (#8195087)
> Let's face reality: it's a little unreasonable to expect every system you work on to have a compiler less than 3 years old.

If you are running Linux, this is one thing that Windows gets right. (Although as you say VC++ has some catching up to do still).

Re:We have C++14 by adrusi on Monday August 18, 2014 @07:27PM (#8195248)
Linux is on all parts of the spectrum here. Ubuntu LTS and Slackware are going to remain outdated by design. Arch Linux almost always have the most recent stable releases of GCC and clang, and you can even build development snapshots from AUR
Re:We have C++14 by shmerl on Monday August 18, 2014 @09:35PM (#8195658)
You don't need to use the compiler from the distro to release for that distro. There is such thing as cross compilation after all. Most do it out of habit and because distros don't offer such services out of the box. But if you build the cross compiler, you can use the newest one even if the distro ships the older.

For example I had a building machine running RHEL 5 which was building for both RHEL 5 and RHEL 6 while using gcc 4.8.2 for both (cross compilers).

Re:We have C++14 by wfunction on Tuesday August 19, 2014 @12:05AM (#8195988)
You say "if you build the cross-compiler" as though it's as simple as "if you cross the street". Have you ever tried building GCC? I've wasted days on it and in the end still failed to make it work.
Re:We have C++14 by shmerl on Tuesday August 19, 2014 @12:55AM (#8196070)
It is hard if you do it all manually. There are helpful tools like Crosstool-NG for example which make it easier.

See also https://en.wikipedia.org/wiki/Cross_compilers#External_links

Re:We have C++14 by exDM69 on Tuesday August 19, 2014 @10:18AM (#8197379)
> Have you ever tried building GCC? I've wasted days on it and in the end still failed to make it work.

I've hand-built GCC for half a dozen of different target architectures over the years and it's perhaps one of the most stable pieces of software when it comes to building it. I've only had one build failure over the years and that was unstable from git (even that usually works no problem).

To build GCC, follow the simple steps on the GCC manual. With a modern fast computer, it's all done in an hour or two (of mostly waiting).

Re:We have C++14 by wfunction on Tuesday August 19, 2014 @01:32PM (#8198643)
I don't know how you manage it, but I can tell you it is not reasonable to expect people to compile every compiler they want to use on every system they want to use it.
Re:We have C++14 by exDM69 on Wednesday August 20, 2014 @05:52AM (#8201702)
> I don't know how you manage it, but I can tell you it is not reasonable to expect people to compile every compiler they want to use on every system they want to use it.

If you're dealing with bare metal projects (kernel programming or micro controllers), building binutils and gcc for cross compiling from source is pretty much required. There are scripts that help and some distros have cross compilers in their package managers.

But building GCC is not difficult and it pretty much works first time, every time.

Re:We have C++14 by tshepang on Tuesday August 19, 2014 @03:17PM (#8199217)
No one implied people are expected to compile every compiler they want to use on every system they want to use it. Point was it's not hard. Maybe link to a message where you detailed your troubles?
Re:We have C++14 by 72deluxe on Tuesday August 19, 2014 @04:24AM (#8196414)
Heh! I am stuck on VC++ 2010 at work. I gaze longingly at C++11 features but can't use them. A pity, as the same codebase is also built under XCode and Clang.
Re:We have C++14 by sitkack on Monday August 18, 2014 @07:12PM (#8195207)
> upgrade the existing compiler in a package-manager-friendly way

This is your problem.

Build a new compiler using the old compiler and install the entire new toolchain in /opt/my-gcc-4.9-0xfoof . rsync this new compiler to any machine you want. The package managers (people and code) a here for our suffering.

Re:We have C++14 by jevinskie on Monday August 18, 2014 @05:47PM (#8194903)
When LLVM started to require C++11 (which we use as a library), my team decided to statically link libstdc++ into our product on Linux. Now we just depend on glibc (and we use symbol versioning to keep the required version to a minimum). It sounds like you ship source though, so it may not be an option for you.
Re:We have C++14 by dfan on Monday August 18, 2014 @04:44PM (#8194558)
Also, how many companies are afraid of the new features and deprecate them internally (fearing compiler bugs, lack of portability, and/or unmaintainability). I still haven't had a chance to use full C++11 in a professional context.
Re:We have C++14 by kyllo on Monday August 18, 2014 @07:00PM (#8195164)
Like Google for example? Their C++ style guide is pretty restrictive, here's an expert C++ programmer's takedown of it: https://www.linkedin.com/today/post/article/20140503193653-3...
Re:We have C++14 by yongjik on Monday August 18, 2014 @08:44PM (#8195499)
FWIW, things like range-based for loops, "auto", and unique_ptr are pretty standard in Google these days.

Still no exceptions, though.

The thing is, when you have a single codebase that is maintained by thousands of engineers, you have to make concessions. There is no place for "rockstar programming": everything must be, in a sense, bland, so that it blends seamlessly into the work of thousands of others.

Re:We have C++14 by Silhouette on Monday August 18, 2014 @09:14PM (#8195594)
Not that I disagree with your real point about writing maintainable code rather than "clever" code, but if you have a single codebase that is maintained by thousands of engineers then I would argue that you're probably doing something horribly wrong already, and using exceptions is hardly exclusive to so-called rockstars.

I don't really understand organisations that still use C++ in 2014 but then knock out such fundamental parts of its functionality, but then looking at the design priorities for Go, clearly at least some people at Google have very different preferences to my own, so YMMV etc.

Re:We have C++14 by yongjik on Tuesday August 19, 2014 @01:04AM (#8196083)
I agree that using exception is hardly noteworthy these days, but consider that in the context of a codebase that has evolved for more than a decade. I guess, ten years ago, "let's not use exceptions; they aren't worth it" was more justifiable.

In any case, the decision was made, and we have millions of LOC where every single API is built with the assumption "No exceptions here." In that context, introducing exceptions seems suddenly a lot more trouble than its worth. Well, YMMV, and in any case I'm not a decision maker so what do I know.

* BTW, I think "a single codebase maintained by thousands of engineers" is the single best thing I found in Google, as it opens up infinite possibility of learning new tricks, new APIs, and sometimes new projects. (Of course, everybody complains that every API is implemented at least three times, but imagine how worse it would have been if every project had its own codebase.)

Re:We have C++14 by claudius on Tuesday August 19, 2014 @03:37AM (#8196325)
This is of course a valid reasoning to forbid the use of some features at this particular company. However, it renders advocating the Google C++ style guide as an ubiquitous style guide for all C++ programming rather moot.
Re:We have C++14 by yongjik on Tuesday August 19, 2014 @02:50PM (#8199080)
Completely agree. I hope nobody's naive enough to say "Well, if this style guide works for Google, it sure should work for our company...!"
Re:We have C++14 by Game_Ender on Tuesday August 19, 2014 @02:49AM (#8196246)
Not adding much value here, but it is a lot worse. You get 5+ implementations everything, and every project is different just because.
Re:We have C++14 by p0nce on Tuesday August 19, 2014 @10:14AM (#8197363)
Perhaps you would have less millions of LOC if you could reuse third-party libraries which happen to use exceptions?

Also no exceptions implies no failing constructors which is plain ugly as a constraint.

Re:We have C++14 by srj on Monday August 18, 2014 @09:04PM (#8195560)
This article is a bit strange. Complex initialization in a constructor can make it more difficult to unit test a class. Copy constructors aren't prohibited, it's just recommended that you remove the implicit versions when your class shouldn't be copied. Some of the C++11 features were blacklisted because Google has had its own implementations. In some cases these C++11 features are now allowed and the previous implementations have been deprecated, it's just that the conversion process took time.

In general if you're going to work with other people I believe you need to be a bit flexible on coding with them rather than trying to be hard headed about your own style. It's important that people not be surprised when they work with your code.

Re:We have C++14 by cubbimew on Wednesday August 20, 2014 @11:25AM (#8202709)
The guide that's publicly available says "If your class needs to be copyable, prefer providing a copy method, such as CopyFrom() or Clone(), rather than a copy constructor" I think that's insane. Or, at the very least, surprising to encounter when working with someone else's code.
Re:We have C++14 by tdees40 on Monday August 18, 2014 @05:29PM (#8194806)
Oh my goodness, yes. The HN crowd probably doesn't appreciate the extent to which people who sling C++ at BigCorp are limited by the rules the company sets.
Re:We have C++14 by jsmeaton on Monday August 18, 2014 @06:02PM (#8194961)
It's not just C++ either. "What do you mean you want to use LINQ (in C#)? No one understands that rubbish".
Re:We have C++14 by voltagex_ on Monday August 18, 2014 @07:11PM (#8195202)
* Don't use LINQ

* Don't use var

* Don't use dynamic

or even better,

"You've only got .NET 2/3 installed"

Re:We have C++14 by guiomie on Monday August 18, 2014 @07:27PM (#8195247)
I can't look at code without var's anymore.
Re:We have C++14 by mhd on Tuesday August 19, 2014 @05:09AM (#8196513)
"We haven't vetted anything other than Java 1.4 on our BigAutoCorp PCs, so if you want to write a desktop app..."
Re:We have C++14 by jahnu on Tuesday August 19, 2014 @06:00AM (#8196607)
And should Go or Rust achieve widespread adoption the same thing will happen to them. So the point is moot.
Re:We have C++14 by Nursie on Monday August 18, 2014 @07:24PM (#8195242)
The main downside I can see with it is how much implicit behaviour there is. Sometimes it's very hard to figure out what's actually going to happen with a line of code.

That said it's quite expressive now, you can do a lot with a little code, which is always nice.

Re:We have C++14 by blt on Tuesday August 19, 2014 @11:15AM (#8197731)
Yes. As much as I love C++, I sometimes get very scared by the implicit behavior. This is why I don't understand the hate on exception-free, more C-like C++. You can still reap huge benefits from std::algorithm, iterators, classes, templates, while stepping back to a more manual approach for allocation and lifetime management.
Re:We have C++14 by JoeAltmaier on Tuesday August 19, 2014 @11:19AM (#8197759)
You definitely have to pick and choose from C++ based on environment, your staff's experience, what kind of problem you're solving. Allocation in particular is problematic in every language (even GC languages) especially when latency is an issue, so that's probably what I manage 'manually' most often.
Re:We have C++14 by sdegutis on Monday August 18, 2014 @04:56PM (#8194631)
Meh, breaking backwards compatibility isn't all that bad. It will be a bit rough for a few years, but it's worth it to clean things up for a brighter future.
Re:We have C++14 by ChuckMcM on Monday August 18, 2014 @06:12PM (#8195004)
The weird thing is, why not just call it something new? I've always wondered if they called Perl 6 "Smeebly" or something would it get a better reception? C+++ ? My personal taste is that if you break backwards compatibility that is when you have a 'new' language and you just just name it as such.
Re:We have C++14 by tshepang on Tuesday August 19, 2014 @03:27PM (#8199268)
People would, on the surface, see a different beast, even though it remains 99% the same language. Not worth it.

With this argument, every release that adds a new keyword (for example) would have to be given a new name, since it will very likely break some code. Question that remains is how much must the changes be before the thing deserves a new name.

Re:We have C++14 by untog on Monday August 18, 2014 @05:08PM (#8194680)
The example of Python 3 is a good one. "A bit rough for a few years" might be an underestimation.
Re:We have C++14 by sdegutis on Monday August 18, 2014 @05:18PM (#8194741)
I don't think Python 3 is a good example. Unlike other cases where languages broke backwards compatibility, the Python community actively discouraged upgrading for years, constantly saying "don't use Python 3" for years, and Python 2 was actively maintained in parallel to Python 3, with features constantly being back-ported. It would have been much smoother overall if they'd just dropped Python 2 altogether, even if a little more painful up-front.
Re:We have C++14 by pmelendez on Monday August 18, 2014 @05:47PM (#8194902)
I believe he was being sarcastic. And breaking backwards compatibility can be really bad. Imagine if the next version of C would break the previous one. How many operating systems and critical software would have to be rewritten in order to be maintained.
Re:We have C++14 by cwyers on Monday August 18, 2014 @06:05PM (#8194974)
Python is in a different boat than C++. If the Python language leaders decides to make a version that breaks backwards compatibility... well, they also make the most popular Python interpreter. The group responsible for the C++ standard isn't in the same position at all, they have to convince the different compiler groups (GCC,LLVM,Intel,Microsoft,etc.) to implement it for them.
Re:We have C++14 by pmelendez on Monday August 18, 2014 @06:22PM (#8195037)
Agreed but even there were a monopoly for the interpreter/compiler you would see people marrying with a specific version and having the implementer to maintain two different branches of the compiler for security reasons.
Re:We have C++14 by Silhouette on Monday August 18, 2014 @09:24PM (#8195626)
Imagine if the next version of C would break the previous one. How many operating systems and critical software would have to be rewritten in order to be maintained.

I don't think the idea is to force existing software to be rewritten. It's to provide a clean break so that new software isn't saddled with the baggage of the old. Over time, most of the older software is retired or replaced, and the industry migrates to use the better tools with more and more projects.

This seems a very reasonable strategy, as long as your ABI or equivalent interface specifications can remain compatible for the common subset of functionality, so that programs built using the new language can still use libraries written in the old one. (See also: Every successful general purpose programming language in decades has offered a FFI for C.)

It doesn't work so well if you don't have proper formal standards for your old and new languages. It's also much harder to achieve in practice if your code is effectively running on some sort of virtual machine so you can't have that clean break at the ABI level, which might be one reason why several languages have failed to make a convincing big jump in recent years (Perl 6, Python 3, etc.).

Re:We have C++14 by bluetech on Monday August 18, 2014 @06:39PM (#8195102)
Maybe they can use something like javascript's and perl's "strict" annotations.