Stroustrup Says C++ Education Needs To Improve
simoniker writes "Over at Dr. Dobb's, C++ creator Bjarne Stroustrup has given an in-depth interview dealing with, among other things, the upcoming C++0x programming standard, as well as his views on the past and future of C++. He comments in particular on some of the difficulties in educating people on C++: 'In the early days of C++, I worried a lot about "not being able to teach teachers fast enough." I had reason to worry because much of the obvious poor use of C++ can be traced to fundamental misunderstandings among educators. I obviously failed to articulate my ideals and principles sufficiently.' Stroustrup also notes, 'Given that the problems are not restricted to C++, I'm not alone in that. As far as I can see, every large programming community suffers, so the problem is one of scale.' We've discussed Stroustrup's views on C++ in the past."
I completely agree with Stroustrup. Too many people these days have little or no exposure to C++, and never learn how programming in the absence of garbage collection works. It is especially problematic in our research labs, where computationally complex problems must be solved with very fast code, but the people writing it get completely confused by pointers and memory management. Worse is when a proof-of-concept is distributed, with horrible bugs and completely incomprehensible code.
Palm trees and 8
...is that C++ is a rather complex and brittle language. :-) ..bruce..
P.S. Feel free to flame away at me, but not only have I developed professionally in C++, I've actually rescued a C++ project by (among other things) drafting C++ coding standards and guidelines for the 30 or so developers working on it.
Bruce F. Webster (brucefwebster.com)
It's way too complex to be managable, resulting in unmaintainable (No IDE can fully go through all typedefs; and if you ever stepped through a program and went into every godam -> operator of boost, you're on my side), unreadable and unneccesary code ("Better declare a private but not implemented copy constructor just to be sure"). It tried to implement all possible paradigmas at once, while trying to be backward compatible at the same time. It's the worst language ever.
C++ isn't going anywhere. Nearly all serious desktop software outside of Mac-land is written in it because the alternatives (Java? C#?) suck rocks. Large amounts of high performance code is written in C++. I don't know where you got the idea that people who care about performance use C from, that's flat wrong in my experience. I agree that D is a very nice language. It will make great strides in the next five yeras. However, maturity counts for a lot.
Yes, that subset is called C.
Seriously, at this point it is time to call a halt to C++ education. Treat it like COBOL, Fortran or any other legacy language that still has demand for programmers but is long since past utility. It is a good idea for students to understand that they have to keep current with programming languages and not expect to be employed as a programmer if they can only code in one. But that does not mean we should start by teaching an obsolete language.
You don't need to tech kids to write in C++ for them to learn how bad an idea lack of GC is. Just give them some existing code and tell them to chase buffer overruns and memory leaks.
I would not code in any language that does not have a garbage collection feature, period. When I coded C in the 90s I wrote my own garbage collector using macros and some extensions to the memory allocation routines. More importantly I would not allow anyone else to write code without GC because none of them were capable of doing it right.
Second, do not use the null terminated string handling. This was one of the key coding requirements that Tim Berners-Lee set out in libwww. All string catenation was checked. It is one of the reasons libwww was so widely used, it was buffer-overun error proof.
I would certainly specify C for use in a low level O/S platform project, but not C++. I think the language is Algol 68 to Algol 60, worse than the original.
Above that point I would use either C#, Java or objective C. From an education point of view they are interchangeable.
C# is at least as fast as equivalent C++ code. The code generator used is identical. You can switch in your own GC if you choose.
Looking for an Information Security student project suggestion?
Try http://dotcrimeManifesto.com/
I will grant you that if you or the parents are shelling out the Purdue tuition, maybe their CS department should find a better professor for their intro course. I am sorry to hear that this experience dissuaded you from completing a CS degree, and there is probably a lot more to your personal story than can be shared on Slashdot.
But I would like to communicate to others out there that you will have a few good teachers in your educational career who are really inspiring, a vast group of average teachers, and a number of who you consider to be really, really bad teachers. The "bad" teachers are that way (in your opinion) for a number of reasons -- they may be "nice guys or gals" who don't have enough preparation or smarts to teach, they may have admitted to you gaps in their preparation that you have taken upon yourself to hold them in disrespect for, or maybe they assign too much HW and work you too hard.
If one is going to take a passive approach, show up to class and demand, "Here, educate me", that is a good way to fail at getting a degree and also to fail at every other opportunity that presents itself down the road. If one is going to take an active approach, working as hard as one can at learning from all teachers, the good and the bad, supplementing gaps in instruction with self-study, working coding jobs, group study, one is going to be successful at college and everything else.
To suggest that a person can have one "bad" prof means that they are on the street drinking methyl antifreeze out of a jar wrapped in a paper bag, this suggests a very passive approach to not just education but life in all its aspects.
I'm full of errors today. I wasn't thinking of the primitives (double,int,char etc). I should have said something like 'first-time programmers have to use objects whereas C++ you can get away with keeping a procedural-oriented mindset. Therefore, you can limit what is introduced. Is that better? ;)
Lack of planning on your part does not constitute an emergency on mine.
There, fixed that for you.
"My favorite lecturer quote, "Oh, I don't really do any coding at all"." That's not a big deal. Computer Science is not about coding in particular, but understanding the practices to design and implement solutions to a problem. Computer Science is more about applied math then writing in language X. I learned some of the most important concepts in a class that was all done in pseudocode. Understanding how to approach a problem and solve it efficiently is more important then learning a language. In fact, once you know how most things are working, with a few basic concepts such as pointers or how a computer interpret an instruction listing, you should be able to pick up almost any language fairly easily. If you are not capable of learning things on your own without being handheld through a set of power point lectures, even if you knew C++ instead of Java you aren't going to be worthwhile in the real world anyways. You are destined to be a code monkey.
I agree. C++ served its purpose in the language world. It was a great FIRST STEP toward object oriented programming, but it has outlived its usefulness. Stroustrup should take pride in his great contribution, and not be discouraged because C++ has been superseded by other, better languages. C++ provided a bridge from the world of no objects in C, to the world of objects. But now that there are languages that are designed with objects in mind from the ground up, it's only academically interesting (and of little practical value) to learn C++ except to support (or port) legacy applications.
The "restrict yourself" stuff is stupid. It's like saying "tie one hand behind your back while programming". Can you think of *any* other profession where professionals are advised not to use their best tools?
The correct advice would be, "use precisely what you need and no more".
I have been programming in C++ for a very long time, and I have needed *every single tool* that some of you nay-sayers would say was unnecessary. And that's needed in the sense of "the best solution was achieved using these tools", not "I padded my CV by adding unnecesary complexity".
For quick prototyping, use Python or Ruby. Or even Perl, if you really can't help yourself.
Yes, the lack of top-level functions in Java is well-known criticism (at least from the Python/Ruby crowd), but personally I've never had any problems with that, mostly because I don't use Java for quick scripts. The constant need to cast everything is a much bigger problem, IMO.
Did I mention using the right tool for the job? Use perl for this example.
You guys are weird. Someone gave incorrect, convoluted code (in C++) for doing something, and you criticize C++ for this???
Err, are you saying that you *have* to use an IDE to generate a class to run a Java app? The equivalent of your C++ main would be:
public class Test {
// ...
public static void main(String[] args) {
}
}
Why do you need an IDE to write that?
Wow, how were you modded "Troll"? I'd mod you up if I could.
Yeah, array/pointer ambiguity is a key "broken" feature of C++, although at the same time it's exactly the kind of thing that makes it possible to use the same language for code running on a microcontroller and for a full-blown GUI. But yes, for most things it would be incredibly useful to have proper arrays with index checking and so on. Most templated solutions that I've seen (Boost?) are just butt-ugly and make the code that much more difficult to understand.
I think anyone that's used C++ a lot (this is probably a truism for all things) develops a strong love/hate feeling towards it. So it goes.
That example is complete bogus. Sure you can write some horrible code in C++, but I write C++ code for a living, and it's at least as clean as any Java or C#. You just need to use the right libraries. Qt provides a class library at least as good as those shipped with C# and Java, and you don't get any of the disadvantages of a virtual machine, with most of the advantages.
Isn't the whole idea of a Computer Science education to learn the underlying concepts of programming, not just the syntax or semantics of a particular language? The programming language used is merely a vehicle for conveying those concepts. The professor who was "learning [J++] with you as we go" was referring to the specifics of the new programming language, not the concepts that he was going to teach in the course. Presumably (unless he was unfit for his position), he knew those concepts well and was able to convey them to the class using whatever syntax and semantics were thrown in front of him.
The quote I'll never forget came from one of my professors during an advising session: "I'll often get calls from IT managers asking if we have any graduating students who know COBOL. I always tell them that ANY of our graduates could know COBOL - and ask if they are hiring someone for their intellect and understanding of programming concepts, or for their knowledge of a particular language."
I think the main problem of C++ is that people who know C assume they automatically know C++ as well. They don't. You might want to read up on this std::vector thing.
It's hemorrhage (US spelling) or haemorrhage (UK spelling) BTW.
echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
"Oh, I don't really do any coding at all"." That's not a big deal.
That is BS
It is ok for, I dunno, a discrete math prof., or maybe an algorythms professor not to code. It is NOT OK for a C++/JAVA/etc teacher NOT TO code.
It is ok if a cellular biology professor is not a practicing MD. It is NOT OK for a surgery professor to not know how to open people up and not to work with that (with the rare exception of 'I can't operate anymore with a bionic hand' kind of stuff).
how long until
You can still use the === operator, or the kind_of? method. And I'm fairly certain metaprogramming is supported.
I've just found that static type checking is about all that's missing, and it isn't incredibly useful, especially when you're doing unit tests.
I'd assumed they did? After all, Ruby is from Japan...
It is nice that it really only uses ASCII for the language itself, though. I should add that to my list.
I'm feeling a bit lost in this jargon... Can you give me some specific examples?
When these are done for me, via things like Eclipse plugins, I don't worry too much about how complex they are under the hood, so long as they work.
For what, though?
The existing constants are difficult enough to override without at least a warning, and I think that's really all you need. The same could be said of the private/protected methods -- there is a bit of a mess with the usage of 'send', but in a language which truly supports reflection and metaprogramming, private/protected is effectively only a warning anyway, as there's always a way around it.
Ruby is at least as strong as C++, I'd think, due to how easy lambdas are. This seems to be about DSLs again, right?
The syntax for calling functions, and for passing them blocks, is simple and clean enough that it almost feels like defining your own language directives. Yet it's all still valid Ruby, which means it's usually readable by anyone who understands Ruby, and it's easy to mix and match.
In other words, LISP.
I'd argue that the sanest way to do this is to just make the typing implicit.
Which still means that you have to put everything (somehow) into the type system, in order for the template to match, if I understand it. It also means that you have that extra template syntax in order to give you something that I think should be on by default.
Why don't you like that requirement?
In the simplest case, I suppose you can define such a function explicitly:
But I suspect that's not what you want. I suspect you're talking about bind variables, which Ruby can do. (Even JavaScript can do those.)
That is, you want something like:
And this can be
Don't thank God, thank a doctor!
On an already ugly programming language, or at least one which is at best obsolescent from a technology perspective.
Having 25+ years of experience in the field my opinion is C++ is aweful. No amount of hacking around the edges of it is ever going to fix that. Due to the very nature of the language defect rates are exceedingly high. Even with modern development, test, and debugging tools building software in C++ is an endeavor which requires an inordinate amount of expertise, mostly in how to avoid doing most of the things the language allows you to do because 99% of them are bad ideas. Instead of learning to program well, most instruction in C++ has to be focused on how to work around its hodgepodge of misfeatures. Personally I wouldn't even consider allowing anyone with less than 5+ years of experience touch a commercial C++ application.
The whole stankin' mess should be retired. The sooner the better.
"Malo periculosam, libertatem quam quietam servitutem." -- Jefferson
Where are they teaching it actively again? I'm a student on computer science at the moment and all they teach in any depth is Java. The only reason I know c++ is my desire to learn it, despite the fact that various parts of my course have recently required a fairly in depth knowledge of c++.
As background, I have worked with Java, C, and C++. I've also dealt with functional languages (Lisp, Haskell), scripting languages (perl, php, python), and a bunch of other stuff. In all my experiences, my response to C++ is pfft, I can live without it. If I want to get into the guts of the operating system, muck with the kernel, or do something nasty by hand in memory, I'll use C, if I want to write an application I'll use Java. C++ is a terrible language for application development, it combines all the worst aspects of OOP with all the worst aspects of C style memory handling, but brings no advantage to the table!
I'm tired of all this chest beating of wanabe's complaining oh they teach me java, but I am such an uber geek I want to learn C++! Computer Science education doesn't teach you to program in JAVA, it teaches you computer science, in the course of that you learn to program, not to program in X, but to program. Any computer scientist worth their salt can program just as easily in one language as another, and can pick up any other language just as easily.
The only big mental shifts come between procedural languages vs oop languages vs functional languages, etc. Everything else is syntactic sugar. Choose the language which best fits the problem at hand.
Hello Mr. n00b, you can fulfill agile requirements in any programming language. And, no, "shipping code in a hurry", as you put it, is not agile, absolutely not. It's more the Dilbert version of agile development.
A monkey is doing the real work for me.
And anyone who is saying 'learn to use the leak detection tool', testing programs for correctness is a total lose. You can never test every state of anything but the simplest programs. A good GC will guarantee that there are no memory leaks without needing to test. Better code safety and better performance as well, memory leaks are the most common cause of performance problems that I see.
Looking for an Information Security student project suggestion?
Try http://dotcrimeManifesto.com/
Why the hell should they? Is knowing the title of a C book that's out of date (OK, the second edition is better, but K&R usually refers to the original edition) important?
Perhaps you don't understand what CS is. CS isn't about C - in fact, it's not even about programming at all. CS is about the theory of computation. Things like programming language theory and computational complexity theory are subsets of CS.
CS doesn't include coding practices, use of source control, project/time management, or software testing. All of that is part of software engineering.
The problem is that people expect CS programs to produce functional software engineers. And while functional software engineers certainly need a strong grasp of theoretical concepts (such as a basic computational complexity theory and common algorithms), what they really need is software and systems engineering experience.