Interviews: Ask Bjarne Stroustrup About Programming and C++
In addition to being the creator of C++, Bjarne Stroustrup is a Managing Director in the technology division of Morgan Stanley, a Visiting Professor in Computer Science at Columbia University, and a Distinguished Research Professor in Computer Science at Texas A&M University. Bjarne has written a number of books and was elected a member of the National Academy of Engineering. He will be doing a live Google + Q & A within the C++ community on August 20th, 2014 at 12:30pm EST, but has agreed to answer your questions first. As usual, ask as many as you'd like, but please, one per post.
Even though I'm an unemployed programmer since the banking crash, I still believe in C++. I can't fathom programming in any of those interpreted languages.
Your language has become one of the most popular in history. If you were launching it today, how would you "market" it? What do you think is the unique selling point?
If you had to create a new language and compiler from scratch, what would be the ideal size and composition of the team? From what fields would you try to recruit people?
Do you think the H1B system is a joke? and they are useing it to get cheap work out people chained to the job?
Sometimes well-established languages keep adding new features and syntactic constructs until most developers are not even aware of all the possibilities, and use maybe 20% in their usual daily work. The old features and syntax are kept around for compatibility and to keep the old guard content, even if cutting them would lead to faster compilation, more elegant language and less confusion.
This may be part of the reason for the constant introduction of new trendy languages with radically simplified syntax and libraries... Which then follow the same pattern. Few languages are introducing new paradigms, many are trying to be a "better" C++, Java, LISP, JavaScript or Perl.
Do you think this cycle is inevitable, or could it be a good idea to sometimes clean up the syntax and the obscure features in new specification versions, to keep the established languages more competitive?
Why work for the vampire squid?
C++ is one of the most complex, inscrutable computer languages ever created. When I read about C++11, I was surprised that it layered more complexity and inscrutability on top of what was already there (like the weird lambda syntax). I wonder if C++ has become an over-the-top example of how not to do a programming language. Is that by intent, or did it just happen? In future versions of the language, will any cosmetic changes be made to create a more understandable language that doesn't overload a small set of symbols and keywords, so that normal programmers have a chance to figure out the language? The language seems to have reached the point that C++ gurus design it for other C++ gurus, and everyone else ignores it. C++ was once the up and coming language of choice, but it has become so difficult that programmers have considered it damage and routed around it. Are you comfortable with this fate for C++, as a niche language for insiders, or do you want to use your influence to rehabilitate the language so that more programmers will use it?
Are there any future plans to gear c++ more towards the increasingly popular web development, or will that depend on 3rd party libraries, etc.?
How do you feel about the evolution of C++ since it was first implemented with Cfront? What began as a pretty straightforward language has been expanded to significant complexity. Has this evolution been positive, or has it been an attempt to make the language apply to too many possible applications?
"To those who are overly cautious, everything is impossible. "
What is your favourite programming language that isn't C++ (or C)?
Maybe the premise of this question is wrong... but I seem to recall reading somewhere that you hate C but built C++ on top of it because it was popular. Is that true and if so, do you ever feel bad about the bait and switch?
Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
Has everyone responsible for the std::vector<bool> tragedy been kicked in the nuts until they are no longer at risk of reproducing?
Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
What do you regret most in C++ and how would you like to change it?
The general consensus as I understand it is that the <iostream> wing of the C++ standard library is hairy, convoluted, time inefficient, and space inefficient in implementation. What's the better solution? <cstdio>? Is Boost.Format, as shutdown -p now suggested, any good?
One of the recent concerns raised with C++ compared to other popular languages is the breadth of the standard library. I know that the C++ standard committee was looking at adding a C++ transformed version of Cairo to the standard. And of course their is boost. What else do you see coming to address the perceived API shortcomings?
With so many new languages writing a spec and then a standard compiler to conform to the spec, I'm curious how you feel about writing a spec and not a compiler.
How do you think this compares to other efforts? Do you enjoy this aspect or do you occasionally get your hands dirty with a particular compiler source? etc.
What is your opinion of the the "Hour of Code" as promoted by CSEdWeek? Does it trivialize computer science education?
When are you going to recant your decision that types are more impotant then syntax clarity and tell everyone you made mistake putting the * next to the type instead of next to the variable where it belongs?
Do you think that one thing holding C++ back is the lack of a standarized binary interface?
Currently if I want to make a module that can be consumed by others (whether than is others using a different language, or a different C++ compiler, or even just to use a pre-built module without sources) I have to export everything as C and use its (de-facto if nothing else) binary standard.
I think an ABI for C++ would increase its "real world" attractiveness considerably with little, if any, overhead. Do you agree, or are there issues around this that make it a significant challenge (apart from vendor adoption of course).
Workforce diversity is a big issue these days. What steps has the c++ working group taken to increase the numbers of female and minority contributors? C++ (perhaps unfairly, due to the popularity) is often criticized in feminist circles for being a patriarchal programming language. Will you be taking steps to address those concerns?
Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
Do you think AI will start replacing junior programmers in the foreseeable future, similar to car drivers and call center operators?
Why doesn't C++ have in language support for memory allocation?
And don't give me that baloney about it being a library feature: We all know that memory allocation of variables on the stack is not handled manually by the programmer.
If you don't add it C# and Java with their GC awfulness will continue to eat C++'s lunch.
When is C++ going to natively support multiple return types?
i.e.
Right now we can use a struct hack, but native support would be appreciated.
_When_ are pragmas going to be standardized instead of relying on brain-dead proprietary extensions where MSVC does things one way and GCC another way? i.e. I'm specifically talking about the idiotic verbose
intead of having a native way to hint the compiler about how hot or cold a function is.
Lastly, C++ has been extremely complex. When is C++ going to simplify the total over-engineering of the language?
When will Boost ASIO make in into the standard library? C++ really needs something of this magnitude for networking and asynchronous event handling. I have not heard much on N3360 since it was proposed.
the growth in cynicism and rebellion has not been without cause
How do you feel about the fact that Darl McBride said that SCO owns C++?
Source 1
Source 2
Source 3
Source 4
I'll see your senator, and I'll raise you two judges.
Why doesn't C++ have in language support for memory allocation?
C++ has the new and delete operators, whose low-level operation a class can customize. Could you clarify what you're asking for?
If you don't add it C# and Java with their GC awfulness will continue to eat C++'s lunch.
The problem with tracing garbage collection as implemented in Java, C#, and the like is that it tends to break the Resource Acquisition Is Initialization (RAII) idiom seen in C++, where an object's destructor is responsible for freeing non-memory resources held by the object, and the language supports calling this destructor automatically in many cases. Instead, GC languages have what I call "viral disposability": a conventional name for an explicit destructor method that an object's owner must remember to call, and anything holding a disposable object must also be disposable.
Would it suck less if they used c++?
Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
I learned C++ the hard way: by hacking on a million-LOC program. It's taught me to loathe the language. It's big, complex, and incomprehensible. I once spent three days chasing a bug through a twisty little maze of templates, all different. I routinely struggle with the implications of static vs. not, member variables vs. globals vs. statics, functions that are part of a class vs. those that aren't... Getting code to even compile is often an exercise in trying something, running the build process, then trying something else, lather, rinse, repeat. It's left me frustrated enough to want to drive to College Station and scream at the walls.
All of this has left me wishing for the days of C, in which I'm quite fluent.
Nevertheless, the world seems (perhaps overly) enamored of C++, and I'm probably going to have to deal with it. How do I learn to at least tolerate it, if not like it, instead of actively hating it?
Disinfect the GNU General Public Virus!
"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone". Do you still feel this way, or are you more comfortable with modern smartphones than the phones that were available at the time of your statement?
The comments and questions here look overwhelmingly negative. On the other hand, all of this passion only exists because people are using C++.
I'm a fan of C++ overall, but it seems to me that C++ templates are a bit of a disaster. They're so complex that I doubt that anybody but you and P. J. Plauger *fully* understands them. Also, when they're actually used, they often result in bloated, slow code - as I recently experienced when stepping through some STL string functions. Further, they bring on a lot of portability issues, evidently due to the difficulty that even the compiler folks have had in understanding and implementing them. Therefore, many programmers minimize their use of templates, both in their own code and in their use of templated library code.
Compared to the complexity of C++ templates, the C macro preprocessor provides a rudimentary form of templating via its very simple and powerful paradigm of text substitution. I've had some success implementing a limited form of generic (type independent) programming in C using just the C preprocessor. I've had much less success doing generic programming via C++ templates.
If you had templates to do all over again, what would you do differently? Was all the complexity of C++ templates (e.g. "partial specialization") really necessary to achieve its goals? Were the goals maybe too ambitious?
if (condition) statement;
or
if (condition)
statement;
or
if (condition) {
statement;
}
Lastly, C++ has been extremely complex. When is C++ going to simplify the total over-engineering of the language?
The same way you simplify any other multi-paradigm language: Learn a subset and use it. PNG, SVG, and the like have "profiles", where an implementation can choose to leave particular sets of features unimplemented and declare this in its profile. Now my own question for Bjarne: Do you plan to implement anything like these profiles in C++ to make well-defined subsets easier to learn?
With C++ standardization picking up steam, and C++'s backward compatibility being a feature, I'm wondering, will there ever be a non backward compatible version of C++ ?
Not as in purposefully making all those millions of lines of code written in the past decades not compile, but using all the hindsight to fix those choice that turned out to be not so good in practice and allowing a "cleaner" language to come out of what looks more and more like a mess of accepted proposals.
I see lots of people complaining about C++ being "Too big". I personally don't mind, nothing is stopping me from using that simpler and maybe more modern subset of the language I want, but aren't you worried that all those old features might hold C++ back and slow down standardization and "innovation" in the future ?
C++ is the most powerful tool I've had the chance to use, and I'm glad to see it being actively improved again, but I'm not sure how long it can keep being at the same time all the languages it used to be and wants to become.
C++ is more or less a superset of C (give or take a few minor issues), why has regular C continued to thrive?
Donte Alistair Anderson Roberts - hi son!
Karma: Chameleon
Compiliers allowed you to move from brutal machine-language numbers to language-like or math-like statements; from number to problem-domain concepts. Compilers were complex pattern recognition, rule-base translators that implemented this. I've seen some early ads touting COBOL as programming in "almost English" (har har). As with most soft-A.I. results, once you did it, it wasnt really considered A.I. anymore.
If you could add one feature to C++ (either the language or the standard library) and have it adopted in the C++ standard and supported by all the compilers etc, what would it be and why?
Couldn't auto & concepts replace templates in those simple use cases where you don't want compile time Turing completeness, but just a simple generic function working on anything with an operator+ or maybe with an argument matching the concept of a container.
I want auto as a type for function arguments. Wouldn't that be simpler, easier to read, beautiful ?
Seriously.
Apple recently introduced a language they call Swift or Objective-C without the C. It is technically a completely different language from Objective-C though. When C++ started out it had the major benefit that it was (mostly) compatible with C which at the time was immensely popular, making it trivial to mix new C++ code with existing C code. Today C is still a popular language but not as widely used as it once was. Assuming that C++ could drop C compatibility, how would you take that opportunity to improve C++?
A lot of C++ complexity comes from trying to maintain compatibility with legacy code. Many of the new features could have been implemented more cleanly if the legacy support was dropped.
What part of C/C++ legacy has been the most troublesome to overcome?
How bad does it hurt when kicked in the Bjarne's?
The linked G+ post says "August 20th, 2014 at 12:30pm EST to 2:30pm EST", but August 20th, 2014 is during Summer Time/Daylight Saving Time ...
So, is is 12:30pm EST, or 12:30pm EDT ??
"Are there any plans for future c++ specifications to focus on readability and debugging at the source level, as opposed to adding new features?"
As everyone well knows, maintenance and debugging are by far the most time intensive aspects of software engineering. Over the years, I and many of the others I work with have evolved various 'personal standards' in our use of C and C++; these personal standards are almost entirely to aid in debugging and readability. A few examples from the C side:
- pretend that the return type of the = operator is void, disallowing both "a=b=c" and "if (a = b)" constructs
- all 'if', 'while', 'for' etc statements must be braced
- certain types of simple arithmetic operations, for example a signed 16 bit integer multiplied by an unsigned 16 bit integer, may only be handled by dedicated macros to ensure proper operation. These macros must be manually tested and verified on each platform the software is ported to.
Many of these things seem trivial, but they add up. I have seen many hours lost to unbraced 'if' statements; I have seen five different compilers require five different sets of casts to ensure that a 16x16->32 bit integer multiply produces the correct results. There are many holes in the language specification which allow compilers to silently generate arbitrary code, requiring extensive debug and testing time when porting to new platforms.
Both porting and maintenance would be eased by truly looking at the lower layers and making some difficult decisions to improve parsing and deprecate dangerous or confusing constructs. Are there plans in future specifications to do this?
Alter Aeon Multiclass MUD - http://www.alteraeon.com
Hello! I december 2013[1] Herb Sutter has written about adding a graphics library to C++. As far as I know Cairo is a well written und usable library and in fact my complete desktop is using it (GNOME/GTK+ on GNU/Linux). But I shy away from the idea to see a graphics library within the standard, because drawing graphics is not part of the base requirements like Input/Output, String-Handling or Containers. What do you think about that? Is Cairo, as an low-level graphics library, also agnostic enough for the long-term future of C++? In my eyes Java only suffered from the integration of AWT/Swing as toolkit into the JRE. But AWT/Swing is a high-level toolkit and merely based on the paradigma of "runs anywhere". Thank you [1] http://lists.cairographics.org...
Apart from work, do you have any personal programming projects going on? Which type of programming do you like most and is there a particular project that you would like to implement?
What features do you think are missing that would make the language utterly incomprehensible, as opposed to almost completely incomprehensible, such as it is already?
In C++ how would you write the most elegant solution that prints numbers from 1 to 100, replacing any number divisible by three with the word "fizz", and any number divisible by five with the word "buzz"?
Is there any syntax in C++ that you would want to change, or remove, if you didn't have to worry about compatibility with previous version?
According to you, what is the worst thing that could happen to the C++ development, i.e. what nightmare would you never like to see happen to an upcoming standard?
There are 2 types of people in the world - those who understand decimal and those who don't.
C was/is a unique language.
It brought us portability and performance in a language suitable from low level system stuff to apps.
C++ manages to keep these traits and add objects, an impressive feat.
This may even be a unique feat.
Given it's compatibility with C, C++ may be the only game in town for systems programming in objects?
But this does not come without loosing a great deal of the simplicity of C.
I think the situation is that C++ is a bit like gasoline. It's powerful and can be used for good or bad.
With C++, it seems to require quite a bit of discipline to stay in the good camp.
For C, I think it is possible for many folks to be familiar with most of the features in the language.
For C++ I continue to find new stuff. Some neat, some only things only a mother could love.
Having seen how the transition from C to C++ proceeded,
given the chance to drive it again, what would you do differently?
Is C++ really the only game in town for doing large, high performance systems programming in objects?
How bad does it hurt when kicked in the Bjarne's?
#include
#include
#include
class Cpu {
public:
virtual int dummy( int, int ) {}
private:
virtual int add_( int a, int b ) { return a + b; } /* A */
virtual int sub_( int a, int b ) { return a - b; } /* B */
virtual int mul_( int a, int b ) { return a * b; } /* C */
virtual int div_( int a, int b ) { return a / b; } /* D */
virtual int mod_( int a, int b ) { return a % b; } /* E */
virtual int and_( int a, int b ) { return a & b; } /* F */
virtual int or_( int a, int b ) { return a | b; } /* G */
virtual int xor_( int a, int b ) { return a ^ b; } /* H */
};
int main( int argc, char* argv[] ) {
typedef int (Cpu::*Memfun)( int, int );
union {
Memfun fn;
unsigned char ptr[6];
} u;
Cpu cpu;
u.fn = &Cpu::dummy;
assert( argc == 4 );
int p1 = atoi( argv[ 1 ] );
int p2 = atoi( argv[ 3 ] );
char op = argv[2][0];
assert( op >= 'A' && op = 'H' );
u.ptr[0] = 1 + 4 * ( op - 'A' + 1 ); // Don't look here!
std::cout "The answer is " ( (cpu.*(u.fn))( p1, p2 ) ) std::endl;
}
A GC works on pointers/references, and works seamlessly together with RIAA, constructors/destructors.
Assuming you meant RAII and not the record industry, popular GC environments don't even guarantee that an object's destructor or finalizer will ever get called. So in a fully GC environment, without using the dispose pattern, how can you ensure that the non-memory resource that an object owns will get released?
How do you feel about Rust, Go and D?
I always thought the whole template logic was more complex than it had to be.
I seem to always want a simple way to enumerate what fields are on some class at compile time..... Without a PhD level template mess of meta-programming and unreadable code.
It's simply amazing to me that this more basic use case was never really formalized. I'm not asking for runtime reflection or even full reflection at compile time.
I also wish there was a more basic "find-replace" type of template. Where I can have it change strings and such inside quotes for static compile-time messages. (For instance for error messages about parsing where I want the field name in the error). Currently I have to make a class or pair to store the "name" of the variable which then complicates all uses of that variable. Usually my desire is again to just write a compile-time template that automatically builds a parser/serializer by looking at a class.
Rarely am I going beyond those use cases when I decide to template something. It's almost always for a parser, protocol layer, or a "framework" that I wish to simply change a few variables around and reuse my code.
Otherwise I feel C++11 was a step in the right direction and with standard thread support, my clients are not nearly as frightened by it. However the linux folks with glibc decided to "partially" implement std::regex such that it kinda-works but breaks if I try a non-capture group or an optional character class. That led me to totally distrust C++11 Regex since I cannot detect whether it's partial or not until the regexes fail to compile at runtime.
How would you plan to fix those issues when it comes to people poorly implementing the standard library extension to C++11 without the language itself having a way to check the "compliance level"?
I'd like a way to #IFDEF around some variable that tells me if I have full std::regex support, partial(crappy) support, or none at all so I can fallback to . That's currently a pain point of mine which I understand is the toolchain's upstream issue and not yours. (But they will derail you if you let them, so let's find a way to check compliance in the future)
Hi Mr. Stroustrup,
I love C++ and really liked what C++11 brought. I now see that there is C++14, then 17. What has led to this sudden change in pace at which the language standard is being updated?
Also, what are your thoughts on moving the standard library towards something pythoneseque where the language comes 'batteris included'. This is really the one thing that sometimes keeps me from thinking of using C++ sometimes.
Again, many thanks for bringing C++ forward.
It is exceedingly difficult to track freestore usage with the new operator. You cannot easily or generally associate counters with it with macros or functions.
Dear Prof. Stroustrup,
Writing templated C++ code has become one of my favorite way to write abstract algorithms in an efficient (runtime wise) way mostly because it not alone allows to know types at compile time, but also some values. Yet programming templates is nightmare because the template system is compile-time duck-typed. How can that system be made better? Concepts were proposed for integration in the C++ norm but got pulled back. Yet it seems they are essentially what is required. Will template programming ever improve?
Best,
My main criticism of C++ is that it's overly verbose. There are many issues resulting from it (difficult to write, overuse of old school pointers, etc). Let's take the simple for loop (I'm using { in place of "less than" since /. code is retarded):
int myVec[100];
for (int i=0; i { 100; i++) myVec[i]=i;
std::vector{int} myVec(100);
for (std::vector{ int }::const_iterator i=myVec.begin(); i != myVec.end(); i++)
{ myVec[i]=i; }
With C++11, it's slightly better:
...but it's amazing that C style (1970's) syntax is both the more concise and readable -- but still loses to C:
for (auto i=myVec.begin(); i != myVec.end(); i++) myVec[i]=i;
for (int i=0; i { myVec.size(); i++) myVec[i]=i;
Aside from the addition of auto, do you ever plan on admitting and addressing the language's problems with verbosity -- which hurts readability, learning curve, etc. -- or just keep introducing increasingly arcane features?
-- Political fascism requires a Fuhrer.
In addition to being the creator of C++, Bjarne Stroustrup is a Managing Director in the technology division of Morgan Stanley
So first he screwed us with that god-awful bastardization of C, then screwed us again with convoluted derivatives that no one could figure out were worthless, ushering in the worst global economic recession since World War II.
Pitchforks and torches are too good for this guy, I say. String him up on the yard arm.
"Somebody has to do something. It's just incredibly pathetic it has to be us."
--- Jerry Garcia
What modern programming language that is not C++ you recommend to learn as first?
Concepts in some form or another have been one of the major promised features for a while now and have the potential to be transformative. Based on the papers, you appear to be one of the major driving forces behing them. It must be exceptionally hard to design a major new feature of a major language without being able to standardise something already out there and in use.
There have been a few experiemental implementations of concepts (first) and then concepts lite. Have you made use of these much? In other words have you done any real programming with concepts and started to gain experience of what concepts are going to feel like in practice? And the important thing following on from that is are you liking what you're seeing?
Also, as a related point, are we likely to see these in C++17? I still look forward to being able to do:
sort(some_vector_of_some_struct);
and having it either work or tell me that operator is missing for that struct.
SJW n. One who posts facts.
How long do you think C++ will continue to be actively developed and changed? When will there just be too much crufty backwards compatibility to warrant improving the language? Do you think we're close to pretty much all the language features we're going to need, so further standards will be almost exclusively library changes?
"When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
If your last name were to be made into a C library string function, what would it do?
I'm Baba Wawa and this............ is Twenty Twenty.
(-1: Post disagrees with my already-settled worldview) is not a valid mod option.
I'm not a C++ programmer. But I have come across situations where people seemed to deliberately use weird, obfuscating stuff just so nobody else could take their place, (I particularly remember a company where somebody had convinced management to use UUCP instead of FTP for internal data xfers because it was more secure. When I was being interviewed on the phone they asked me what I thought of UUCP, and I think I was one of the few people they interviewed who had even heard of it.)
So, if C++ is as complicated and full of stuff as I keep reading about, I can see how somebody might deliberately cultivate for themselves a set of esoteric off the wall constructions that they'd throw in their code just so nobody else could work with it, all the time selling management on how 'good' it was.
In theory, theory and practice are the same; in practice they're different. (Yogi Berra & A. Einstein)
Signed integer overflow is undefined. That is, in C++, overflowing a signed integer is considered to be equally bad as dividing by zero. Combined with modern compilers, this is resulting in exploitable security bugs in many programs.
Programmers have been taught for decades about two's-complement integer arithmetic and how it overflows. As a result, many of us who don't know about signed integer overflowing being undefined are making "mistakes" like assuming that it wraps as we were taught.
The reason that C++ considers signed integer overflow to be undefined is because of non-two's-complement machines. Such machines pretty much don't exist anymore. Why does C++ insist upon keeping such requirements around, when it is wreaking security havoc on everyone else?
"Screw Sun, cross-platform will never work. Let's move on and steal the Java language." - Visual J++ Product Manager
C++98 is almost a superset of C89. C99 brought many incompatible changes to C, some of which were reconciled by C++11, but some of which weren't (restrict, VLAs, designated initializers, etc.). To a certain degree, this is understandable and unavoidable (although personally I've decided to stop using C++-incompatible features in C). Worse, in my opinion, are the new features that were added to both C and C++, but in a source-level incompatible way. I'm talking about thing like multithreading and complex numbers.
Without using either an external library or ugly preprocessor hackery, I can't write a program using multithreading or complex numbers that's valid as both C++ and C. Do you think these incompatibilities can be reduced? It's probably too late to do any thing about complex numbers (and C++ got them before C anyway), but is it reasonable for me to expect a future C++ standard containing a cthreads/threads.h header that duplicates C11's thread.h header in a completely compatible manner? Or am I simply being forced to make a choice between C++ and C?
1) You said on multiple occasions that backwards compatibility is an important feature of C++. That feature comes at a cost, however (e.g. in language size and complexity). Do you think that at some point the cost of backward compatibility will outweigh the benefits? To put this in a context - several recent languages try to go into the system programming domain (D, Rust, Go). All quote dissatisfaction with C++ as (one of) the primary motivations (primary reasons being language complexity, poor support for parallelism, and long compile times). Can we hope the committee will be more aggressive in obsoleting old/broken features?
2) When will size_t be replaced by a signed type?
3) Your take on increased throughput of the committee and planed standardisation of many new libraries (graphics, asio, fs, etc.)
You speak alot about code rejuvenation and bringing old code to new standards. As you are working on C++14, many compilers do not fully support C++11 yet. In the past, it was even worse. Don't you think that this lack of feature support from compilers is a major problem and the biggest obstacle to code rejuvenation?
The auto keyword in C++11 makes writing code a hair faster but makes maintaining code much harder. It was seen as a great feature so programmers don't have to write out long and messy template class declarations, but I feel that it makes code maintenance a nightmare. Instead of knowing exactly what is being returned, the code that abuses "auto" makes the maintainer have to track down the function signature and then find the return type. Coupled with less than perfect (and much worse compared to C# and Java) IDE support for source code, it kills productivity. What is your view on the auto keyword?
I like many things about C++ and would like to use them. Unfortunately I'm seeing many new library features being implemented in such a way that I can't get around the use of exceptions. An example if C++11's new threading libraries. For reasons that are beyond the scope of this question, I will not use exceptions in my code. This means I can't use C++11 multithreading and have to keep using the less portable (on paper, anyway) pthreads. Why aren't the interests of those who want to use C++ without exceptions being taken into account more specifically?
By approximation, how many lines of code have you written in C++?
And what were the types of software you worked on?
If Pandora's box is destined to be opened, *I* want to be the one to open it.
You, and the committee, are reluctant to add keywords. Thats why the sematics of keywords like "delete" are overloaded and theres no "lambda" keyword. Presumably this is to avoid breaking compatiblity with c++03 code, but gcc, clang, and many others need -std=c++11 to enable c++11 anyway. Any thoughts?
And seriously, can we just deprecate or remove trigraphs? I expect people who still use them also use gcc 2.95 or VS6.
Many programmers (including me) are flat out annoyed by the need to maintain header files (they are useful for documentation purposes only, but there are automated tools for extracting this type of information). Also, there seems to be no technical necessity to use header files (other than helping compiler/linker implementors).
Why are header files still (a non-optional) part of the standard?
If Pandora's box is destined to be opened, *I* want to be the one to open it.
Personally I find it often easier to write code that uses template meta-programming, than to read it.
Do you share this opinion, and don't you think this is exactly contrary to how it should be?
If Pandora's box is destined to be opened, *I* want to be the one to open it.
In a multi-stage compilation process, libraries could generate readable C++ code based on (type-)requirements of a user-program.
This could be an alternative to template (meta)-programming, which would (I suppose) result in much easier to read programs and possibly better understandable error messages.
Have you considered such a compilation model? And if so, why do you consider templates to be a better choice?
If Pandora's box is destined to be opened, *I* want to be the one to open it.
I've been using the pimpl pattern lately, and enjoy the benefits of separating the API from the implementation.
The main down side is the extra overhead of writing the separate public and private classes, and forwarding the public implementation calls to the private implementation.
What are your thoughts on making pimpl part of C++ as a new class type?
The Web Standards Project published three compliance tests called Acid1, Acid2 and Acid3 to measure the compliance of a specific browser.
Is it possible/desirable to give access to free-to-use C++ sources to measure the compliance of a specific C++ compiler?
(It could be, for example, published on isocpp.org)
c++11 added attributes which is kind of what you want, I think. Except there are only 3 standard ones and compiler-specific ones are namespaced.
Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
There are a ton of unused characters on a standard keyboard that could be useful and/or fun to use as part of core language feature additions or more operator overloaders. Is there a reason that we don't use them?
As a C++ developer, C++11/14 brings me a lot of features that, indeed, makes C++ feels like a new language (my pet feature is the move semantics).
A few years ago (2007), you proposed open multi-methods (http://www.stroustrup.com/multimethods.pdf)
What are the reasons (technical, or otherwise) open multi-methods are not part of the current C++ standard, or even proposed for the next iteration?
I was always curious, why did you choose Simula as inspiration for OO design? Many, including Alan Kay himself, are believing this is wrong approach for original object oriented design in languages, which are followed by Java, C# and many more. Why didn't you used Smalltalk or even CLOS as basis for more dynamic and introspective system (Common Lisp compilers are proving CLOS dynamism doesn't have to be barrier for creating fast and optimized code) and do you think Objective C did the right thing?
What I meant to ask in my OP was:
"Why doesn't C++ have language support for allocation and deallocation of variables on the heap. C++ manages the lifetimes of stack variables, why not heap variables?"
You've said, "There are only two kinds of languages: the ones people complain about and the ones nobody uses." Why does this tend to happen?
It's sad to see so many "questions" on here like from the person who hates C++'s lambda syntax but didn't even bother to suggest a syntax or a language that they do like for comparison..I don't see how anyone can easily answer such non questions or should have to without a basic starting point.They are less than lazy. I understand it even less why these people don't get on the C++ Standard website and make their suggestions there so their ideas can be standardized and they could learn something.
I think more can be done to encourage people like the lambda poster to participate on the C++ Standard website forums in a positive way and I think there is a lot more to get excited about C++ in the future like Concepts, Multi-methods, type safe switch, etc. and maybe even a new STL down the line.
Do you see the ISO Standard C++ website being extended further with more tools and communications options to make collecting ideas on those proposals easier so the feedback can be more organised and do you intend to talk about these specific features I mention soon on here or that site and not just Concepts, to continue stirring up interest?
Thanks for C++! It's been an enduring success.
What do you think about Andrei Alexandrescu's Loki library, with the idea of many template parameters allowing users to customize common utility classes?
Screw ancient architectures and minor compiler optimizations. I'd rather have my binary math work like all of us were taught in discrete math classes. Not to mention not have my machine pwned by the mob because a programmer didn't realize that their security check was removed for being undefined behavior.
"Screw Sun, cross-platform will never work. Let's move on and steal the Java language." - Visual J++ Product Manager
I'm writing a new security library in c++11 as an esperiment, and I choose to avoid exceptions and rtti. There are stories that you have done similar choices with some of your projects, for example to be able to use some proof of correctness.
Do you have any recommendations on a specific set of features for my (or other) use cases?
Well, considering that you said "numbers" and not integers and that any number is divisible by 3 or 5, the output of such a program would be a never ending repeat of "buzz" or "fizz" or "buzzfizz". Since you did not specify whether "buzz" or "fizz" takes precedence, all three choices are valid. Here is a sample of your program's output: ...buzzfizzbuzzfizzbuzzfizz...
Do you think Rust is a good replacement for C++?
Are there any features of the language that you wish hadn't been added or could now be removed?
All those moments will be lost in time, like tears in rain.
If you had to design a new programming language from scratch today, unencumbered by backwards compatibility, what would it look like?
Any comments about the fact that the template metaprogramming is Turing Complete?
Pass by const reference.
(Btw, std::strings may have their warts, but at least they TRACK THE FUCKING LENGTH OF THE STRING correctly. Not so for C "strings".)
Where do you see the programming sector move both geographic-wise and usefulness
Why won't we get new operators like *>, >=> or &&& ? Haskell allows defining an infinite number of arbitrary operators, which is very useful.
C++ is has turned 30 and you're one of the most recognised names in computing. What does your fuzzy, scratched and cloudy crystal ball tell you about C++43 and what computing will look like then?
SJW n. One who posts facts.
If we have begin, end and cbegin, cend, why don't we have cauto? Please don't say you do not want to break legacy code. That argument appears to be the killer of all innovation.
Bjarne: There really is a question at the end of this, but it takes some setting up. Please bear with me.
In the late '80s I came to Silicon Valley for a startup, which was using C++ for a major project. I learned the language then and got over the "doing it the object-oriented way" hump. In the process I analyzed what cfront was producing and got a good understanding of what was under the hood (at the time).
The project was very ambitious. Much of it was creating a data base engine for a complicated indexing mechanism. The result was that transactions occurred by creating a transient structure. The bulk of the work occurred during its construction, and errors during this stage had to be unwound carefully.
In those days C++ didn't have exception handling - "catch" and "throw" were reserved words, to be defined later. (So I built a set of exception handling classes that unwound even errors thrown from deep in construction and destruction correctly.)
Some of the architectural types had come to OOP via Xerox PARC and Smalltalk, and didn't want to be "slowed down" by getting "manual" memory management right. So we built a set of classes (incluing "smartpointers") and a preprocessor (to automatically generate pointer-identifying virtual functions) and got garbage collection working just fine. (We did a similar thing for remote procedure calls, and so on. We may still hold the record for layers of preprocessing between source and object...)
C++ WOULD have been the ideal language for it. But we found a little hole in the spec that caused BIG problems. The language got it SO ALMOST right that it was painful.
Consider construction of a subclass with virtual functions. Suppose the base class exports a pointer to itself (say, putting it into an external list). Then suppose that, at some time during the execution of the constructor of a member object of the derived class (or other initialization of the derived class), something gets hold of that pointer and calls a virtual function of the base class that is overridden by the derived class. Does it get the base class or derived class version of the function?
IMHO it should get the BASE class version during the initialization of the derived class UP TO the execution of the first user-written statement of the constructor, and the derived class version once the constructor's guts are executing. Getting the derived version before the constructor proper is entered means attempting to use functionality that has not been initialized. (Before the constructor is enetered you're still initializing the component parts. During the constructorf you initialize the assembly, and the author can manage the issue.) Similarly, during destruction it should get the derived version through the last user written line of the destructor, the base class version after that (as first the object-type members, then the base class(es), are destroyed).
Examples of how this would work in real problems:
- Object represents a an object in a displayed image. The base class is a generic displayable object, which hooks the object into a display list. It has a do-nothing "DrawMe()" virtual function. The derived class adds the behavior. When the display finishes a frame the list is run, calling the "DrawMe()" methods of all the objects. If one is still under construction and the derived class overriding is clalled, uninitialized memory is accessed (including pointers containing stack junk).
- Object is heap-allocated. Virtual functions are the "mark()" or "sweep()" pointer enumerator for the garbage collector. Base classs is the generic "I'm a heap allocated object" substrate, hooking into an "allocated objects" list with do-nothing virtual functions. At each level of object derivation the new version of the function enumerates, for the mark and sweep phases, the member variables that are pointers (and calls the base class version to also enumerate the pointers at the more baseward layers. The pointers' own initialization
Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
When will c++ lose external exceptions and stack so that all events and state are programmable. E.g. mail home a stack dump on a null pointer. Lisp/SNOBOL/,,, can do this.
Why the static initialization order problem was not addressed in recent reforms of the language ?
It does not seem very hard to fix. Although I am aware of the workarounds I do not like them. In my opinion we need to fix what is broken before adding more features. Thank you for your attention, Mauricio Gomes.
"Think globally, act locally".
When I code in C++ I really miss things like algebraic data types, pattern matching, and type classes.
boost::variant exists, but requires too much syntax.
The lack of type class like functionality is also pretty irritating, emulating this in C++ requires far too much boilerplate--
Could you get the committee to step on it with adding features? The pace seems glacial:(
An initializer list is supposed to provide parameters for a function call. At least in VC++, I can use it as brace initialization instead of parentheses; for example, given a function that takes an integer and a pointer to const char, I can initialize it as either F(1, "two") or F{1, "two"}. There is no requirement for a function to take any sort of homogenous types as parameters.
However, a std::initializer_list, which is also values between braces, and is intended to provide parameters to a function, is a template of type T. Since I know of no T that would represent both an int and a const char *, I don't see how std::initializer_list could be used for the above parameters.
Is there any plan to make std::initializer_list more versatile, so it can actually do what it was apparently intended to do? How likely are we to get more of these "almost works" features in further standards?
"When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
You bought a cowboy hat when you tried to teach C++ at Texas A&M University. What did you do with the hat after they fired you ?
What is the ideal size of an Object?
Casteism
There is no way to specify a format for size_t in C that will work in all official standards. "%z" wasn't introduced until C99
C99 is a decade and a half old. It's time to pull a new compiler from your publisher's repository:
Though the official inclusion of its types in C++ is only three years old, dating to C++11, compilers have provided the C99 types as an extension to C++ for as long as they've implemented C99.
In your interview with Emyr Williams for CVu magazine you mention that, with hindsight, you "would not have chosen the C declarator syntax or two-way conversions between fundamental types, but to fix those, you would need to take the time machine a few years further back for a chat with Dennis."
Including the two issues mentioned, what are the design decisions/mistakes made in C which you had to carry forward to C++ due to the decision to remain largely compatible with C?
Why did you think adding the "friend" keyword to C++ was a good idea?
Do you still think it is good?