Bjarne Stroustrups and More Problems With Programming
Phoe6 writes "As a follow up to the first part of his interview, Technology Review Magazine has another article running titled 'More Trouble with Programming'. Bjarne Stroustrup shares his point of view on good software, bad software design and aspect oriented programming." From the article: "Technology Review: Name the coolest and lamest programs ever written in C++, and say what worked and didn't work. Bjarne Stroustrup: Google! Can you even remember the world before Google? (It was only five years ago, after all.) What I like about Google is its performance under severe resource constraints. It possesses some really neat parallel and distributed algorithms. Also, the first Web browsers. Can you imagine the world without the Web? (It was only about 10 years ago.) Other programs that I find cool are examples of embedded-systems code: the scene-analysis and autonomous driving systems of the Mars Rovers, a fuel-injection control for a huge marine engine. There is also some really cool code in Photoshop's image processing and user interfaces."
It is,
int main()
{
cout "Hello World" eol;
return 0;
}
Very cool at first, then it just goes down from there.
Please... he's one of the most influential people in the field of computer science today, at least spell his name right.
My understanding was that much of Google was in python.
Why try to imagine it, can't we just remember it?
I do not believe that a paradigm completely replaces previous paradigms in one revolutionary moment (or "shift"). Instead, each programming paradigm adds to what worked previously
I think that line explains a thing or two about C++..
He then goes on to say that Java and C# go on to further this, and I don't believe that. Java (and my C# experience is limited, but I believe it applies to C# as well), does not augment C/C++. In fact wasn't it originally called C++-? Java did shift the paradigm, and as a java developer, I am thankful.
WorldWideWeb, being on a NeXT box, was written in Objective-C, not C++.
FTFA: I hope you didn't put too much money on it! I don't see aspect-oriented programming escaping the "academic ghetto" any day soon, and if it does, it will be less pervasive than OO. When it works, aspect-oriented programming is elegant, but it's not clear how many applications significantly benefit from its use.
Totally agreed. AOP is a strange form of "dynamic" insertion of code at special "cut points" of execution within the code and represent a very very lazy way to avoid good OOP structure of your applications.
In a bigger framework AOP can be totally unpredictable and wreck otherwise locked and working code.
When AOP started to pick some speed in the beginning I was naturally both interested and slightly annoyed that so short after OOP here's yet another concept for programming I have to learn and implement in my software.
Not so fast though, since as much as OOP provides useful abstractions that makes your code more readable and predictable, AOP does exactly the opposite except in few very limited cases.
The cons outweigh the pros.
Why yes, I remember the world before Google. We had AltaVista. Their ads? Teh suck. Their search? If we're talking before they left DIGITAL Corp, as good as Google's. Google's an *ad* company, people, not a geek company.
Javac is the coolest program written in C++ :-)
Some drink at the fountain of knowledge. Others just gargle.
Where in "Plain Old Text" you have to escape < as <
Claiming Google as a cool C++ program is about 1/3 true. Most Google code is written in C++, Java, and Python: C++ for performance-critical stuff, Python for scripting, and Java for everything in between. The trend is definitely toward Java at the expense of the other two.
Also, for what it's worth, Google's use of Aspect-oriented programming is ramping up pretty fast.
Can you find the bug in this C++ program?
---- begin bugdemo.h ----
template<class T> void doprint(T obj) { printf("The numbers are: %d %d\n",obj.num1,obj.num2);}
void foo(void);
void bar(void);
---- end bugdemo.h ----
---- begin bugdemo.cc ----
#include "bugdemo.h"
int main(int argc, char *argv[])
{
foo();
bar();
return 0;
}
---- end bugdemo.cc ----
---- begin foo.cc ----
#include <stdio.h>
#include "bugdemo.h"
struct A {
int num1,num2;
};
void foo(void)
{
A myobj;
myobj.num1=-5;
myobj.num2=6;
doprint(myobj);
}
---- end foo.cc ----
---- begin bar.cc----
#include <stdio.h>
#include "bugdemo.h"
struct A {
short num1,num2;
};
void bar(void)
{
A myobj;
myobj.num1=-5;
myobj.num2=6;
doprint(myobj);
}
---- end bar.cc ----
This program seems to be intended to generate:
The numbers are: -5 6
The numbers are: -5 6
But instead generates:
The numbers are: -5 -1
The numbers are: -5 6
or perhaps something different altogether.
The problem is portable across platforms and compilers (although the exact incorrect answers sometimes vary).
TR brought up aspected orientation, and BS brought concurrency (in line with current CPU design pattern) and generic programming. Concurrency will definitely be a biggie - it applies not only to multi-core CPUs, it already applies to distributed computing (cluster and all those related). Generic would need a lot more work. It has been in C++ (template, STL) for many years, but only the ninjas would cook up their own templates - most of use simply use library-supplied templates and don't f*ck it up. Same story with Java generics, the way it was added. C#'s generics seem easier to use.
.net) is the push AO needs to take root in practice/industry.
.net are based on runtime VM, and it has the advantage of access to the runtime profile information that static languages lack. I'm thinking addition to language that better expresses how the VM should optimize in execution of the program (maybe in conjunction with dynamic typing - i.e., runtime morphing of the code) can provide the next leap in programming productivity by pushing up the abstraction level. MDA promised the same result, but so far it seems to have failed to hit the sweetspot on the tradeoff between abstraction and control. And the super VM is not mutually exclusive with any of the ideas noted.
:-)
AO appears more of an extension to OO - helps to organize and manage the design workload. Much buzz, but no real uptake so far. Maybe a takeup by one of the big platforms (C++, Java,
My guess is growing importance of VM/runtime support. Both Java and
Ok, just an idea out ma ass. I know next to nothing on the topic of VM design.
"Severe resource constraints"? Since when a datacenter with half a million servers in it is called "resource constraints"?
OK, I really try not to be elitist/whatever but this one kind of bugs me. Google has been around, and part of (mostly) popular culture for more than 5 years. And I would imagine that a decent amount of people actually do remember the days before Google. Writing like that is just lazy.
:wq
Yes, yes, all fine and well that he's influenced by Kierkegaard and dislikes AOP, but ... COULD SOMEONE PLEASE ASK HIM TO EXPLAIN THE "CONST" keyword .... please ....
(A very good explination is given here for those of you who didn't know I was kidding)
For the perfect anti-Unix, write an OS that thinks it knows what you're doing better than you do and let it be wrong.
Um. Yeah. Er.
"WorldWideWeb was written in Objective-C."
How can any not read this interview with Stroustrup? http://www.nsbasic.com/ce/info/interview.shtml
Severe ranting ahead, you have been waned...
That's just the problem, a lot of companies don't come to professionals when they need something more complex or robust. They usually start off hiring a bunch of amateurs who have no firm grasp of professional software design because they are cheap to employ and let them loose without proper supervision. These people cobble together some system that works, it doesn't work very stably, but by and large it works if you constantly monitor it and as long as it the system is still relatively small. This system gets maintained for a while and added to. These additions are usually badly designed or even worse, quick fixes intended to patch up problems that could have been avoided if the system had been properly designed in the first place. As I said before, while the system is still relatively small the bad design does not matter so much but as the system's complexity, the load the system is subjected to and it's importance to the company grow the instability and constant hiccups due to bad design begin to become a liability. This is usually the point the company finally decides to call in the professionals who are then confronted with a system that badly needs a complete rewrite and an employer who expects the necessary rewrite to be done in a couple of weeks and on a shoestring budget. My experience is that a lot of the time (not to be read as: **always**, there are companies out there who proper design work) the professionals are called in to clean up messes created by people who learned to write code with only a few months training. Way to many of the jobs I get involve cleaning up problems created by people who committed basic errors such as duplicating code all over the place instead of building it into class libraries and who didn't seem to be aware of the existence of nifty utilities like 'javadoc'/'doxygen' and 'subversion' or even revolutionary concepts like 'multi-line code comments'. Not that I am complaining mind you; the clumsiness of these badly trained developers and the frugality of the managers who hire them keeps me, a professional university educated software developer, employed but it's still a frustrating way to make a living because a lot of the crap I have to deal with could have been so easily avoided.
Only to idiots, are orders laws.
-- Henning von Tresckow
I dont think he likes it thought or
http://www.research.att.com/~bs/bs_faq.html#impos
Yes, I remember clearly, I used some other search engine instead.
People need to stop acting like google invented the search engine.
It's a decent one, but only marginally better than the competition and if google search disappeared tomorrow it just wouldn't be a big deal.
Ooops. To avoid confusion for people trying to follow along with what I did, I should mention that I had changed my copy of the header to
template<class T> void doprint(const T& obj) { printf("The numbers are: %d %d\n",obj.num1,obj.num2);};
that's why I got void doprint<A>(A const&) instead of void doprint<A>(A).
C++ is an inherently and unnecessary complex language, if you want to use some C inheritor for OO programming resort to Objective-C: it is a much simpler and cleaner "enhancement" of C instead of C++ which tries to kill many flies with one stroke (multiparadigm language). ObjC is essentially C + Smalltalk, you can learn it within one day if you already know C, just compare the number of pages of http://www.amazon.com/C++-Programming-Language-Spe cial-3rd/dp/0201700735 vs http://www.amazon.com/Object-Oriented-Programming- Evolutionary-Brad-Cox/dp/0201548348 . it's like in real live: the worse approach wins (Windows vs. Linux and so on). Good tutorial here: http://objc.toodarkpark.net/ . And by the way: the OpenStep Libs are to die for!
He is talking about object orientation not being a paradigm shift, not a specific language. Object orientation as implemented in Java did not throw out all of the previous programming language concepts from C++, Simula, Smalltalk, Algol, etc. It built on them and picked and chose features from previous systems. Hence, no paradigm shift.
Can you imagine the world without the Web? (It was only about 10 years ago.)
/me cries.
The web was created by Al Gore in 1996?
My word ignorance has passed on even to our elders.
Just a quick look at AltaVista's about pages shows they *indexed* the web in 95. Of course, the Internet wasn't there before Google, so it must be bogus.
RFC 1580/FYI23 which was published in March 1994, contains a definition of the web.
In actuality, the World Wide Web came about in 1992 about 15 years ago.
Now, had Bjorn meant that slashdotters wouldn't remember before ten years ago because that's about how old most moderators are, i could understand, but he should have been more clear on the matter.
Have you read my journal today?
What is a language anyways but a context free grammar? The school I goto teaches Java as the primary language, but once you get into the junior, senior classes you branch out into C and C++ (they even teach Cobol, ewww, I know). Once you take on Automata and Computability, and learn about CFG's then the language isn't the problem. On the other hand, learning a paradigm (like OO vs Structural) can be a bitch.
It would be silly to fault someone for not having 20/20 foresight, so I can hardly blame BS for not including things that we know now to be good, but not necessarily then. One example would be pass by value, which at the time seemed like the safest default for parameter passing (the thinking was probably to avoid unintentional side effects). Extending this to objects though causes pains involving copy constructors and other esoteric stuff. Java decided on always pass by reference, and from my experience, unintentioned side effects almost never come up (the fact that the 'native objects' were immutable might have helped).
Yet to read these articles, it's almost like he still thinks that C++ is the top language, and anyone who's not using it is just a poorer programmer who can't handle the power. When I hear him reply with stuff about Java's success coming from 'massive corporate backing' it just sounds like tired whining. C++ did fill an important role, it introduced a lot of people to OO by piggy backing on a very popular language. It also allowed for OO programming on a lot slower hardware. But the cost was it wasn't much of an abstraction. I think it can be put to rest for the majority of projects. There's still some areas where it will shine for quite awhile (graphics maybe) but those are the minority.
I actually code in AOP everyday at work - and couldn't imagine life without it. Sure, it is a bit difficult, but then you start to understand and appreciate its beauty. It is perfect for my job, Hardware Verification.
The language I use is 'e'. Take a gander at http://www.ieee1647.org/ if you are interested.
Vividly... Searches for Hippopotamuses turned up porn. Searches for C++ turned up porn. Searches for Slashdot turned up porn...
Other than the porn, there were dozens upon dozens of pointless hits for sites that only in-passing included the search term you wanted, and perhaps not even that, as search engine databases were often years old, and sites completely changed in that time. What's more, there was never any spell-checker, so with a trivial mistake, you could be wasting all that time with the wrong term, and never find what you want.
Finding anything was laborious and extremely time consuming. Now with Google, almost ALL search engines have raised their standards near the Google level (alltheweb seems to be somewhat of an exception) and now only a tiny fraction of searches turn up page after page of pointless crap.
However, Google doesn't seem to be improving much these days, while there are obviously other ideas to be explored. On vague or expansive subjects (or just if you aren't particularly good at searching) Clusty tends to be a better bet, as it automatically categorizes your results for you, allowing you to trivially easily narrow them down... much moreso than if you just included additional categorizing terms in the search.
Yes... fondly. Links neatly grouped together in the same spot on every page, not in colors that blend in with the background, in tiny font sizes, or hidden in buggy, inconsistent javascript sub-sub-sub menus.
No god awful color schemes, or Flash-only sites. No sites that have huge columns on the left and right sides (with almost nothing useful in them) that squish the center column (content) down to one-word-per-line (I'm looking at you, Slashdot).
Never a single site that depended on your screen resolution (now all but 0.01% of websites are utterly unusable in 640x480 or below).
No cookies, no javascript, no background images, no BLINK element, no pop-up windows, etc. To make a site, you actually needed CONTENT, not overindulgent designers.
Slashdot gets worse every day... Pipedot: News for nerds, without the corporate slant
Yes, I think so too. In addition, I don't think, the Mars rovers certainly aren't programmed in C++ either... Would be pretty lame for the author of the language to claim credit like this...
In Soviet Washington the swamp drains you.
So you think it's worth arguing the toss about whether 1992 is "about 10 years ago", which means you're arguing about how vague the term "about" is, which means you seem to be missing all of the major points.
Go back much more than 10 years, and most people had next to nothing to do with the web; for most practical purposes "the Web" as we know it today (in practical terms) wasn't there.
But then you didn't manage to spell Bjarne's name correctly, so why would I expect you to make useful criticisms?
Bjarne Stroustrup is the problem with programming. C++ is probably the worst widely-used language design the industry has ever seen. And what makes it particularly insidious is that it seems useful and powerful, that is, people get started with it, like the raw power and performance they get, and often never figure out the profound problems the language has.
"It is impossible to develop a framework such as GStreamer in isolation as there are always usecases and trouble areas that get lost or design decisions who seem clever from the framework point of view but which is a complete fuck up from the application developers point of view. This is a big part of the reason why GStreamer have taken so long to get to where it is today."
http://blogs.gnome.org/view/uraeus/2006/12/08/0
Well the problem with C(++) is that it wasn't actually "designed", but just an ugly conglomeration of features which turned out to be easy to implement at the time of writing the compiler.
Just look at it. His standard book about C++ has 956 pages and even he himself tells the programmers to not use all those features.
The language itself is very chumbersome to use. Creating an object typically takes you a _lot_ of lines and concepts like copying objects create incredibly bloated code. (I have been writing commercial software for several years in Delphi and never had the desire to copy an object)
Some features are just halfway implemented. Look at operator overloading. It only works in some cases on some operators.
Of course, you can write efficient code in C(++), but it's hard. And most programmers don't work hard enough to actually write such code. That's why computers seem to not get faster since the mid 90s.
My point is, if you want to write in C(++) you need to learn how to do it. You need to learn what it does, even down close to the hardware. Then you can write in those languages. If you don't want to do that, then C(++) is not the language of your choice.
You might think twice about using C++ after reading this interview with Mr. Stroustrup.
I have quite a bit of experience with C++ and this example is just _one_ of a seemingly unending list of problems that bite the unwary C++ programmer. And without 10s of years of experience, there is _no way_ you can know about all of these. Some of my other 'favourites' are problems related to ordering of construction/destruction of static objects, virtual overrides becoming overloads without warning (try to change one of the arguments of a virtual function to be 'const' in the base class and what happens if you forget to do the same change to the override in some derived class?), all kinds of memory overwrite bugs caused by hanging on to pointers to memory that have been freed, being able to pass the address of an object on the stack out of a function (there is no excuse for this, the kind of program analysis done by optimising compilers could catch this easily -- the worst thing is the code often works at first but breaks much later when no-one has a clue where the bug is). And so on, and so forth...
Unfortunately the code I write is performance critical, so I have to put up with the nightmare that maintaining and extending a million line of code C++ project is...
The interactive way to Go -- http://www.playgo.to/iwtg/en/
... and now explain how using the 'const' keyword interacts with overloading functions and how it works with templates
class A { virtual void f(const A *pA); }
class B : public A { void f(A *pA); }
quick, which functions are the following calling?
A *p = new B(); p->F(p);
const A *p = new B(); p->F(p);
B *p = new B(); p->F(p);
const B *p = new B(); p->F(p);
And that's just overloads...
The interactive way to Go -- http://www.playgo.to/iwtg/en/
I think you're right, you have to know C or C++ intimately to be able to write correct code. C++ is a half-assed attempt to add modern features to C which results in an explosion in complexity. The thing is, C is not an easy language to program in because there is almost no protection against shooting yourself in the foot. Luckily C is pretty small and simple, and it is possible to understand the language well enough to be able to write a simple compiler after you've used it for a couple of years. Now C++ is pretty much impossible for one person to understand. Even the compiler writers find themselves struggling with the specification. If anyone still have doubts, have a look here http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_de fects.html for some eye-opening reading material...
The interactive way to Go -- http://www.playgo.to/iwtg/en/
Apart from the fact that the #includes are missing it's not C++. Shure (with the missing includes) it might compile. But it is not the way it is done in C++.
The C++ (as well as C99) standart define 0 to be the null pointer. With older C standards that was different and there where indeed some platforms with:
#define NULL ((void*)-1)
which means that
if (s && s[0] != '\0')
won't work. But that' all over now - it's the null pointer is 0 now. on the other hand C++2008 is likely to get an extra null pointer keyword.
But it does show the greatest problem of C++ programming: Most C++ programmers don't actualy know how C++ works. And just because MS used NULL it does not mean it is current standart.
Martin
For those of you that say you have to learn all these all these algorithms and correct way of doing things what would you do when you have to program a quantum computer where none of what you learned before seems to apply? People do quick and dirty programming in todays world but don't just casually dismiss people's ingenuity to come up with crwative solutions.
I would not consider C++ as a Grandparent to Java, C# or .Net.
This role would belong to Objective-C and OpenStep (OpenStep also has been licensed by Sun before coming along with Java).
WebObjects was the first (Web) Application Server (1995 I believe) long before Sun had anything in this area.
He's the idiot who invented C++ when C, LISP and Smalltalk were doing just fine. Not to mention Erlang.
Moderation was obviously by C++ programmers who are feeling insecure about their skills. Good going, guys.
Without turning on my compiler, I would say that this is ambigious(And really really bad DESIGN even if allowed. But you can shoot your self in any language)
:}
Do I really have to find gcc to test it
AOP is not a hack, is just one indirection level ahead of usual programming, I like to think about this kind of concepts as something that has full sense somewhere between the system and the programs.
It's not about what a program must do, it's about what should be done when a program do something.
What's in a sig?
Even some of the cited examples did not come from academia:
t heory#Historical_background
g _language
Shannon's information theory Bell labs. One can check wikipedia http://en.wikipedia.org/wiki/Shannon_information_
Smalltalk XERO PARC. http://en.wikipedia.org/wiki/Smalltalk_programmin
The atomic bomb started as pure research. The early investigations into the physics of the atom was pure research, however, the manhatton project was not.
The answer to this is not to hire unwary C++ programmers, but rather competent professionals. C++ is not a language for newbies or cash-grabbing McProgrammers, and I rather doubt Bjarne or anyone else on the standards committees has ever claimed it was.
A professional would immediately tell you that you should not rely on the order of construction or destruction for statics, that the derived class implementation will hide the base class one in your const modification case (precisely to prevent the kind of problem you described, actually), that you should rarely need to use simple pointers in C++ code so your released memory problem shouldn't be a problem in practice, that pretty much any recent compiler will warn if you try to return a reference to a local variable, etc.
Most of this stuff is in the better introductory books, the main FAQ, and countless "how not to shoot yourself in the foot" guides. Anyone who hasn't come across them doesn't know their subject well enough to be using it for real. If you want to hire people in that category, sure, give them Java or something, where the balance between safety and expressive power/performance is different. Just don't expect the kind of results you could have had by paying for professionals to do the job with more powerful tools.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
Nice trick question.
For one thing, C++ is case-sensitive, so your p->F(/*whatever*/) calls have nothing to do with the f members of your classes.
For another, class visibility defaults to private, so you can't call any of your member functions via a pointer (other than from within the same class).
Next up, and this is perhaps where you think there is a difficulty, there are no overloads or overrides in your example at all. The function f in class B hides the function of the same name in class A because of the different parameter types. Any call through an A* can only see A::f. Any call through a B* can only see B::f.
So, assuming we change the function identifiers to be consistent and that you're calling from somewhere with access to private members, the compiler has only one possible call to consider in each of your example cases. If const correctness permits, it will use it. Otherwise, the code will fail to compile.
That means the answers are:
First case: calls A::f
Second case: fails to compile (can't call a non-const method on a const pointer) or would call A::f if this were made a const member function
Third case: calls B::f
Fourth case: fails to compile (same as second case), and would still fail to compile even if the member functions were made const, as it can only see B::f and that requires a non-const A* parameter.
Really, if you understand a few basic rules, this sort of thing is all pretty obvious. Not good design, of course, but obvious all the same.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
Advanced Compiler Design and Implementation by Steven Muchnick is a good book in my opinion. Did you try that?
The interactive way to Go -- http://www.playgo.to/iwtg/en/
Lets rely on programmers to know everything and be perfect, rather than having languages that don't suck. Programmers should never be making mistakes anyways, and its easy to always remember the hundreds of C++ problems that will bite you when coding at 3 am in crunch time. Who needs to concentrate on the problem at hand anyways, much better to use your precious memory on remembering how to avoid getting bitten by a hostile language.
When evaluating a computer language people often concentrate on generated code quality. Very few languages can rival C++ in this area. But what is often neglected is code build times. The code generated by C++ templates is pretty amazing - huge chunks of C++ code can sometimes be reduced into a few machine opcodes, but few people have the hundreds of hours per year to spare waiting for their compilers to actually build the code. I like the power and expressiveness of C++, but javac build times puts C++ to shame. Even if you rebuild your entire project from scratch in Java it is still 10 times faster than an incremental build in C++. God forbid you change a key C++ header file or something drastic. Knowing that C++ compile times are so horrendously slow, people often keep lousy base classes in place and puts hacks in derived classes that should not be there. Yes, pointer forward declarations help. Yes, Distcc and ccache are also helpful. But these techniques and tools do not address the basic shortcomings of the static C++ build process. If your build cycle is fast you can get more work done, plain and simple.
C++ could greatly benefit from ONE standard object file and bytecode format for all OSes and CPUs. Yes, I'm a heritic. The linker or loader should be responsible for translating the standard object file format to the host's native machine code. Bjarne's biggest failure in C++ was giving too much flexibility in C++ compiler implementations. This aided early adoption of C++, but this flexibility has led to needless incompatibility - even with compilers on the same architecture and OS. LLVM's bytecode format is as good a candidate for such a universal intermediate format as any (and probably better than most). Just having a standard C++ ABI is not good enough to carry C++ forward. C++ needs a proper architecturally neutral distrobution format and a standard set of libraries. With such a format in place C++ developers might mirror the 3rd party library support success that Java and its ubiquitous .jar files currently enjoy.
.jar file for X - almost never download the actual code.
/*NOTREACHED*/
When someone writes code in java here is the process:
1. Google for feature X.
2. Grab
3. write 2 lines of code in Java to call the function in question.
4. done.
When someone tries to do the same in C++, here is the process:
1. Google for feature X and C++.
2. Find something written in 1997 on some C++ compiler/platform that is different than your own.
3. download the code and see if it is compatible with your own C++ code and its myriad of compiler flags and libraries on your system.
4. try to compile it - this step usually ends in failure.
5. even if it does compile when you go to run the code it will invariably crash due to some invalid type size assumptions in the library code.
6. hack the 3rd party library source to get it to work, but you realize that it does not do what you want it to do.
7. go to step 2.
8.
25 years ago Stroustrup wasn't wrong, I would like to see you run a modern java enviroment on a 64k machine (no, the embedded java systems that remove most of the language don't count).
C++ was never aimed at "64k machines". The kinds of machines people started using C++ on had several megabytes of memory at least--machines perfectly capable of running other high level languages of the day. C++ use on PCs didn't become common until they reached that size and performance; prior to that, it was used mostly for research applications on UNIX workstations.
Also, C++ 20 years ago (which is when it was released) was not the same language as it is today. 20 years ago, C++ was a small, backwards compatible extension of C, implemented as a preprocessor. As such, it made sense as a temporary improvement for C until people could move to something else. Today, C++ is a different language--a bloated monster.
Performace did matter back then, for example the much toted java garbage collection system would take up 100% of a 8mhz 286's cycles just figuring out what could be released.
That's not how GC costs work; GC isn't some big, fixed overhead that you can only afford once you have a fast machine. Rather, GC costs a certain number of cycles per byte allocated. That means that the impact on a normal program running 10 sec on an 8 MHz machine is the same as on a normal program running 10 sec on an 8 GHz machine.
Furthermore, then, as now, a good garbage collector reduces the total amount of CPU spend on memory management compared to C++'s manual storage management scheme; C++ memory management is highly inefficient.
As for Java, Java's implementation of garbage collection, reflection, and other features are lousy, so you can't use Java as a yardstick. Nevertheless, C++ programs like OpenOffice and Firefox are slow and very resource intensive; evidently, using C++ as the underlying language doesn't work magic.
Stroustrup was wrong 25 years ago, and he should have known better. I was there, I know.
is a monster of a language, and stroustrups knows it, but sometimes it takes an ugly monster of a language to get a job done.
Nothing will ever replace c++, except another language like c++ that provides all of its low level power. That said, I'd like to see a few outstanding issues in c++ fixed.
1. compile times. headers should be discarded, and a single implementation file approach used by java and c# adopted.
2. templates should be cleaned up a little bit. c# style generics are generally preferable (although runtime instantiation is probably impossible for a compiled language.)
3. 1st class lambda's and bindings would be nice. the stuff provided through boost is pretty awkward right now...
It would be nice if there was a language that was to c++ as c# is to java, a language that fits the same niche, but doesn't have to be compatible so that core language issues can be learned form and cleaned up. To some extent D fills this void, but I'm waiting for a more fleshed out toolchain (IDE, 3rd party libs and bindings, etc) to become available for it before I mess with it for anything more than for fun projects.
As for using memcpy: how actually are you going to memcpy a 0 or NULL? They both don't have an address to copy from.
Maybe you meant memset. But memset won't work for NULL either. Look at the prototype:
void *memset(void *s, int c, size_t n);
The bad news is: int might not be large enough to hold a pointer (It's defined in 6.3.2.3 as well) and indded is not for x86_64. One is supposed to use intptr_t or uintptr_t.
Martin
Yes, you need exceptions from the type system - but they should be exceptions and not default behavior.
Martin
A "common" GC allocator divides memory into two regions. Allocation is done from one region, by simply returning the current end of memory, and advancing. If the allocation would no longer fit, a GC pass is made, copying all live memory to the second region.
Allocation is now a constant time operation EXCEPT for the GC, and "free" is zero time.
This can be modified to tenure blocks of memory -- if a block lives over "n" copies, it is pulled from the normal allocation, thus increasing the efficiency of the copies. (Which is the "nubbin" idea behind most generational techniques).
There is no heap structure implemented at all.
Ratboy
Just another "Cubible(sic) Joe" 2 17 3061
dynamic_cast makes a runtime check to see if the source pointer is compatible with the destination pointer. As such it is the savest cast available.
It would have been easy to extend the idea of a runtime check to create a save cast for primitive data types (int, long, char). Then one would have got the matra "dynamic_cast is save" which would have been easy to teach to C++ beginners.
But sadly the C++ standart comete where so pointer centric.
Shure you can create templates for save numeric casts (the boost library got one, I programmed one myself). But they are all missing the matra value and - more importanly - are not mentioned in "Teach yourself C++ in 21 days".
Martin