C++ Status at the end of 2015
bfilipek.com
bfilipek.com
That was me being cautious, see http://blogs.msdn.com/b/vcblog/archive/2015/04/29/c-11-14-17... - "I previously listed "Atomics in signal handlers" as No, because despite maintaining <atomic>'s implementation, I didn't know anything about signal handlers. James McNellis, our CRT maintainer, looked into this and determined that it has always worked, going back to our original implementation of <atomic> in 2012."
Also really excited for co-routines. I never liked using promises.
Wow, had no idea ranges and contracts are on the table too. With all this stuff, C# is really losing its appeal.
So C# might lose its appeal to you specifically but not to many people ;)
This is a big benefit of C# (and every other remotely popular language except C and C++; how C compares to C++ is a separate question.) Arguably, some systems cannot afford a garbage-collected language, but your comment kinda assumes you can choose between C# and C++.
Modern C++ is pretty nice if your team is ready to embrace it and leave old styles behind. I still use C# for utilities and prototypes but for production stuff, users' time is more valuable than mine.
Contracts and some of the stuff in the new Core guidelines take it further.
Everyone's needs are different obviously. The stuff I work on has tons of users and start up perf and minimal memory usage are primary requirements. Most of our bugs are nullptr access violations or straight up programming errors that C# doesn't shield you from either.
Not really. RAII still allows for dangling pointers/references. The STL is vulnerable to iterator invalidation. Ranges are likewise vulnerable.
> Contracts and some of the stuff in the new Core guidelines take it further.
How do contracts help memory safety?
The ISO Core C++ bounds/lifetime checker does, yes, but as I mentioned in the other comment I don't know whether it is still going to be C++ in practice.
> The stuff I work on has tons of users and start up perf and minimal memory usage are primary requirements.
Those are valid reasons to use C++, yes.
> Most of our bugs are nullptr access violations or straight up programming errors that C# doesn't shield you from either.
C# doesn't make null dereference undefined behavior :)
2) The invalidation rules are pretty well known at this point, but I concede that it's much better to have compile-time validation. A good STL impl will have iterator debugging, which catches iterator invalidation. e.g: debug mode in GCC
3) Regarding null, you're theoretically right, undefined behaviour and all. In practice[1], accessing a null pointer/reference will result in a crash both in C# and C++.
When developing Java apps (C#'s big brother), the biggest sources of bugs during development were null pointer exceptions and unhandled exceptions propagating to the event loop and killing the UI thread.
[1] There are strange cases such as http://blog.llvm.org/2011/05/what-every-c-programmer-should-...
No, it doesn't.
std::vector<std::unique_ptr<int>> x;
x.push_back(std::make_unique(1));
auto& y = *x[0];
x.clear();
std::cout << y; // use after free
This is, of course, a toy example. For lots and lots of real examples, search Web browser engine bug trackers for UAF vulnerabilities. (They have been using smart pointers exclusively for a decade or so now.)> A good STL impl will have iterator debugging, which catches iterator invalidation.
Valgrind and ASan catch UAF too and have been around for years and years. Yet we still have a ton of UAF vulnerabilities.
In your example, it would be a major red flag in code review to create a reference like that. Some code constructs are just asking for trouble.
I think the reasons behind still having errors despite tools like Valgrind and ASan are: a) many devs don't know about them or use them b) you need 100% coverage to remove all errors
Using said engineering practices will not result in a completely big-free program, but it will have a significant impact on the quality. For something that doesn't have the nightmare security profile of a browser or various other exposed services, that can be just fine, even if not ideal.
I'm guessing the reason why C++ yields lower memory usage than C#/.NET is because RAII and reference counting ensure that memory is always freed as soon as it's no longer needed, whereas garbage collection only ensures that memory belonging to unused objects will be freed sometime later. Is that correct?
Though GC has its own advantages too--the ability to compact being the main one.
*edit: ~16 MB for .Net Native, ~10 MB for C++ using latest VS2015 targeting x86.
Not going to matter for most apps, but for system UI that has to run on multi-user servers it does ;)
And surely you'll agree with the GP that they're not really comparable.
I would absolutely not choose C# for building a UI app even today.
Even if memory safety is important to you (the point of this subthread)?
I would personally prefer to use various engineering practices such as static and dynamic analysis, unit tests, etc rather than change programming languages.
There's also the other side of this argument: my last project was Java. C++ would have allowed us to port more easily to other platforms (a current pain point) and get better performance in combination with OpenGL (another major pain point), however, the project constraints would have made it extremely difficult to bring a C++ project to market with the resources we had.
There is no static and/or dynamic analysis out there that effectively stops programmers from writing UAFs (to name one especially problematic class of memory safety problems) in C++ over and over. This is despite decades of work on it. The language itself is fundamentally hostile to analysis.
I also dislike "one language to rule them all" thinking. Web app and network backend developers shed that mentality a long time ago, and the industry is better for it. Java, Ruby, PHP, Python, Go, JavaScript, Scala, etc. are all used on the server where their niches are strongest, and this is great! The industry would have been in much worse shape if they all had tried to stick with C++.
I agree with your other points, though--the choice of programming language has to be balanced among many factors. Sometimes security against RCE doesn't matter or isn't relevant, and the crashes caused by memory safety problems can be lived with. But I don't think we should pretend that C++ is safe, or as safe as other languages. It just isn't, and no tooling so far has been able to make it so.
"my last project was Java. C++ would have allowed us to port more easily to other platforms"
I'm not saying that you must wrong for your particular situation, but as soon as you've compile Java, you've essentially ported it to a massive number of platforms. https://en.wikipedia.org/wiki/List_of_Java_virtual_machines
If anything a dependency on OpenGL would limit your choices.
Not ideal, but perhaps workable.
Well, to be fair ISO Core C++ (mentioned in the blog post) with all safety profiles turned on is designed to fix this issue. I have my doubts about whether it'll actually succeed in still being C++ though, as it rules out so much valid modern code (and I also have doubts, or at least unanswered questions, about its soundness/expressiveness).
I'm sure the C++ community will gradually work to address the (huge!) security issues through heroic effort, but it's doubtful that anything meaningful can be achieved when "undefined behavior" remains an acceptable definition of the semantics of an operation.
EDIT: Don't get me wrong... I am in awe of the recent efforts of the C++ committee (and co.), and I hope they succeed in this endeavour!
Well, I should be fair. I may be wrong here, but my understanding of ISO Core C++ plus all safety profiles is that this will no longer be the case: there will be no undefined behavior in this particular dialect of C++, assuming the effort to create this dialect succeeds.
We won't know what the delta is between "migrating to ISO Core C++ with all safety profiles" and "migrating to another, memory-safe language with a good FFI" until ISO Core C++ is complete and widely deployed. My instinct tells me that this delta will not be particularly wide--that is, that porting most existing industry C++ code to totally safe ISO Core C++ will not be much easier than rewriting that code in Go or Swift or whatever. (Look at how long the Python 2 to Python 3 transition has been, and consider that ISO Core C++ is much farther away from industry C++ than Python 3 was from Python 2.)
I could be wrong about this, though--we'll have to see.
I'm just waiting for standards-sanctioned A(lgebraic)DT data type support -- it's bound to happen at some point! :)
> Single-quotation-mark as a digit separator
I have to admit to utter befuddlement about why you would ever want that. (Presumably they will also require scanf to honor this as well . . . that'll be fun).
Just when I thought the C++ committees were getting their heads screwed on straight. Am I missing something, or is this another trigraph disaster?
100000000000000
100_000_000_000_000(Or, rather, as ((uint64_t)100 * 1000 * 1000 * 1000 * 1000), but you'll need to do something to prevent overflow in most languages, anyway.)
According to Wikipedia [1] underscore was proposed for C++ but rejected because it conflicts with user-defined literals.
Is there any reason they could not have used space? Offhand, I can't think of anyplace where a space in a literal number would not currently be illegal, so adding that as a separator should not introduce any problems, but C++ has grown massively in complexity since I last seriously used it so I could easily have overlooked something.
[1] https://en.m.wikipedia.org/wiki/Integer_literal#Digit_separa...
alias dfk='LC_NUMERIC=de_CH df --block-size=\'\''1024'
alias duk='LC_NUMERIC=de_CH du --block-size=\'\''1024'
that help me when something like du -h won't do.Also, the underscore is used to separate words in variable names, where it is significant.
int my_long_var_name, mylongvarname;
are different variables. But in numeric constants, the underscore has no meaning. 186_282.397 and 186282.397
would be the same number. This is inconsistent.Finally, in a variable width font, the single quote is much less visually intrusive than the underscore, which tends to be a wide character.
I would like to see this form used universally. In my wildest fantasies, I'd also allow either '.' or ',' as the decimal indicator. That would make some of my European friends happy.
"""
The note was written for committee members, but “escaped into the wild.” Here are a few comments from the web:
• http://www.reddit.com/r/programming/comments/33us7z/what_wil... up_on_c17_goals/
• http://forums.theregister.co.uk/forum/1/2015/04/27/c_daddy_b... ections_for_v17/#c_2500733
• https://news.ycombinator.com/item?id=9441245
As you see, people outside the committee also have strong opinions. Those opinions can depart radically from the ones I hear in the committee and from reality.
"""
I'd definitely recommend CPPCast (http://cppcast.com/) for learning about the C++ community.
Pluralsight has some decent videos as well.
It's a website that looks like a C++ dev made it.
Still big in medical devices too, embedded or not.