Bjarne Stroustrup Announces the C++ Core Guidelines
alphabetsoup writes: At CppCon this year, Bjarne Stroustrup announced the C++ Core Guidelines. The guidelines are designed to help programmers write safe-by-default C++ with no run-time overhead. Compilers will statically check the code to ensure no violations. A library is available now, with a static checking tool to follow in October.
Here is the video of the talk, and here are the slides.The guidelines themselves are here.
Here is the video of the talk, and here are the slides.The guidelines themselves are here.
If you take all the fun out of finding memory leaks and stack overflows what fun is there to C/C++? I mean I just love using AutoPtr everywhere, it's perfect!
Harrison's Postulate - "For every action there is an equal and opposite criticism"
CPPCoreGhost?
For example, one of the guidelines here is to always prefer make_shared over std::shared_ptr(new ...). That's good advice for a couple of reasons
1) it allocates your memory for the shared_ptr control block and the object contiguously
2) it means you can't separate the allocation from the creation of the shared ptr and end up with an owner who's not looking at the shared ptr in-between.
However, it also means that if you have any weak_ptrs pointing at the end of that shared_ptr, the object itself won't go away until all the weak_ptrs do too (because the control structure won't go away until they do, and they're contiguously allocated).
Imperative programmers reinvent functional programming concepts, but in a shitty way. More at eleven.
"print" is deprecated. You must now use the safe_print_n function and get a safe pointer back using the SafetyFirst() method of the SafeLiteral class.
Because safe by default, amirite?
Safer than you could possibly imagine.
He has a connecting to all the features he put into C++ and any coding guidelines should include thing that should not be used. First among those are exceptions, unfortunately Bjarne has never wanted to admit C++ exceptions were a mistake.
Its nice to see efforts to drive the complexity out of the design/implementation of safe code but this won't due much to improve the already error prone task of debugging optimized code. You don't always have the luxury of running a debug build, especially when analyzing a crash dump from a customer and templated/STL C++ constructs are often too complex for debuggers to parse properly. Hopefully these efforts reduce the number of crashes enough to justify the added complexity of debugging the crashes that still occur.
You did not hear this sound? It was like whizzzz or whoooooosh or alike.
Safe but you have to pay a lot of attention to not make it accidentally unsafe, thus.. sort of safe?
Ada95 added OO features including clear mechanisms (enforced by the compiler) on how to get OO design benefits without runtime performance costs or risks for dispatching.
Much of what I've seen in C++ is a response to problems in the original language design, particularly gaps or errors of omission.
Computer Science in the 21st Century seems to be full of stuff we knew about in the '80s and '90s, but forgot.
Bjarne has never wanted to admit C++ exceptions were a mistake.
What should a method that fails do instead of returning an exception? Should it instead be set up to explicitly return two different types of return value, namely the object that it's supposed to return if it exceeds or an object describing the failure if it fails?
I think it is sad, looking around on the responses so far, to see, yet again, that the overwhelming response to this is to jeer at anything that is beyond people's comprehension. I guess what it boils down to is, that far too many who call themselves coders can't be bothered to sit down and work out a detailed plan before barging ahead. You get nothing but trouble from OOP if you think in terms of simple scripts, and that is particularly true of C++.
Just like "don't use goto", or "don't use threads", etc., these guidelines and recommendations are really great to prevent beginners from making hard to spot errors, but all those variations and features exist for a reason and have a use.
"Within C++ is a smaller, simpler, safer language struggling to get out." -- Bjarne Stroustrup
Very true, C++ would struggle no matter how laudable the goal is.
sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
You claim that all exceptions should be fatal. I hope this was sarcasm. If not, then for example, if a program lacks a configuration file because it is being started for the first time, what lesson ought to be taught, to whom, and why?
More than half of Stroustrup's talk was concerned with pointers. In 2015, we still need the kind of effort Stroustrup is calling for, simply because a fairly advanced OO language STILL uses pointers, with the risk of dangling ones, of pointers outliving the thing they point to, etc. etc. ? I dunno, people... but this is one of the main reasons I never made the switch to C++.
Religous speak to God. Insane are spoken to by God. When all shut up, one can finally hear Shostakovich in peace
The core language spec isn't much over 400 pages, and the library adds something less than a thousand additional pages. Ever since around 2000, when O'Reilly published "Java in a Nutshell" in four volumes, I've stopped listening to complaints about excessive library size.
There are unit testing frameworks for C++. Unfortunately, C was not straightforward to parse, and so C++ isn't either, so that hinders the development of additional tools. I expect Clang to improve that eventually, but it's a language problem that can't be fixed.
There are safe ways to pass pointers around, and there's a lot of work going on on how to do it. It reminds me of people discovering exception safety after the first C++ Standard came out.
"When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
I found Rust
I've found it best not to talk about Rust around here. The language has already accumulated a legion of haters at Slashdot. Rational discussion about Rust sans the office punklets happens at Hacker News.
It was anticipated that Rust would motivate some progress in C++ memory safety. Some have argued that if that is all that Rust accomplishes it is worthwhile. Too bad an entire language has to be invented to get some folks off the dime.
The uptake of Rust is so large though I don't think it's going to go away just because C++ adopts some degree of compile time memory safety. The language is great on it's own merits, there is none of that half century of baggage to slog through and the entire stack and all native Rust third part modules provide the same memory safety guarantees, barring 'unsafe.'
These things, combined with the never ending stream of opportunities the segfaults and overflows that C/C++ cannot avoid providing will ensure a chunk of mind-share, haters be damned.
Maw! Fire up the karma burner!
Safe as houses, safe as fuck!
All those moments will be lost in time, like tears in rain.
Checked exceptions are probably better viewed as part of a the API, in the sense that if exceptions didn't exist, these would be implemented as return parameters, which you would also have to declare and either check, or pass to the calling code.
Maybe all exceptions should have been checked, but the difference (not always followed) is that checked exceptions are supposed to be for things the deployed program or user has some control over (missing file, sleep interrupted - that is, things you should plausibly expect to happen), and unchecked exceptions are for bugs or uncontrollable things (NULL, out of memory - bugs you should have fixed, or can't expect). In other words, handling checked exceptions should be as natural as checking to see if fopen returned NULL in C.
Not done as consistently as it should have been in Java though. Made them confusing, inconsistent, and irritating to a lot of people who just decided checked exceptions were wrong rather than misimplemented (similar: operator overload abuse makes many people dislike the entire idea).
It will give you code so secure that it can even order some fruity cocktails with those little umbrellas!
We used to have a Bill of Rights. Now, with the rights gone, all we have left is the bill.
Or the ever popular MessageBox with ERROR! in the caption, no text and the choice between the two buttons "yes" and "no".
Just to keep the user sweating whether he could possibly save his last 2 hours of work just by hitting the right button.
We used to have a Bill of Rights. Now, with the rights gone, all we have left is the bill.
Half century? Are you counting from Algol?
That said, the cruftiness of C++ is one of the things that keeps me from bothering to properly learn it, however much I respect its newer developments. Another is that its place on the scale of abstraction isn't often a place that I need to go personally: C or Python usually makes more sense for me.
Where on that scale would you say Rust lies? Is its target use software that lies on the boundry between systems software and applications, e.g., web servers?
if a program lacks a configuration file because it is being started for the first time
That isn't an exception. That's a given.
Based on a cursory Google search, "given" appears not to be a term of art in programming. What is the C++ idiom to handle givens? I know Python's idiom is Easier to Ask Forgiveness than Permission (EAFP), which uses exceptions liberally because they're less likely to be vulnerable to time of check to time of use (TOCTTOU) attacks on a multitasking system than the alternative Look Before You Leap (LBYL) paradigm.
Exceptions were devised to handle exceptional events, not to handle your main flow of control.
"Use the settings in the configuration file except when the configuration file does not exist." How is that not "exceptional"?
If you had written it in C++ instead of BASIC it wouldn't be offtopic.
"Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo" becomes legal C++.
Nothing ensures that the config file exists, and your program is responsible for creating it.
You appear to state that the std::ios::fail() paradigm of C++, which allows an inconsistent stream object to continue to exist, is superior to the exception-on-failure paradigm of Python. Do I understand you correctly?
Seasoned professionals have given us decades worth of mostly unnecessary buffer overflows.
FWIW, Lakos' book (he wrote only one, but it's a good one) was published in 1996 with a possibly new edition in 1997. Since some of the recommendations appear quite specific, I don't know how applicable it is in 2015.
"When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
The dead tree versions are expensive. The PDFs are far cheaper, and less dangerous.
"When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
Except in weird circumstances, valid C++98 code will work in C++14, or it will fail to compile and it'll be obvious what needs to be changed. I've never had any problems upgrading C++ versions.
There is no C/C++ language. There are two languages, C and C++. Both are useful, but the common subset is suboptimal C and really bad C++. Know which language you're working in. Consider other languages for projects that don't play to the strengths of C++ (for example, Javascript will work much better embedded in web pages than C++).
There are good C++ compilers for Linux and BSD. There's no reason to restrict yourself to C, unless you're working on a particular project with particular requirements. (Don't try to submit Linux kernel patches in C++, for example.) Both g++ and clang are much better at standards conformance than Visual C++.
"When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
Myself, I am currently being impressed by the efforts of the golang community.
No generics? Not only not a set collection in the standard library, but no reasonable way to define one?
Go is a nice, tidy, compact little language. But...
Congratulations: You just created a time of check to time of use (TOCTTOU) race bug. Consider what happens if another process deletes the file between the call to isfile and the call to open.
exceptions should be used much more sparingly in C++ than in Python because they don't work as well in the former.
Could you explain what you mean by this? Is it that Python tends to throw (predictable) exceptions in cases where C++ has (unpredictable) undefined behavior?