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.
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.
http://en.wikipedia.org/wiki/One_Definition_Rule
"Severe resource constraints"? Since when a datacenter with half a million servers in it is called "resource constraints"?
Can you explain where the problem is ?
Bonjour !
The problem is that two different translation units define two different versions of struct A.
... in a program provided that each definition appears in a different translation unit, and ... each definition of [the name defined more than once] shall consist of the same sequence of tokens ..."
Relevant parts from Section 3.2 of the cpp standard:
"There can be more than one definition of a class type
In the example provided, two translation units have definitions for struct A. However, they are not identical; in particular, one has members that are ints, the other, shorts.
However:
"If the definitions of the [name defined more than once] do not satisfy these requirements, then the behavior is undefined."
In other words, the compiler is not required to diagnose violations of the ODR (One Definition Rule).
In this particular example, the compiler compiled bar as if doprint had a four-byte argument* (two shorts) but then threw out one of the definitions of doprint, leaving the other to treat shorts as if they were ints.
*or maybe an eight-byte argument with misc padding that wasn't cleared
The compiler generates different but identically names instances of doprint() in each of the two modules (notice the difference in the definition of struct A). The linker then arbitrarily picks an instance and throws out the other.
The net result is that one of the calls to doprint() ends up using a template instantiation for an incompatible datatype and prints out the wrong things.
With GNU ld, the linker's selection of the instance is determined by the order of parameters on the command line, so you can get different behaviors by switching the parameters around.
I spent a week tracking this down during my dissertation work. It was buried in a 4000 line (not including libraries) numerical analysis code. The offending template definition was buried in a macro expansion defined in an external library.
Needless to say, I've avoided C++ since then. Too many gotchas and subtle behaviors, weirdnesses with virtual methods, etc. Not to mention the const/non-const combinatorial explosion and the other hassles resulting from strong typing.
These days I usually end up using C, Matlab/Octave, or Python depending on the problem. The new Numpy is very very good for numeric computation.
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.
You don't need to write doprint because the type can be deduced from the argument to doprint.
(This can be further demonstrated by the fact that making your change doesn't fix the problem.)
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
By the way, ld (the link editor) has has an option called --allow-multiple-definition whose documentation says: This tells me that it is a bug in the linker (or at least the linker's documentation).
Note that ld also has an option called --warn-common whose documentation says: This option does not warn about the issue in question, so I consider that a linker bug as well.
p.s. The best policy is to disallow header files to define nonstatic symbols. This is fairly difficult to enforce programmatically, but you can at least catch multiple definitions and reject them before linking if you do something along the lines of: nm -ogC --defined-only *.o | cut -d: -f2 | sort | uniq -dc. In this case, you'll get 2 00000000 W void doprint<A>(A const&), which indicates that there are two weak symbols with the name void doprint<A>(A const&), so your custom build process can halt with an error.
p.p.s. The fix for the case in question is to change its definition to be template<class T> static void doprint(T obj) { printf("The numbers are: %d %d\n",obj.num1,obj.num2);}
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.
"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 the three Smalltalk books describing it are even more pages than the C++ book, so obviously ObjC is inferior to both? What a stupid way to compare programming languages.
ObjC is a language which has a core with a static type system, which is somewhat weak because of the ease of casts and on top of that a language with a dynamic type system. So basically you have the worst of two worlds. It is neither as efficient as C/C++ nor as elegant as Smalltalk. And yes, C++ is multiparadigm, structured if you basically use the C core, object-oriented when you use the class system and generic when you program with templates. ObjC is also multiparadigm, structured and object-oriented, but dynamic typing doesn't need generics, so it has no concept for it.
And sorry, but the learning speed of a language is not determined by the number of symbols. Without the supporting libs you can't do anything in either and I doubt you learnt the OpenStep libs in a day. The same is true of C++ and expecially Smalltalk. That language is so small that its syntax graph fits on two pages of the first Smalltalk book. So by your reasoning you should use Smalltalk, why don't you?
Please understand me right. I don't like ObjC as you obviously don't like C++. I have my reasons and you yours. But I really, really dislike the claim of ObjC being "basically C + Smalltalk" because that is simply not true. And I have programmed in all four languages, C, Smalltalk, ObjC and C++, although the least amount in ObjC because I heard the claim "it is like Smalltalk" (which I already knew at the time before trying ObjC) and was very disappointed, no, it is not like Smalltalk. Interestingly I never heard someone claim it who also knows Smalltalk.
... 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.
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
Power is the problem.
The most powerful flow control construct is if/then goto. It's more power than you need.
Likewise C++ has more features than anybody needs, although most of the features may be needed by somebody some of the time.
This is not a criticism of Stourstrup; C++ simply implements what everyone thought was necessary in a high performance OO language twenty five years ago. Since the paradigm was not in widespread use, it's no surprising that the design is different from what we'd come up with today.
Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
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?
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.
This is not a criticism of Stourstrup; C++ simply implements what everyone thought was necessary in a high performance OO language twenty five years ago.
Sorry, no, that's false. People knew pretty much as much about OOP and high performance language implementations back then as they do today: dynamic compilation, dynamic optimization, generational garbage collection, incremental compilation, runtime class updating, method dispatch optimization, etc.
Since the paradigm was not in widespread use, it's no surprising that the design is different from what we'd come up with today.
We haven't "come up" with anything "today". What happened is that people like Stroustrup incorrectly postulated 25 years ago that efficiency was more important than good design and designed languages without what they naively considered "inefficient" constructs. We have been spending the last 25 years putting these features back in again. Today, Java and C# are almost where OOLs were before C++, except that Java and C# are far more bloated and less consistent.
Stroustrup was simply wrong, and he could have known better if he had done his homework.
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). 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.
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.
Well, let's see what I missed:
- No unary and binary selectors, so no way to define a new numerical type like complex
- No way to influence the type coercion on numerical types, so you can't define a new complex type where e.g. double automatically converts itself to a complex when necessary (yes, Smalltalk can do that)
- Static typing clutter allowed in selectors (and already used by the base runtime, so can't be evaded). Something like test: (int) aVal is just plain ugly and breaks dynamic semantics.
- No block contexts, so no way to create new control structures like do:
- Native types not part of the dynamic system, so if you want the full power you have to define your own integer type, which is even slower as Smalltalks
Somehow I don't see the "is basically like smalltalk" if most of the really cool core features of Smalltalk are missing. Also one of the best aids in Smalltalk development is the environment which won't compile code if there is no selector with the signature you tried to use and could show you all classes implementing a certain selector. And the debugger allowing to stop, change the code and resume operation. Compared to that the compile cycle of ObjC is that of a static language without the abilities to catch the same problems a statically typed language can catch.Hmm, Simula's class model has single inheritance, no data hiding (public, protected, private) and no overloading. C++ has multiple inheritance, virtual inheritance (the same base class appearing multiple times is only included once in the data layout), data hiding with the three keywords plus a way to break it (friend) and overloading. Also Simula had no operators, no constructor or destructor. To me ObjC's class model is exactly that of Simula. The only thing they differ in is that Simula uses Algol function syntax and ObjC Smalltalk selector syntax. So I really don't see that the class model differs. The object model of all three is basically the same: an opaque reference to an object (ref in ObjC, pointer and reference in C++, forgot what it was called in Simula (haven't used it in the last 15 years) and in Smalltalk it has no name as the references are the only type of the system) you can send messages/call functions on which does polymorphic dispatch. In the dynamically typed languages basically looking if a matching selector exists in the target, in the statically typed languages statically designated by the inheritance relationship. So for me they differ the most in the method dispatch and that is exactly to be expected.
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