Slashdot Mirror


Bjarne Stroustrup On Concepts, C++0x

An anonymous reader writes "Danny Kalev has an interview with Bjarne Stroustrup about the failure of concepts, the technical issues of concepts, whether the ISO committee's days are over, and whether C++ is at a dead-end. 'I don't think that concepts were doomed to fail. Also, I don't think concepts were trying to fix many things or to transform C++ into an almost new language. They were introduced to do one thing: provide direct language support to the by-far dominant use of templates: generic programming. They were intended to allow direct expression of what people already state in comments, in design documents, and in documentation. Every well-designed template is written with a notion of what is required from its arguments. For good code, those requirements are documented (think of the standard's requirements tables). That is, today most templates are designed using an informal notion of concepts.'"

346 comments

  1. Really Unfortunate Initials by eldavojohn · · Score: 4, Funny
    I enjoyed the interview but I felt the initials of the participants were really unfortunate. DK and BS? I kept reading the whole thing as:

    Donkey Kong: The specification of concepts has taken seven years. By contrast, the standardization of the entire STL took about half that time. What is so complicated about concepts?

    Bull Shit! I count the concepts work as started in 2002! I presented my first design papers in 2003! In 1994 Alex Stepanov presented a complete implementation of the STL to Andrew Koenig and me, but 2002-to-2009 and 1994-to-1998 are not comparable time lines! Alex had been working on the STL from at least 1976! ... etc.

    What's really unfortunate is that he's one of the very few language maintainers out there that isn't of the mentality "Rah rah! My language/tool/design-philosophy/whatever is the solution to all your problems and will take over the world tomorrow." (phrase lifted from the interview) Wish we had more people like you out there, Stroustrup. Also, if this isn't fixed by now, I'm sorry Slashdot couldn't even get your name right in the title to this story.

    --
    My work here is dung.
    1. Re:Really Unfortunate Initials by Desler · · Score: 5, Insightful

      What's really unfortunate is that he's one of the very few language maintainers out there that isn't of the mentality "Rah rah! My language/tool/design-philosophy/whatever is the solution to all your problems and will take over the world tomorrow."

      Care to actually provide the names of those other language maintainers, with appropriate citations, that make such claims?

    2. Re:Really Unfortunate Initials by rumith · · Score: 2, Funny

      Assume that DK stands for Dungeon Keeper, and the tone of the interview suddenly becomes much more sinister... :)

    3. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 2, Funny

      You've never seen a Python coder, have you?

    4. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 1, Insightful

      WAIT A MINUTE THERE BUDDY!! Python is the best language ever! It will solve all your problems and take over the world tommorrow!!!

      How dare you say ... oh ... wait, you were saying Python is that language.

      Yeah, python is cool, isn't it?

    5. Re:Really Unfortunate Initials by Desler · · Score: 3, Insightful

      You've never seen a Python coder, have you?

      He said language maintainer, not language user. Care to quote the Python language maintainer(s) making such a claim?

    6. Re:Really Unfortunate Initials by eldavojohn · · Score: 1, Insightful

      What's really unfortunate is that he's one of the very few language maintainers out there that isn't of the mentality "Rah rah! My language/tool/design-philosophy/whatever is the solution to all your problems and will take over the world tomorrow."

      Care to actually provide the names of those other language maintainers, with appropriate citations, that make such claims?

      Very well. They don't out and out say that exact phrase but I'm sick of languages being marketed to me like an automobile. Here are a few after a bit of Googling. I don't really have time to dig more up:

      Larry Wall of Perl: "Perl is designed to give you several ways to do anything, so consider picking the most readable one. " - From the Perl Man Pages

      Yukihiro Matsumoto of Ruby: "Why should you switch to Ruby? If you are happy with Perl or Python, you don't have to. But if you do feel there must be a better language, Ruby may be your language of choice." and then "I believe people want to express themselves when they program. They don't want to fight with the language. Programming languages must feel natural to programmers." From an interview. It's hard not to roll my eyes when I hear about the latest flavor of the month. Ruby's marketed as 'the most natural.'

      From Sun's about Java page they claim, "Write powerful and efficient applications for mobile phones, remote processors, low-cost consumer products, and practically any other device with a digital heartbeat." As one of their reasons developers choose Java.

      I'm surprised you aren't sick of languages being marketed to you as silver bullets that can solve all your problems. That's really all I see these days. No more are people considering a multitude of languages to be a toolbox you use to solve all kinds of problems but instead you see languages like Java being marketed for inappropriate things. It's like the inventor of C#, Anders Hejlsberg said, "The dream is to have a single programming model." I just don't believe that's a realistic dream.

      If I were in their shoes, I would explicitly say what the language is but also explicitly say what it is not. As someone who's tried to do video analysis in Java, I've been down the "should not" path and wasted my time.

      --
      My work here is dung.
    7. Re:Really Unfortunate Initials by shutdown+-p+now · · Score: 4, Informative

      Care to actually provide the names of those other language maintainers, with appropriate citations, that make such claims?

      Few people remember this days, but Java was positioned that way back in late 1990s. I cannot find any reference because I don't remember the exact words, but I recall Scott McNealy saying something along the lines of "Now that you have Java, why would you write in anything else"?

      Bertrand Meyer and his Eiffel programming language is another example. He isn't really stating directly that it's the best thing since sliced bread, but virtually all his papers on the matter read like aggressive advertisements, praising the virtues of Eiffel, and sniding other languages because they don't "see the light" in form of design-by-contract and command-query separation (conveniently ignoring the major flaws of Eiffel such as universal generic type covariance). He also edited Wikipedia article on Eiffel to match that, got extremely offended when other people have tweaked the article to remove self-promotion, and tried to "revoke" his GFDL'd contributions (read from here on, and check the article history, for the full story of that drama).

    8. Re:Really Unfortunate Initials by Desler · · Score: 5, Insightful

      What are those people supposed to say about their language? That it sucks? That user's shouldn't use it? None of those quotes imply anything that you are claiming. Those are just snippets telling people what the positives of using their languages is. In the case of Ruby the maintainer even says that if you are happy with Perl or Python that you shouldn't switch to Ruby. That's hardly a claim of "my language is the solution to all your problems and it's going to take over the world".

    9. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 0

      What are those people supposed to say about their language?

      Read the last sentence of his post. You also quoted the Ruby quote out of context. The following sentence says it all what he is thinking. It's actually pretty snobby.

    10. Re:Really Unfortunate Initials by tepples · · Score: 1, Offtopic

      Donkey Kong [...] Bull Shit

      Bertrand Meyer and his Eiffel programming language is another example.

      Let me guess: Bowel Movement?

    11. Re:Really Unfortunate Initials by halivar · · Score: 1

      I play too much WOW. I read "Blacksmither" and "Death Knight".

    12. Re:Really Unfortunate Initials by GooberToo · · Score: 1

      Larry Wall of Perl: "Perl is designed to give you several ways to do anything, so consider picking the most readable one. " - From the Perl Man Pages

      Isn't that statement a backhanded way for Larry to tell people to use just about any language other than Perl?

    13. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 2, Insightful

      Wow. Calling out Matz of all language maintainers as one with a "rah rah" mentality really shows that you have no clue at all what you are talking about. I've read most of his posts on the Ruby mailing list throughout the past 9 years and I don't think you could find a worse example. At least pick someone like David Heinemeier Hansson -- the creator of Ruby on Rails and one of the most annoying self-marketers I've encountered in software development.

    14. Re:Really Unfortunate Initials by osu-neko · · Score: 1

      I play too much WOW. I read "Blacksmither" and "Death Knight".

      Everybody who plays WoW plays too much WoW. (Now if you'll excuse me, I need to go earn another 2400g to buy new mounts for all my toons that now qualify thanks to patch 3.2...)

      --
      "Convictions are more dangerous enemies of truth than lies."
    15. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 3, Insightful

      Larry Wall of Perl: "Perl is designed to give you several ways to do anything, so consider picking the most readable one. " - From the Perl Man Pages

      Wait, wait, wait. You're seriously citing THAT as an example of (quoting from the GGP)

      "Rah rah! My language/tool/design-philosophy/whatever is the solution to all your problems and will take over the world tomorrow."

      ?

      The other examples are actually quite similar; Ruby says, in essence, "we think Ruby is good", and Java says, in essence, "Java is good". Nothing wrong with that - certainly it's not saying anything about other languages. In fact, in Ruby's case, it's explicitely said that if other languages work for you, then by all means continue using them.

      But Perl? You're even crazier there. Larry isn't even saying "Perl is good"; in fact, his quote could just as well have come from someone who does NOT like Perl but still wants to give some useful advice (advice that, one might add, is applicable to just about EVERY programming language).

      If that's your idea of "rah rah take over the world!", then you must be from Bizarro World - you're not even wrong.

    16. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 0

      I think that the simplest language to write AND maintain while still providing acceptable performance is the one to use.

    17. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 0

      He also edited Wikipedia article on Eiffel to match that, got extremely offended when other people have tweaked the article to remove self-promotion, and tried to "revoke" his GFDL'd contributions (read from here on, and check the article history, for the full story of that drama).

      Ehm, I read your link and he seems the biggest deal was him using blue font for syntax highlighting on code snippets and some idiot editors going too far (some guy called Ideogram in particular). This is a rather insightful comment from that page:

      I am shocked also: Jimbo's user page states: [4]

      Greater involvement by scientists would lead to a "multiplier effect", says Wales. Most entries are edited by enthusiasts, and the addition of a researcher can boost article quality hugely. "Experts can help write specifics in a nuanced way,"

      But, when one comes along and adds quality verifiable content he is made to feel heckled and is finally dismissed with "Goodbye and good riddance" because Wikipedians feel that all coding snippets must not be blue?

      Hasn't anyone read Ignore_all_rules: "If the rules prevent you from improving or maintaining Wikipedia's quality, ignore them." - It's part of the Wikipedia Trifecta: [5] (along with NPOV and Don't be a dick).

      So, the Editors here have violated 2 of the Wikipedia Policy Trifecta (ignore preventative rules, and don't be a dick) and have alienated a good faith, quality, knowledgeable contributer because they prefer non-blue text. Dr. Meyer may have also made the same violations, but he is a newbie. The long-time editors and admins should definitely know better and should be ashamed of their behavior. 144.189.5.201 00:10, 29 August 2006 (UTC)

      Note that I did not know who Meyer is before looking at your link.

    18. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 1, Interesting

      Having had some exposure to Eiffel, I can safely say that Eiffel's generic implementation is intuitive and consistent. Constrained genericity was something that I was first introduced in Eiffel and it seemed to be quite natural for OO design. The simplicity of multiple inheritance and repeated inheritance makes efficient code reuse possible in Eiffel. With these contributions, I can tolerate some marketing messages from the creator. The downside being, it converts almost every eiffel programmer to an evangelist :-(, including yours truly.

    19. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 1, Informative

      It's like the inventor of C#, Anders Hejlsberg said, "The dream is to have a single programming model." I just don't believe that's a realistic dream.

      Try not to confuse programming language with programming model. The vast majority of programming nowadays follows the imperative model, but such programming is done in a variety of programming languages (C, C++, Java, Perl, Python). Furthermore, many programming languages borrow ideas from multiple programming models (e.g., C++).

    20. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 2, Interesting

      What about this quote from Guido van Rossum?

    21. Re:Really Unfortunate Initials by shutdown+-p+now · · Score: 2, Interesting

      Check out the history of the actual article. The comments should be read in context of that.

      By the way, the "blue font" issue might need clarification as well - it's not that he tried to use blue just for the keywords, it's that he used blue as the base text color for all code snippets, including inline ones (as it's mandated by the "Eiffel methodology"). This just looked ugly, and caused confusion with hyperlinks, which is why most other editors of the article have supported not using blue text for code snippets. Meyer ignored that as well, insisted that Eiffel is an "all or nothing" thing, and therefore any Eiffel code should follow his conventions; and kept reverting any attempts to remove the blue highlighting.

    22. Re:Really Unfortunate Initials by Tetsujin · · Score: 1

      Larry Wall of Perl: "Perl is designed to give you several ways to do anything, so consider picking the most readable one. " - From the Perl Man Pages

      Isn't that statement a backhanded way for Larry to tell people to use just about any language other than Perl?

      No, it's more like an excuse for Perl's reputed illegibility. He's saying, basically, "it's possible to write legible code in Perl because Perl gives you a lot of ways to do the same thing. If legibility is important to you, you have the freedom to write legible code in Perl (just as you have the freedom to write decidedly illegible code in Perl...)" -- Paraphrasing, obviously.

      --
      Bow-ties are cool.
    23. Re:Really Unfortunate Initials by ChaosDiscord · · Score: 1

      Perl is designed to give you several ways to do anything, so consider picking the most readable one.

      You do realize that's simultaneously a joke and a warning, right? While it does implicitly reference the Perl motto, it warns of the dark side: if there is more than one way to do it, there are almost certainly many very bad ways of doing it. It's hardly mindless cheerleading for the language.

      One of the things I appreciate about Perl and Python are their forthrightness. Perl's motto is "There is more than one way to do it." Python's design philosophy included, "There should be one-- and preferably only one --obvious way to do it." Just based on that, a reasonably reflective and experienced programmer should be able to determine which language matches his mindset better.

    24. Re:Really Unfortunate Initials by stephanruby · · Score: 1

      Larry Wall of Perl: "Perl is designed to give you several ways to do anything, so consider picking the most readable one. " - From the Perl Man Pages

      Come on, that statement is in the man pages! The context of that quote already limits its applicability considerably. "anything", within the context of a shell means very little (not that shells aren't very powerful, but you guys know what I mean). Also, comparing the man pages to the way automobiles are being marketed is kind of silly. It's such an horrible analogy, I'm not even sure where to begin.

    25. Re:Really Unfortunate Initials by Tetsujin · · Score: 1

      I enjoyed the interview but I felt the initials of the participants were really unfortunate. DK and BS? I kept reading the whole thing as:

      Donkey Kong: The specification of concepts has taken seven years. By contrast, the standardization of the entire STL took about half that time. What is so complicated about concepts?

      I always wonder about those shirts and stuff that say "Donkey Kong New York", too...

      --
      Bow-ties are cool.
    26. Re:Really Unfortunate Initials by BikeHelmet · · Score: 1

      Yeah, but Java actually has clout. It's what I consider a "heavyweight" language. It's well designed, and efficient - so much so that you can implement other languages in it, to speed them up significantly.

      C/C++, ASM, and Java are basically the big three that everything is built on top of. Many people would be shocked that an interpreted language could make the cut.

    27. Re:Really Unfortunate Initials by shutdown+-p+now · · Score: 4, Insightful

      It's well designed

      I would disagree. Anonymous inner classes are clearly a hack necessitated by a lack of first-class function types. Lack of a more concise capturing mechanism (i.e. true lambdas) is crippling. There's nothing in the language to help solve, or even warn about, the brittle base class problem (@Override is one piece of the puzzle, but more are needed to solve it - see C# for a proper take on this problem, and API versioning in general). Type-erasing generics are one huge hack (I don't care about perf, but they are simply not first-class, and not fully typesafe - consider `instanceof` for a generic interface). Etc.

      and efficient - so much so that you can implement other languages in it, to speed them up significantly.

      Can you give any example of something being sped up significantly by reimplementing it in Java?

      C/C++, ASM, and Java are basically the big three that everything is built on top of. Many people would be shocked that an interpreted language could make the cut.

      I wouldn't be shocked, as Java isn't an interpreted language. JIT compiler still produces native code. And back when there was no JIT, Java was slow.

    28. Re:Really Unfortunate Initials by jeremyp · · Score: 1

      I'm just saddened that, if you type "Eiffel" into Google, a fairly obscure programming language that almost nobody uses beats one of the World's most famous landmarks into second place (as of 8/8/09 00:00 UTC).

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    29. Re:Really Unfortunate Initials by shutdown+-p+now · · Score: 1

      It may be an artifact of your browsing habits (especially if you are logged in with some Google service, but I don't think it really needs that to track them). It's the same for me, though, so maybe not (or maybe it is, since we are both on Slashdot after all).

      On the other hand, Eiffel tower is on the first place on Bing, for me at least.

    30. Re:Really Unfortunate Initials by BikeHelmet · · Score: 1

      Can you give any example of something being sped up significantly by reimplementing it in Java?

      Jython? JRuby?

      I wouldn't be shocked, as Java isn't an interpreted language. JIT compiler still produces native code. And back when there was no JIT, Java was slow.

      It sure does JIT compile fast, though.

      Apparently fully-interpreted Java implementations(Like JamVM w/ GNU Classpath) are faster than the fastest Python/Ruby implementations. I don't have any articles I can cite, but it was the opinion of a brilliant Scala (and C/C++/Java/Python/Ruby/Lisp/Haskell) developer I met.

    31. Re:Really Unfortunate Initials by shutdown+-p+now · · Score: 1

      Jython? JRuby?

      If the original interpreters were sped up by rewriting them in Java, you'd have a point. Instead, the reason for the speedup is that both Jython and JRuby ditch the relatively primitive bytecode intepreter based VMs used by the respective reference implementations, and use the very advanced Java VM instead. Of course that boosts performance. However, the bytecode-targetting compiler for either language could still be written in C, and would, in fact, likely be faster that way. And, of course, JVM itself is written in C.

      It sure does JIT compile fast, though.

      Not really, it's just smart about it, and doesn't JIT-compile if it thinks it would be faster to interpret (e.g. for a one-off method call). If you want to see a really fast (and consequently dumb) JIT compiler, look at .NET. That thing always JIT-compiles because it doesn't have a bytecode interpreter at all, so it had to be made really fast. Even so, when doing perf tests, the delay introduced by JIT compilation is really noticeable when you're measuring operations on the scale of tens of milliseconds.

      Apparently fully-interpreted Java implementations(Like JamVM w/ GNU Classpath) are faster than the fastest Python/Ruby implementations.

      I would be extremely surprised if it wasn't so. Even bytecode-interpreted Java gives plenty of optimization opportunities. For example, Java virtual method calls can still be vtable-based (with pointers directly to bytecode). And all types are known in advance. For Python, to do a method call, you have to start with looking up the method by its name (a string!) in a dictionary for the object. Then, of course, the fact that there are no typed variables or fields, so every operation has to start with a typeswitch. All those bits don't speed things up.

      In fact, I bet that a very simple and straightforward Java bytecode interpreter, written with no optimization in mind whatsoever - just by using the most obvious and simplest implementation techniques - would still be faster than CPython.

      Ruby, well... the reference Ruby interpreter is notorious for being extremely inefficient. It's several times slower than Python! IIRC, of all comparable languages, only PHP has the dubious honor of being slower than Ruby (but it's a mess in many other ways, so no surprise there).

    32. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 0

      Try Blacksmith, moron.

    33. Re:Really Unfortunate Initials by ADRA · · Score: 1

      > Anonymous inner classes are clearly a hack necessitated by a lack of first-class function types
      I don't much care for functional languages and I'm glad I don't have to deal with them for general purpose Object-oriented programming language. If you're hot for functional languages, there's always groovy and Scala to write on top of.

      > Can you give any example of something being sped up significantly by reimplementing it in Java?

      Development time

      All joking aside, Java is simpler and its faster to develop pretty much anything that Java's suitable for. It may not be as fast as the native counterparts, but you'll finish development a lot faster. Your statement on speed just proves my point, you can spend years making a millions of line ASM program to make a GUI application that an equivalent in Java will never be able to beat, but that doesn't mean that I'm literally going to spend the time to do it. If it makes sense to program 'insert application here' in Java( or any other high level languages), then do it and save time/money. If said environment can't meet your requirements, then maybe you have a case to tear down a few abstractions and do it in a lower level language.

      There's a reason so many enthusiasts write in C/C++, but most professionals code in Java, VB, C#, etc... (Excluding scripting / web languages, as those are generally for a different crowd). When I get excited about coding, I like to reinvent every little bell or whistle to see how it all works. I want to challenge myself, because frankly that's why I'm programming in my spare time to begin with; versus at work, I code whatever my boss's bosses thinks will be the fastest / cheapest development time possible so that they can ship 2 more widgets to potential customers. Its far less glamorous, and far more productive.

      --
      Bye!
    34. Re:Really Unfortunate Initials by halivar · · Score: 1

      DOES IT hart yuor FEELINGS WHEN i HAVE A missspelllings IN mie posts?? DOES it MAKES yuo WANT to crie????? I DONT WANT yuor am 2 crie litttle ac because i KNOW im teh onlee friend yuo HAF!

    35. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 0

      You've got to be joking! I'm so tired of Bjarne talking about how great C++ is. Its not that great -- honest! I'm mean it is great for a small portion of what we as software engineers need to do. But he needs to quit acting like its good for building applications -- its not. I've seen teams fail just because someone had chosen C++ for them to do their application development.

      Every time Bjarne does an interview, he always goes on and on about how everyone else says how great there stuff is, but mine is great... and... I"m just happy with my millions of followers because my language is so great... And how everyone wishes they could be C++. Blah blah blah, I've written a lot code in C++ and tutored many a person on how to program with it. I don't do it now and I don't miss it at all.

      Its funny he tries to act like he's not just as bad as all the other language pushers and and I'm sorry that you fall for it. Ha! 95% of applications should not be written in C++. There I said it.

      Thank you for your time :-)

    36. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 0

      OK, let me get this straight..

      Java is a slow, inefficient, crippled, poorly designed, language lacking important features and incorporating 'huge' hacks?

      Damn! Thanks for letting me know.

      I better go undeploy all those mission critical applications I have developed over the past decade or so and give back all that money I made ;)

    37. Re:Really Unfortunate Initials by shutdown+-p+now · · Score: 1

      Java is a slow, inefficient, crippled, poorly designed, language lacking important features and incorporating 'huge' hacks?

      No, it's just not a very good language in general, and not the most perfect one even within its niche. But there are far worse ones.

      Of course, its success is defined more by its libraries and tools (Java had the first IDEs that were recognizably modern, with proper refactoring etc) than by the language itself, so it doesn't matter that much in the big scheme of things.

      I better go undeploy all those mission critical applications I have developed over the past decade or so and give back all that money I made ;)

      You'll have to stand in line after the VB6 folks first, sorry.

    38. Re:Really Unfortunate Initials by stephanruby · · Score: 1

      Whoooooosh...! -- Paraphrasing the paraphraser.

    39. Re:Really Unfortunate Initials by Anonymous Coward · · Score: 0

      C/C++, ASM, and Java are basically the big three

      That's four by my count.

    40. Re:Really Unfortunate Initials by jsight · · Score: 1

      If you want to see a really fast (and consequently dumb) JIT compiler, look at .NET. That thing always JIT-compiles because it doesn't have a bytecode interpreter at all, so it had to be made really fast.

      I don't know about the claim that the JIT compiles everything... but I do know that it does have an interpretter. Its quite possible to run the .Net CLR in pure interpretted mode.

    41. Re:Really Unfortunate Initials by GooberToo · · Score: 1

      Well said!

      +1 Insightful
      +1 Sense of Humor

    42. Re:Really Unfortunate Initials by shutdown+-p+now · · Score: 1

      I don't know about the claim that the JIT compiles everything... but I do know that it does have an interpretter. Its quite possible to run the .Net CLR in pure interpretted mode.

      Please explain how and/or provide the links. All reference material on .NET that I am familiar with which touches the topic quite explicitly states that there is no bytecode interpreter in .NET by design - so bytecode can be optimized for the easy JIT compilation specifically. This is often highlighted as one of the major points of difference between CLR and JVM.

      For example, here is the interview with Anders Hejlsberg - a man who is certainly qualified to speak on how CLR works - about CLR design choices. In it, he says:

      Anders Hejlsberg: ... In our case, though, we never intended to target an interpreted scenario with the CLR. We intended to always JIT [Just-in-time compile] ...

    43. Re:Really Unfortunate Initials by spitzak · · Score: 1

      I tried Google and got the Eiffel Tower Wikipedia article first, and Google then thought the Eiffel language Wikipedia page was a sub-page and listed it indented second.

      Most of the rest of the links were for the tower.

      However there was only one link to Gustave Eiffel...

    44. Re:Really Unfortunate Initials by badkarmadayaccount · · Score: 1

      Give a technical reason for the impossibility of the existence of One Programming Language to rule them all (TM).

      --
      I know tobacco is bad for you, so I smoke weed with crack.
    45. Re:Really Unfortunate Initials by jedwidz · · Score: 1

      Anonymous inner classes are clearly a hack necessitated by a lack of first-class function types. Lack of a more concise capturing mechanism (i.e. true lambdas) is crippling.

      I can't agree that anonymous functions make more sense than anonymous classes in Java. Java is an OO language and code consists almost entirely of class declarations. Anonymous classes are a good fit for this paradigm, just as lambda expressions are great in functional languages.

      I agree entirely that closures and higher-order functions would be an improvement for cases where only a single method is needed (e.g. Runnable), but that's just a special case. Anonymous classes are more general.

  2. C++0x? by clone53421 · · Score: 0, Troll

    What the hell? Do I have to RTFA to find out what C++0x is supposed to mean?

    --
    Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    1. Re:C++0x? by betterunixthanunix · · Score: 5, Informative

      No you need to calm down and thing about the previous designations of C and C++ standards: C++98, C99, etc. C++0x was intended to be a C++ standard released between 2000 and 2009; at this point, it looks like it is actually going to be released in 2010, and we'll all be calling it C++10.

      --
      Palm trees and 8
    2. Re:C++0x? by larry+bagina · · Score: 0, Redundant

      Language standards often include the 2 digit year. C89. Fortran77. The x in c++0x was a placeholder for the year it would eventually be approved.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    3. Re:C++0x? by clone53421 · · Score: 1

      ogood, I didn't. :D

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    4. Re:C++0x? by Trepidity · · Score: 4, Informative

      It's named in parallel with language-revision names like Fortran77 and C99, that use the base language plus the last two digits of their revision year. When the process started years ago, though, they didn't know what year it would finish, but expected it to be in the 200x decade, hence "0x". So, C++0x. Now that the finalization has slipped past 2009, it's C++1x. When it actually comes out, it will have a year with no 'x', like C++10 or C++11.

    5. Re:C++0x? by Desler · · Score: 0, Offtopic

      A flamebait mod? Seriously? Have that mod not been following what has been going on in committee with respect to this new revision? The whole entire process has been a joke for years.

    6. Re:C++0x? by Anonymous Coward · · Score: 0

      What the hell? Do I have to RTFA to find out what C++0x is supposed to mean?

      More than one penis?

      --
      flag@whitehouse.gov

    7. Re:C++0x? by Anonymous Coward · · Score: 0

      Actually, I think it's going to be called C++0A.

    8. Re:C++0x? by Anonymous Coward · · Score: 0

      *sigh*, this got modded all the way down to -1?

      Okay, look. This was not supposed to be a troll post. It was an honest question, I got several good responses, and I'm a little surprised that at three people thought it was troll... or maybe they didn't read the comment and just modded it down because of the title. I don't know.

      Maybe the mods thought my question was obvious, but it would have been nice to have the summary actually tell what C++0x meant.

    9. Re:C++0x? by Dareth · · Score: 1

      That was a really optimistic placeholder. I can hardly wait for C++21XX to come out! Hopefully it won't be just the final version of C++0x. *wink*

      --

      I only look human.
      My mother is a halfling and my dad is an ogre, so that makes me an Ogreling
    10. Re:C++0x? by Threni · · Score: 1, Troll

      If there isn't a standard now, there's never going to be one! Really, you'd think the guy's time would be better spent fixing memory leaks and buffer overruns...

    11. Re:C++0x? by shutdown+-p+now · · Score: 1

      What the hell? Do I have to RTFA to find out what C++0x is supposed to mean?

      If you don't know what it means, then most likely TFA is of no interest or concern to you, anyway.

    12. Re:C++0x? by clone53421 · · Score: 1

      Yeah... which is why I didn't want to read it. I only R'dTFS in the curious hope that it would explain what C++0x meant, and it didn't. Hence my frustration...

      meh, it doesn't really matter.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    13. Re:C++0x? by Impy+the+Impiuos+Imp · · Score: 1

      > Do I have to RTFA to find out what C++0x is supposed to mean?

      I hate to say it, but C# is a more clever name than that. C++ with another ++ over the top of the first ++, like C++, ++. And "sharp" as in musical sharp, which is a little bit higher than the note its sharping.

      --
      (-1: Post disagrees with my already-settled worldview) is not a valid mod option.
    14. Re:C++0x? by Impy+the+Impiuos+Imp · · Score: 1

      Oh thank god you put the *wink* there so I knew you were being jokingly sarcastic.

      --
      (-1: Post disagrees with my already-settled worldview) is not a valid mod option.
    15. Re:C++0x? by russotto · · Score: 1, Funny

      And here I thought they were just glomming on random bits of language syntax
      C++
      C++0x
      C++0x[]
      C++0x[&]
      C++*0x[&]
      etc.

    16. Re:C++0x? by Trepidity · · Score: 3, Insightful

      Hehe, it does seem a pretty good symbol of C++'s syntax: bits of syntax that make sense individually turning into a monstrosity when combined.

    17. Re:C++0x? by Tetsujin · · Score: 1

      What the hell? Do I have to RTFA to find out what C++0x is supposed to mean?

      More than one penis?

      Probably. Makes you wonder why there are so few female programmers, doesn't it?

      Oh, I don't know... Your mom always seemed pretty good at handling more than one penis.

      --
      Bow-ties are cool.
    18. Re:C++0x? by shutdown+-p+now · · Score: 1, Funny

      I like how the following is a legal and meaningful C++0x expression:

      [](){}

      Larry Wall should start getting worried!

    19. Re:C++0x? by Jerry+Coffin · · Score: 1

      Now that the finalization has slipped past 2009, it's C++1x.

      No, it is not C++ 1x. There's already a project that's called C++ 1x, which is slated to be the next revision of C++. There's also a plan for a Technical Report (TR) intended to be published a couple years (or so) after the C++0x revision, but before C++1x.

      I'd note that it's actually fairly common for final approval of a language to happen some time after the date by which it's usually known.

      • Fortran 2008: Not finished yet, most recent draft dated 23 June 2009
      • Algol 60: Approved as an ISO standard in 1984
      • Simula 67: Approved as a Swedish national standard in 1987 (never approved as an ISO standard)
      --
      The universe is a figment of its own imagination.
    20. Re:C++0x? by betterunixthanunix · · Score: 1

      Well, about a decade elapsed between the first C++ "standard" and C++98; it has been a little more than a decade and C++0x is almost done. Serious programming languages are updated from time to time; Fortran is still updated every so often, as is Ada, so why no C++ as well? A lot of companies are committed to C++, and there are billions of lines of C++ code in production right now.

      --
      Palm trees and 8
    21. Re:C++0x? by Anonymous Coward · · Score: 0

      And there I assumed it was going to be C++0xa...

      np: Death Cab For Cutie - Little Fury Bugs (We Have The Facts And We're Voting Yes)

  3. Why not just do duck typing? by morgan_greywolf · · Score: 3, Interesting

    Templates are what Python calls 'duck typing'. ("If it looks like a duck and quacks like a duck...") Why not just do that? You could add methods for introspection and so forth...

    1. Re:Why not just do duck typing? by EsbenMoseHansen · · Score: 1

      Templates are what Python calls 'duck typing'. ("If it looks like a duck and quacks like a duck...") Why not just do that? You could add methods for introspection and so forth...

      Because C++ is a statically typed language, which means that type errors are discovered at compile time. For C++, discover = kilobytes of error messages, which is one of the key things concepts would fix.

      Generic (static) programming is one of the areas where C++ is far outshines it's competitors, though heaven knows it has enough other flaws. Sigh, someday I will get a language which satisfies my quite reasonable list of requirements for a decent language.

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    2. Re:Why not just do duck typing? by Anonymous Coward · · Score: 0

      LOL

    3. Re:Why not just do duck typing? by smallfries · · Score: 5, Informative

      I don't think that they are. There is quite a good comparison on the wiki page. The main difference that springs to mind is that duck typing in Python is dynamic (resolved at runtime), where-as the type system in C++ is static (resolved at compile-time). That makes them very different beasts.

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
    4. Re:Why not just do duck typing? by spiffmastercow · · Score: 1

      Because in C++ a class is basically a struct with some function pointers. If you make that struct a variable size, you break the memory allocation system.

    5. Re:Why not just do duck typing? by Anonymous Coward · · Score: 1, Insightful

      Sigh, someday I will get a language which satisfies my quite reasonable list of requirements for a decent language.

      Like this?

    6. Re:Why not just do duck typing? by EvanED · · Score: 2, Informative

      Other people have said that that breaks C++'s static typing, but what they didn't say is that static typing is one of the explicit design goals of C++.

      Some quotes from The Design and Evolution of C++:

      "The importance of static type checking was also strongly emphasized. In other words, C++ follows the Simula rather than the Smalltalk model of inheritance and type checking."

      "This delayed type-error detection [as present in Smalltalk or Python] was considered unacceptable for C++."

      "However, the most fundamental reason for relying on statically checked interfaces was that I was -- as I still am [at least 1994] -- firmly convinced that a program composed out of statically type-checked parts is more likely to faithfully express a well-thought-out design than a program relying on weakly-typed interfaces or dynamically-checked interfaces."

    7. Re:Why not just do duck typing? by EvanED · · Score: 1

      Neither duck typing nor introspection requires variable-sized structs.

    8. Re:Why not just do duck typing? by Abcd1234 · · Score: 0

      Templates are what Python calls 'duck typing'. ("If it looks like a duck and quacks like a duck...")

      First, what you young bucks like to call 'duck typing', as cutesy as that sounds, the computing science world calls 'dynamic dispatch'. And it's hardly a new concept (see Smalltalk for a classic example). But, hey, what's old is new and shiny again, right?

      Second, dynamic dispatch specifically happens at runtime. Templates, on the other hand, are realized at compile time, as are any method calls made against a templated class. As such, the two concepts are entirely different, both from a conceptual and an implementation standpoint.

    9. Re:Why not just do duck typing? by metamatic · · Score: 4, Insightful

      Because C++ is a statically typed language, which means that type errors are discovered at compile time.

      Well, many type errors are discovered at compile time. Unfortunately, static typing tends to have the side effect of requiring more complex code, and often has to be worked around.

      Personally, I write mostly in Java and Ruby. Java is pedantically static to a level that would make C++ blush, while Ruby is completely duck typed. I've had situations where Java's pedantic nature has caught bugs before test runs, but I've also had situations where the code was 10x as long and harder to debug because of the inflexibility. I think it's highly debatable which approach is better, and the answer probably depends on the kind of problem you're solving.

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    10. Re:Why not just do duck typing? by EvanED · · Score: 1, Informative

      First, what you young bucks like to call 'duck typing', as cutesy as that sounds, the computing science world calls 'dynamic dispatch'.

      That's not true.

      First, 'duck typing' is actually a reasonably-standard term. I would define it as "the operations your object supports are not defined a priori". A language like Smalltalk or Python or Ruby doesn't have class definitions in the same way as Java and C++ do; instead, an object just has some methods, and if it supports the method you're trying to call it works, otherwise it fails. C++ templates are duck typing -- they're just compile-time duck typing. For instance:

      template <typename T>
      void foo(T & a) {
        a.bar();
        return a + 1;
      }

      This function imposes an interface on T: it needs to support a zero-argument bar function and operator+ with an int argument (or something int can be converted to), be it a member or free function. But there is nowhere that interface is actually specified; it's implicit in the function. For any type T that supports those two operations, you can instantiate foo with that type. This is what is meant by "if it looks like a duck and quacks like a duck, it's a duck."

      By contrast, you can have dynamic dispatch in a statically-typed language. C++ does: virtual methods. Virtual method dispatch is dynamic dispatch, even if it's through a statically-defined interface that produces a vtable.

    11. Re:Why not just do duck typing? by spiffmastercow · · Score: 1

      They do if you want to add class members on the fly. If not, then duck typing is pointless, as is introspection

    12. Re:Why not just do duck typing? by Timothy+Brownawell · · Score: 1

      First, what you young bucks like to call 'duck typing', as cutesy as that sounds, the computing science world calls 'dynamic dispatch'. And it's hardly a new concept (see Smalltalk for a classic example). But, hey, what's old is new and shiny again, right?

      No. Dynamic dispatch is what for example virtual methods (or multimethods) do, where which version of the code gets called depends on the types of the arguments. Duck typing is where instead of you telling the compiler what types of arguments are allowed, it either figures it out entirely on its own (ocaml, I think) or just checks at runtime instead (dynamic languages).

    13. Re:Why not just do duck typing? by Abcd1234 · · Score: 1

      First, 'duck typing' is actually a reasonably-standard term.

      Only since Python and particularly Ruby fans started using it as a way to market a feature in their pet language (dynamic typing coupled with dynamic dispatch) that's been available in existing languages for *many* years. It's a marketing term, nothing more. It adds nothing to the actual discussion, other than to sound all neat and cutsey.

      I would define it as "the operations your object supports are not defined a priori".

      And I would define it as dynamic typing and binding. Nothing more. The language determines, at run time, how to bind a method call to an object. It's just that simple.

      A language like Smalltalk or Python or Ruby doesn't have class definitions in the same way as Java and C++ do

      Of course they do. Every single language you listed is strongly typed. The only difference is that Smalltalk, Python, and Ruby are dynamically typed, while Java and C++ are statically typed. That's it.

      C++ templates are duck typing -- they're just compile-time duck typing.

      "compile-time duck typing" is, by definition, a contradiction. Duck typing specifically necessitates binding at runtime. You have an instance of an object, and a method call directed at it, and the compiler doesn't bind that call until it actually occurs, at which point the runtime figures out how to dispatch the call.

      Templates, on the other hand, are realized at compile time. The template arguments are applied to the type, and new code is generate which represents the realized template. That template is then compiled, and the method calls are type checked and linked at compile time. It's a fundamentally different operation.

      But there is nowhere that interface is actually specified; it's implicit in the function.

      And that's a *bad thing*. Because if the object doesn't support the method, the compile will generate the templated code, the code will fail to compile, and the compiler will emit an exceptionally cryptic error. This is the whole reason Concepts were invented: it allows the developer to be explicit about what the template expects from it's arguments, so that when the compile fails, the compiler can do a much better job explaining what, exactly, went wrong.

      But again, the key is, all this is happening at compile time before the code ever runs. It's completely different from what you like to call "duck typing".

      By contrast, you can have dynamic dispatch in a statically-typed language.

      Correct. And as such, you're right, my original post wasn't accurate. What I should've said is that duck typing == dynamic dispatch + dynamic typing. Either way, it's hardly a new idea. And it's an idea that does *not* fit in a language that's meant to be strongly, statically typed (eg, C++).

    14. Re:Why not just do duck typing? by Abcd1234 · · Score: 1

      Dynamic dispatch is what for example virtual methods (or multimethods) do, where which version of the code gets called depends on the types of the arguments.

      Uh, no. That's just multimethod dispatch. Dynamic dispatch is what makes polymorphism possible. Specifically, it's the binding of a method call to an object at runtime (for example, in C++, this is done with vtables). But, you are correct, in that I wasn't being precise enough (see below).

      Duck typing is where instead of you telling the compiler what types of arguments are allowed, it either figures it out entirely on its own (ocaml, I think) or just checks at runtime instead (dynamic languages).

      Yes yes, I know, I was being too simplistic (I realized this after I hit submit). Duck typing == dynamic dispatch *and* dynamic typing. Either way, "duck typing" is a stupid marketing term, nothing more.

      And, BTW, duck typing is *not* the same as type inference, which is what you see in ocaml and Haskell.

    15. Re:Why not just do duck typing? by morgan_greywolf · · Score: 1

      By contrast, you can have dynamic dispatch in a statically-typed language. C++ does: virtual methods. Virtual method dispatch is dynamic dispatch, even if it's through a statically-defined interface that produces a vtable.

      Correct. In Python, all methods are virtual.

      My point is it sounds like Bjarne wants to take C++0x and add dynamic language features. My suggestion is either to make C++ a dynamic language, or at least support some subset of features of a dynamic language that you can in a statically-typed langugage.

      The implementation details of how to do that are left as an exercise to the reader.

    16. Re:Why not just do duck typing? by Homburg · · Score: 1

      duck typing in Python is dynamic (resolved at runtime), where-as the type system in C++ is static (resolved at compile-time).

      It's not quite that simple. C++ templates are a Turing-complete programming language, evaluated at compile time. So "runtime" for templates is compile time. Type checking for templates is done when they are evaluated, not when they are defined, that is, at runtime (to repeat, the template runtime that happens during compilation). So they are indeed, like Python, duck typed. Concepts would have added a system for checking templates when they are defined, which would be the equivalent of a static type system for the template language that gets evaluated during compilation.

    17. Re:Why not just do duck typing? by EsbenMoseHansen · · Score: 1

      Because C++ is a statically typed language, which means that type errors are discovered at compile time.

      Well, many type errors are discovered at compile time. Unfortunately, static typing tends to have the side effect of requiring more complex code, and often has to be worked around. Only if said checks are broken, I believe. Do you have an example? But yes, declaring your types leads to more verbose code for sure; this is one of the trade offs for static typing.

      Personally, I write mostly in Java and Ruby. Java is pedantically static to a level that would make C++ blush, while Ruby is completely duck typed. I've had situations where Java's pedantic nature has caught bugs before test runs, but I've also had situations where the code was 10x as long and harder to debug because of the inflexibility. I think it's highly debatable which approach is better, and the answer probably depends on the kind of problem you're solving.

      I myself has worked extensively in C, C++, Ruby, Perl and Java and many other languages, and of those I do like both Ruby and C++. Java feels like a straightjacket to me, and it sounds like you have the same problem. Perhaps you should try a more powerful language, such as C++?

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    18. Re:Why not just do duck typing? by Timothy+Brownawell · · Score: 2, Insightful

      Only since Python and particularly Ruby fans started using it as a way to market a feature in their pet language (dynamic typing coupled with dynamic dispatch) that's been available in existing languages for *many* years. It's a marketing term, nothing more. It adds nothing to the actual discussion, other than to sound all neat and cutsey.

      Standardized terminology adds quite a lot to any discussion.

      And I would define it as dynamic typing and binding. Nothing more. The language determines, at run time, how to bind a method call to an object. It's just that simple.

      What do you call what Ocaml does?

      Templates, on the other hand, are realized at compile time.

      C++ templates are a turing-complete functional programming language, and are executed by the compiler. What you think of as "compile time" is the same as "runtime" for the templates.

      What I should've said is that duck typing == dynamic dispatch + dynamic typing. Either way, it's hardly a new idea. And it's an idea that does *not* fit in a language that's meant to be strongly, statically typed (eg, C++).

      The principle of duck typing says that you shouldn't care what type of object you have - just whether or not you can do the required action with your object.
      CeePlusPlus: Templates can create compile-time polymorphism via DuckTyping (as used in AndreiAlexandrescu's ModernCeePlusPlusDesign as well as Microsoft's ActiveTemplateLibrary).
      In computer programming, duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class or implementation of a specific interface. [...]"when I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."

      Duck typing does not require dynamic dispatch, and does not (strictly) require dynamic typing. All it requires is that what matters is "I have a multiply() method" rather than "I am a number".

    19. Re:Why not just do duck typing? by Homburg · · Score: 1

      "compile-time duck typing" is, by definition, a contradiction.

      Not if compilation involves evaluating a Turing-complete language. In that case, "compile time" is also the run time for the language that is evaluated during compilation. Compiling lisp code that uses macros also involves running those macros. Likewise, compiling C++ code that uses templates involves running those templates; compile time is also run time. Dispatch that happens when these templates are evaluated is as much duck typing as the dispatch that occurs during the evaluation of a Python program. Just because the interpreter in this case is also a compiler doesn't make it any less duck typing.

    20. Re:Why not just do duck typing? by metamatic · · Score: 1, Interesting

      Well, either you believe in static typing, or you don't. If you do, Java is a good choice. If you don't, Ruby is a good choice. C++, on the other hand, is static enough to be annoying, but not static enough to be safe.

      I actually much prefer Objective-C to C++. Once again, the worse solution won.

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    21. Re:Why not just do duck typing? by EvanED · · Score: 1

      It's a marketing term, nothing more. It adds nothing to the actual discussion, other than to sound all neat and cutsey.

      As another poster has said, giving something a name has merit too. I mean, look how much the Gang of Four's Design Patterns has been cited, and how influential it was. They themselves said they didn't actually invent anything, but merely described existing practice and gave it a name. And now most programmers know what a singleton is.

      "A language like Smalltalk or Python or Ruby doesn't have class definitions in the same way as Java and C++ do"

      Of course they do. Every single language you listed is strongly typed. The only difference is that Smalltalk, Python, and Ruby are dynamically typed, while Java and C++ are statically typed. That's it.

      No they don't. Python, Smalltalk, and Ruby can (I think; I know Python can) add and remove methods dynamically. About the most you can say is that an object specifies its own class definition.

      If I have a python definition of a class and create an instance obj then add a method foo to it, where is the definition of that class plus method foo? There isn't one. It's implicit in the code.

      By contrast, in C++, if I have an object, I know that the interface it supports is listed in the source relatively locally. I know that somewhere there is a class definition that contains (with its inheritance ancestors) exactly that object's interface.

      Put another way, in general the shortest description an object's interface in Python is the list of methods it supports, even if you have the source code. The shortest description of an object's interface in C++ is the name of its class.

      "Doesn't have a class definition" != "not strongly typed". (Not that I think "strongly typed" has much meaning. See here, at the message a few down written by Mark-Jason Dominus.)

      Duck typing specifically necessitates binding at runtime.

      I'm not sure I agree. I think describing templates as "compile-time duck typing" conveys a lot about how templates behave in a reasonably accurate manner. (I do think that the arguments about compile-time being run-time for the templates are a bit of a red herring.)

      I mean, yes, in some sense "compile-time duck typing" is an oxymoron, but that doesn't mean it can't be a useful term. I think the essential aspect of "duck typing" is less the "dynamic" part and more the "no explicit interface specification" part.

      And that's a *bad thing*. Because if the object doesn't support the method, the compile will generate the templated code, the code will fail to compile, and the compiler will emit an exceptionally cryptic error. This is the whole reason Concepts were invented...

      Yes, I know that.

      In fact, in the past I've described concepts as being the template analogy of a class definition, in that they explicitly specify what types support the interface a template expects. So "class definition : object :: concept : class".

      (Incidentally, I say this fits right into what we're saying here. Explicit immutable class definitions are the opposite of duck typing for objects, so templates that used concepts would be not duck-typed.)

    22. Re:Why not just do duck typing? by EvanED · · Score: 1

      Both of those can be very useful without being able to change what methods are available on the fly. For instance, Java doesn't let you modify the available methods of an instance (at least AFAIK; I'd be astonished if you could), but still has reflection capabilities that are occasionally very useful and let you do things you couldn't otherwise.

    23. Re:Why not just do duck typing? by Timothy+Brownawell · · Score: 1

      And, BTW, duck typing is *not* the same as type inference, which is what you see in ocaml and Haskell.

      I know the difference, it looks like I just misremembered what Ocaml can (or can't) do:

      # type aaa = X | Y | A;;
      type aaa = X | Y | A
      # type aaa = X | Y | A;;
      type aaa = X | Y | A
      # type bbb = X | Y | Z;;
      type bbb = X | Y | Z
      # let foo e = match e with X -> 5 | Y -> 4 | _ -> 0;;
      val foo : bbb -> int =
      # let bar e = match e with X -> 5 | Y -> 4 | A -> 2 | _ -> 0;;
      Error: This pattern matches values of type aaa
      but a pattern was expected which matches values of type bbb
      #

    24. Re:Why not just do duck typing? by Anonymous Coward · · Score: 0

      But Objective C lost!

    25. Re:Why not just do duck typing? by EsbenMoseHansen · · Score: 1

      Well, either you believe in static typing, or you don't. If you do, Java is a good choice. If you don't, Ruby is a good choice. C++, on the other hand, is static enough to be annoying, but not static enough to be safe.

      I actually much prefer Objective-C to C++. Once again, the worse solution won.

      Perhaps you can back that up with an example of where Java makes it bothersome? Then I can show you how it is done in an adult language :P (Limitation: I haven't found a good static reflection-enabled language, (I have no idea why), so reflection based examples are off-limit :) )

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    26. Re:Why not just do duck typing? by Anonymous Coward · · Score: 0

      That's the monomorphism restriction. Haskell has it too, but it can be overridden in ghc. It can result in undecideable types, however, but you can even allow those if you don't mind potentially stalling your compiler for minutes.

    27. Re:Why not just do duck typing? by Anonymous Coward · · Score: 0

      Using variant variables might do what you want. Check out cppscript on google code (http://code.google.com/p/cppscript/) it uses variants for everything but mixes seamlessly with c++. There is also my library, luawanb, (http://code.google.com/p/luawanb/) that uses variants to try and make the functional equivalent of lua's tables in c++.

    28. Re:Why not just do duck typing? by spiffmastercow · · Score: 1

      But those useful things are usually due to the common inheritance in Java (i.e. given a list of objects, do something different with the objects depending on what type it is). These are irrelevant in C++, since classes do not all derive from a base object type. Likewise, duck typing is irrelevant if you use a system of interfaces as in C#, or multiple inheritance with virtual functions, as in C++. I'm not saying its the best way to do it, but if you changed these things, it wouldn't be C++ anymore.

    29. Re:Why not just do duck typing? by bar-agent · · Score: 1

      I haven't found a good static reflection-enabled language, (I have no idea why), so reflection based examples are off-limit

      Dylan is a good static reflection-enabled language. Well, it's a dynamic language, but you can statically declare the type of everything, even unto the elements of collections, the valid ranges of integer values, and a class's subclassability.

      --
      i'd hit it so hard, if you pulled me out you'd be the king of britain [bash.org]
    30. Re:Why not just do duck typing? by EvanED · · Score: 1

      But those useful things are usually due to the common inheritance in Java (i.e. given a list of objects, do something different with the objects depending on what type it is).

      There are still plenty of things that you could use them for that don't have anything to do with that:

      It would be much easier to write a simple scripting language to interface with the core of your program if the core is written in a language with reflection. Right now you basically have to write or generate a bunch of wrapper functions, so that if in your scripting language you say "a.foo()", there is a translation layer that eventually calls "foo" on object "a". If C++ had reflection, you could write a "callMethod()" function in "a"'s class, pass it "foo" as a string, and just use reflection to call it.

      This example requires annotations too, but assume that you can annotate functions and access those annotations from the reflection API. One of my favorite command line argument processing engines I've seen is Mono's GetOptions library. (So super-duper better than getopt and variants it's not even funny. There is at least one other technique, shown in Mono.Options and a Boost library and Python, that give GetOptions a run for its money though. I'm not sure which I like better.) Basically you write a class that has a field for each option you want (I'm not sure if it will let you call functions; there are some improvements that can be made while keeping the idea the same), and you annotate each field with what command line option should set it, what should be accepted as arguments to that option, etc. You then call some parse function with the actual argv array. The parse function uses reflection to look through the object you give it to find the fields with annotations, looks at the annotation to get the option, the looks through the command line for that option. If it's present, it sets the field accordingly.

      About 8 years ago I was an intern at IBM, and was programming a Java Servelet for the summer. One of the other interns on my team (we were a team of 3 interns plus some supervisors) pushed for using Java Apache Struts for the project, and we did that. In general I'm unhappy when I see Java have support for things that are harder to do in C++ (if I were to program in a language in the statically-typed C-like language area, C++ would be my clear choice; D is the only one I've seen that I would consider much), so I thought about what you would need to do to write basically a C++ version of Struts. The only part of it that I think would be hard to duplicate for a C++ library was some part that used reflection. (Not to say it wouldn't take a lot of time. I'm certainly not going to do it.) Unfortunately for the life of me I can't remember what it was though.

      None of these require adding or removing methods from an object, and none of them require classes inheriting from some base type. Templates somewhat take the place of the latter problem.

    31. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 1

      C++, on the other hand, is static enough to be annoying, but not static enough to be safe.

      Can you give an example of where C++ is "not static enough" to be type-unsafe? I.e. any piece of C++ code that would be type-unsafe and wouldn't involve an explicit cast telling "yes, I really want this to blow up!".

    32. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 1

      "compile-time duck typing" is, by definition, a contradiction. Duck typing specifically necessitates binding at runtime.

      Where does the definition of duck typing specifically necessitates binding at runtime?

    33. Re:Why not just do duck typing? by EvanED · · Score: 1

      Can you give an example of where C++ is "not static enough" to be type-unsafe?

      I'm not the original poster, but many PL people would consider memory safety violations as breaking type safety. This includes buffer overruns, multiple frees, etc.

      You can get around using arrays in C++ with strings and vectors most to almost all of the time, but usually not all the time. And vector's [] operator isn't bounds checked anyway with most implementations not in debug mode; you have to use .at() to be safe.

      There's also an argument that the fact that you can even do unsafe casts means that C++ isn't fully type-safe. (Especially because it's probably too easy to be in a situation where it seems like a cast is safe but it actually isn't.)

    34. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 1

      First, 'duck typing' is actually a reasonably-standard term. I would define it as "the operations your object supports are not defined a priori". A language like Smalltalk or Python or Ruby doesn't have class definitions in the same way as Java and C++ do; instead, an object just has some methods, and if it supports the method you're trying to call it works, otherwise it fails. C++ templates are duck typing -- they're just compile-time duck typing.

      All true, but there's a perhaps even better example of "static duck typing" - Objective Caml. It doesn't have templates, but its OO type system is structural (rather than nominal), and it has full type inference. What this means is that I can define a function like this:

      let f x = x#foo (x#bar);;

      Operator # in OCaml is the same as dot in C++/Java/... - method call on an object. So function f in example above first calls method "bar" on object "x", and then uses the value returned from it as an argument in another call, this time to method "foo", on the same "x".

      Note how I didn't specify type for "x", nor the signature of "foo" and "bar". OCaml is a statically typed language though, so the type is actually there - it was fully inferred. If you use the REPL to define the function above, it will spell it out.

      val f : < bar : 'a; foo : 'a -> 'b; .. > -> 'b

      The type of "x" here is the part inside angle brackets (which by themselves mean "object"):

      < bar : 'a; foo : 'a -> 'b; .. >

      This says that "x" must be an object with method "bar" which takes no arguments and returns some value of some (unknown) type 'a, and method "foo" which takes a single argument of the same type 'a, and produces a different value of a possibly different type 'b. That ".." at the end means that object can have any other methods in it aside from the ones listed. The function "f" itself is therefore generic on 'a and 'b.

      With that, the following will work:

      class c1 = object
        method bar = 1
        method foo x = x + 1
      end;;
       
      f (new c1);; (* 'a is int, 'b is int *)

      and so will this:

      class c2 = object
        method bar = "123"
        method foo x = int_of_string x
      end;;
       
      f (new c2);; (* 'a is string, 'b is int *)

      However, this is all fully typechecked at compile-time, and furthermore, unlike C++ templates, it doesn't error out at the point where the function tries to use the member that's not available - it fails immediately at the function call.

      Still, if "f" in the example here doesn't use duck typing, then I don't know what the hell duck typing is supposed to be. So we have it: static duck typing.

    35. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 2, Informative

      I'm not the original poster, but many PL people would consider memory safety violations as breaking type safety. This includes buffer overruns, multiple frees, etc.

      Er, you said it yourself - there's "type safety" and there's "memory safety". Those are two entirely orthogonal concepts, and I'm not aware of anyone who's into PL design (professionally or otherwise) who would mix those.

      There's also an argument that the fact that you can even do unsafe casts means that C++ isn't fully type-safe.

      Well, Java lets you do unsafe casts as well. Especially with generics (where such casts need not fail immediately), this can be an endless source of fun. Granted, Java at least doesn't say it's just U.B. to do so, but still.

      In any case, the original post was (seemingly, at least) made more from a pragmatic perspective than from an academic one. With that in mind, consider that C#, for example, also has raw pointers with arithmetic and unsafe casts. I don't see how it makes it any more type-unsafe than Java for the end-user (i.e. your average developer).

    36. Re:Why not just do duck typing? by EvanED · · Score: 1

      I think I mostly agree with basically everything you said. That particular example of objects in O'Caml seems very closely-aligned with what I would call 'static duck typing', though I don't know much about O'Caml specifically. I have done rather a bit of SML programming though; with the part of type inference that fits in that language's model (i.e. no objects), I would say they are related but still sufficiently different that I would still distinguish.

      There's just one more comment I have, which is about your statement that "[O'Caml] doesn't error out at the point where the function tries to use the member that's not available - it fails immediately at the function call." If anything, I think that templates are a little closer to the dynamic notion of duck typing for exactly that reason -- if the same code were written in a dynamic language, the compile-time type-checking error becomes a run-time error. But it will be an error at the site of the call to the missing function rather than the call to f -- in which case the backtrace corresponds almost exactly to the "instantiated from" stack that the C++ compiler gives. ;-) (That's not to say that the O'Caml compiler error is worse than C++'s, just that templates are closer to the dynamic notion of duck typing on that count. In fact, the goal concepts was to bring C++ errors closer to what you'd get in O'Caml in that example.)

    37. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 1

      There's just one more comment I have, which is about your statement that "[O'Caml] doesn't error out at the point where the function tries to use the member that's not available - it fails immediately at the function call." If anything, I think that templates are a little closer to the dynamic notion of duck typing for exactly that reason -- if the same code were written in a dynamic language, the compile-time type-checking error becomes a run-time error.

      True, but the difference isn't really important in this case - any C++ template call that would succeed will be inferred as typesafe in correspoding OCaml code, and any OCaml call that would fail to typecheck would also fail in corresponding C++ code during template instantiation. Well, at least for those subsets of both languages where they interlap, since C++ lets you use duck typing some things that cannot be done in OCaml (such as calling global functions, or applying operators).

    38. Re:Why not just do duck typing? by BikeHelmet · · Score: 1

      Well, either you believe in static typing, or you don't. If you do, Java is a good choice. If you don't, Ruby is a good choice. C++, on the other hand, is static enough to be annoying, but not static enough to be safe.

      I actually much prefer Objective-C to C++. Once again, the worse solution won.

      I don't believe in static typing, but I much prefer Java to C. Half-baked implementations really irk me.

      Whether being half-baked is useful is beside the point, because I'd sure find it useful to be able to treat any integer as a pointer or integer, on demand, as you can in assembly. That's even more lax, but according to C/C++ worshippers, that's too lax, while C/C++ isn't.

      So I definitely prefer too strict to "too lax".

    39. Re:Why not just do duck typing? by DogAlmity · · Score: 1

      What? No. Templates are not what any language calls duck typing. Templates help with generic programming, duck typing helps with dynamic types and type inference. These two things are related ( I guess ) but not the same.

    40. Re:Why not just do duck typing? by HeronBlademaster · · Score: 1

      Because duck typing can lead to weird and inconvenient bugs that are nearly impossible to detect.

      More to the point, Python's duck typing is broken. Nobody should have to spend five hours tracking down a bug specifically caused because Python can't figure out that when I tell it to write an integer and I give it a string, it should treat the string as an integer (and before you all say "the string must not have had a number in it", the string was nothing but "10", as I confirmed when I figured out the cause of the bug).

      Now if you'll excuse me, I have a meeting with my Recovering Python Programmers support group.

    41. Re:Why not just do duck typing? by EvanED · · Score: 1

      Er, you said it yourself - there's "type safety" and there's "memory safety". Those are two entirely orthogonal concepts, and I'm not aware of anyone who's into PL design (professionally or otherwise) who would mix those.

      I would say that lack of memory safety implies a lack of type safety.

      This is probably just a matter of definition of "type safety"; I'm likely being more picky about what counts as that than you are. I definitely think that they are not at all "entirely orthogonal".

      Well, Java lets you do unsafe casts as well.

      Java's unsafe casts are entirely different than C's unsafe casts. Downcasts are still checked at runtime. In C you can cast a double* to a int* and actually read the bytes of the double as if it were an int; there's no way to do that in Java, and such operations are most decidedly not type-safe.

      With that in mind, consider that C#, for example, also has raw pointers with arithmetic and unsafe casts. I don't see how it makes it any more type-unsafe than Java for the end-user (i.e. your average developer).

      This is certainly true. There is definitely a spectrum from "type safe" to "type unsafe". Something like ML is basically entirely on the "type safe" side; something like C is pretty darn close to "type unsafe". (Implicit casts between pointer types and a couple other things that C++ fixes completely break C's type safety IMO.)

      Java is most of the way across towards "type safe" and C# is just a little less safe.

    42. Re:Why not just do duck typing? by Abcd1234 · · Score: 1

      Well, many type errors are discovered at compile time. Unfortunately, static typing tends to have the side effect of requiring more complex code, and often has to be worked around.

      Not at all. Take Haskell, for example. It is, without a doubt, the strongest typed language I've ever seen, and has a rather interesting type system. But thanks to type inference, it can figure out most of the details at compile time, which means that you rarely have to do type annotations (although developers typically do, as it aids in readability).

      As an aside, C# will be including some level of type inference in version 4, which should make it's functional features far less onerous to use (anyone who's made heavy use of anonymous delegates knows what I'm talking about).

    43. Re:Why not just do duck typing? by Abcd1234 · · Score: 1

      Still, if "f" in the example here doesn't use duck typing, then I don't know what the hell duck typing is supposed to be.

      But, you said it yourself. It's not duck typing, it's compile-time type inference.

      Duck typing, at least in my mind, is the idea that, in a given block of code, I, nor the compiler, care what the type of a given variable is. I just call a method on it, and it'll either work, because the object supports the method/message, or it won't. ie, it'll either quack like a duck or it won't.

      But if you're doing static type inference, the compiler *knows* whether or not the thing is a duck, and will tell you if it isn't (and fail to compile). This is a very different thing. In this case, all the types exist, everywhere, but because of type inference, they just aren't annotated. But with "duck typing", the types are discovered at run time, and method dispatch occurs at that point (in a static language with type inference, the binding will happen at link time, since the compiler will know exactly which method to call).

      So, no, I disagree, what you described is *not* duck typing. It looks similar, in that the developer doesn't have to worry about being explicit with types, but deep down they're very different things.

      So, I guess the real question is: is duck typing a description of a mechanism (dynamic typing + dispatch), or is it just a generalized philosophy. If it's the latter, then any language that supports type inference, statically or dynamically, strong or weak, can lay claim to it. That includes Python, Ruby, Perl, Javascript, C# 4.0... heck, even regular ol' C with run-time type casting can claim to be "duck typed", as you can freely cast a void* to anything you want, and it might or might not work as you expect. 'course, at that point, the term has lost all meaning.

    44. Re:Why not just do duck typing? by HeronBlademaster · · Score: 1

      If C++ had reflection, you could write a "callMethod()" function in "a"'s class, pass it "foo" as a string, and just use reflection to call it.

      That's not particularly difficult to fake, if you're willing to do a little maintenance. Make a map of std::string to function pointers, mapping the scriptable function name to the object's member function. boost::bind lets you do this pretty easily; I've used it to write a generic context menu class (wrapping MFC's insane menu API).

      This has the added benefit of preventing people from calling functions on that class that you don't want them to call - using reflection, they could in theory call any member function of the class, regardless of whether it's part of your scripting API, unless you explicitly filter for it in your callMethod function.

      If you're going to maintain a set of allowed (or disallowed) functions anyway, I'd personally choose to maintain the permitted list rather than the non-permitted list, to avoid mishaps.

      Of course, if your functions take different numbers and/or types of arguments, you might have to handle each individual function separately anyway, making the whole reflection thing moot.

      Bottom line is, I don't think reflection would really add anything to the language that you couldn't fake with some ugly and/or elegant code (at least as far as your example goes).

    45. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 1

      Java's unsafe casts are entirely different than C's unsafe casts. Downcasts are still checked at runtime. In C you can cast a double* to a int* and actually read the bytes of the double as if it were an int; there's no way to do that in Java, and such operations are most decidedly not type-safe.

      In Java, you can cast a List<Double> to a List<Integer>, and the cast will succeed at run-time. In fact, depending on the underlying container, you will actually be able to put objects of the wrong class into it, and will only get an exception when someone will try to treat an Integer element as a Double. Yes, this isn't the same as treating raw bytes of object in a wrong way, but in terms of type safety violation it's still breakage.

    46. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 1

      So, I guess the real question is: is duck typing a description of a mechanism (dynamic typing + dispatch), or is it just a generalized philosophy. If it's the latter, then any language that supports type inference, statically or dynamically, strong or weak, can lay claim to it.

      Not quite - only a language that supports type inference and structural rather than nominal typing (i.e. allow types to be like "any object with operations X, Y and Z supported", and not require it to be specifically "of class Foo") would be able to lay claim to it.

      Otherwise, I agree that it is really a matter of definition. Since "duck typing" is not a well-defined term, I guess we'll have to just agree to disagree.

      hat includes Python, Ruby, Perl, Javascript, C# 4.0

      It's a curious listing, but I don't really understand why you wouldn't consider the listed languages to be duck-typed even under your, stricter definition (of dynamic typing + dispatch). Or am I missing something?

      heck, even regular ol' C with run-time type casting can claim to be "duck typed", as you can freely cast a void* to anything you want, and it might or might not work as you expect.

      Since a cast to anything but the original pointer type (with a few exceptions, such as char* to get raw bytes) is U.B., such casting doesn't give you a mechanism to say "do X" on an object of an uncertain type, and have it done so long as "X" is somehow supported for the object (again, with a few edge cases, such as X being "copy all bytes constituting the object"). So it's not duck typing even from my definition of it.

    47. Re:Why not just do duck typing? by EvanED · · Score: 1

      Yes, this isn't the same as treating raw bytes of object in a wrong way, but in terms of type safety violation it's still breakage.

      That's only if you take the position (as I occasionally do, but only occasionally) that types are a property of a variable and not a value. That's basically the strictest possible interpretation, and to take it would mean that you think that Python, Scheme, etc. aren't typesafe. There's not any real difference between the sort of runtime checking that dynamically-typed languages do and the sort of runtime checking that Java does on a downcast from a type safety point of view.

      In both cases, either the compiler or runtime system enforces that the globs of memory that correspond to objects are treated in a way that is consistent with their interface; this is something that you don't get with unsafe C casts. (And incidentally you also don't get it if you overwrite those bytes by going off the end of an array, which is why memory-safety violations can be considered type-safety violations from a certain point of view.)

    48. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 1

      That's only if you take the position (as I occasionally do, but only occasionally) that types are a property of a variable and not a value.

      But this is decidedly true for any self-declared statically typed language - such as, well, Java - by the very definition of "statically typed"! In a statically typed language, expressions have static types. Variables represent bound expressions, and therefore also have types.

      In any case, my Java example wasn't about variables at all. It can be written thus with no variables involved:

      ((List<String>)(new ArrayList<Integer>())).add("Foo");

      Not only this won't fail to compile (though you'll get a warning with default settings), but it will actually execute successfully at runtime as well.

      In both cases, either the compiler or runtime system enforces that the globs of memory that correspond to objects are treated in a way that is consistent with their interface; this is something that you don't get with unsafe C casts.

      Technically, the only real difference is that Java guarantees that you will get an exception when you try to treat an object "wrongly" (even though this isn't the same as treating "in a way consistent with their interface", as my example demonstrates - clearly it is not consistent to be able to add a string to a list of integers!). On the other hand, C specification doesn't actually preclude the implementation from doing full type checking on such casts as well. It merely says that those casts are U.B.; an implementation of C that uses fat pointers (typeid + address + bounds) can do full type and bound checking on all pointer operations to the same extent that Java does - raising well-defined errors immediately upon every operation that is declared as U.B. by the spec - and still remain conformant to the spec; so, by that definition, C can be typesafe.

    49. Re:Why not just do duck typing? by EvanED · · Score: 1

      That's not particularly difficult to fake, if you're willing to do a little maintenance.

      I'd dispute the characterization as "a little".

      If your project uses a common base class for whatever reason (not terribly out-there; e.g. Qt defines the QObject class), you could even put one implementation of callMethod in that base class and have the same interface everywhere. That's very different than "you have to update callMethod() each time you add a class."

      This has the added benefit of preventing people from calling functions on that class that you don't want them to call - using reflection, they could in theory call any member function of the class, regardless of whether it's part of your scripting API, unless you explicitly filter for it in your callMethod function.

      If your language supports annotations, you could annotate the function explicitly; this is preferable IMO because it co-locates the specification that the function should or should not be called with the function, instead of having them in different locations.

      (Okay, so maybe my argument is really that reflection + custom annotations would be a great and very useful addition. Reflection on its own I could see as rather less useful.)

      Of course, if your functions take different numbers and/or types of arguments, you might have to handle each individual function separately anyway, making the whole reflection thing moot.

      Why? You could use the reflection API to get the number and types, and do conversions based on that. I can think of a not-very-complicated way to implement this with reflection once (i.e. it would still work with my "put one callMethod() class in your base" statement above).

      Bottom line is, I don't think reflection would really add anything to the language that you couldn't fake with some ugly and/or elegant code (at least as far as your example goes).

      You can say the same thing about classes. Why should C++ have classes? After all, you can simulate classes with structs and explicit function pointers. Personally, I think the syntactic gains you get from supporting classes is around the same as the syntactic gains you'd get from real language-supported reflection over some hacked-up solution like that.

      The problem with the above is that I'm only thinking of what the difference would be with a program that uses reflection somewhat heavily. The fact that classes are used all over the place means that the gains in terms of code effort are much higher with classes. So I'm not arguing that reflection is as worthwhile as classes, just that the syntactic gains are, I think, comparable.

      Besides, that was just one example of two and a half. The second (and I think third, but don't count that) relies on enumerating the members of a class.

    50. Re:Why not just do duck typing? by HeronBlademaster · · Score: 1

      Yeah... you're probably right.

      I guess my opinion mostly comes from the "I'm not doing anything right now that could benefit from reflection, so obviously C++ doesn't really need it." That's probably not the best reason...

    51. Re:Why not just do duck typing? by EvanED · · Score: 1

      In any case, my Java example wasn't about variables at all.

      This is true; I should have said "expressions" instead of "variables".

      Technically, the only real difference is that Java guarantees that you will get an exception when you try to treat an object "wrongly" ... On the other hand, C specification doesn't actually preclude the implementation from doing full type checking on such casts as well.

      To me that's like saying "the only difference is exactly the difference you were talking about". Sure, an implementation could do such type checking, but I dare you to find me one in anywhere near common use that actually does. CCured is about the closest thing I know of.

      Practically speaking, C doesn't do said type checking, and the difference exists.

      (Put another way, Java is type-safe from this perspective. C is not type-safe even if a particular implementation is. Type safety to me means a guarantee, and since the C standard doesn't make such a guarantee, it's not type safe. Since Java's spec does make such a guarantee, it is.)

    52. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 1

      Sure, an implementation could do such type checking, but I dare you to find me one in anywhere near common use that actually does.

      For the sake of this argument, I could write one ;)

      Put another way, Java is type-safe from this perspective. C is not type-safe even if a particular implementation is. Type safety to me means a guarantee, and since the C standard doesn't make such a guarantee, it's not type safe. Since Java's spec does make such a guarantee, it is.

      In the end it all boils down to the definition of "type safe", again. This LtU post has an interesting classification, and the rest of the thread mirrors our discussion in many ways (specifically "type safety" vs "memory safety", or one being subset of another).

    53. Re:Why not just do duck typing? by jgrahn · · Score: 1

      Well, either you believe in static typing, or you don't. If you do, Java is a good choice. If you don't, Ruby is a good choice. C++, on the other hand, is static enough to be annoying, but not static enough to be safe.

      What's less static about C++ compared to Java? I don't know Java, but the only thing I can think about is the wealth of integer types in C and C++, and the conversions between them (some of which you can tell your compiler to warn you about even though they may be legit). I don't count casts (foo_cast or the less safe legacy C-style cast) because if you use them it's your fault.

      C++ also includes 'const', which adds a whole new dimension to the static checking. I really miss that in other languages.

      And come to think of it, since you can create new types for free in C++, you have /more/ opportunities to add type safety. Don't want to accidentally do arithmetic on TCP port numbers? Write a TcpPort class, with no more runtime cost than an uint16_t would have had.

    54. Re:Why not just do duck typing? by Javagator · · Score: 1

      If it looks like a duck and walks like a duck and quacks like a duck, then it must be an int or a float, or possibly a programmer defined complex number. Scripting languages are great for quickly dashing off a smallish program, but for programs running into hundreds of thousands of lines, you want strong typing. Even if the compiler can figure out what you meant, human readers may not. Trust me on this one.

    55. Re:Why not just do duck typing? by metamatic · · Score: 1

      C++ will do implicit conversions between types that Java doesn't allow.

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    56. Re:Why not just do duck typing? by Abcd1234 · · Score: 1

      Since "duck typing" is not a well-defined term, I guess we'll have to just agree to disagree.

      Well, Wikipedia seems to think it's reasonably well defined. Here's what the consensus says (obviously I'm going to abbreviate, here, but you can see it for yourself):

      In duck typing, one is concerned with just those aspects of an object that are used, rather than with the type of the object itself. For example, in a non-duck-typed language, one can create a function that takes an object of type Duck and calls that object's walk and quack methods. In a duck-typed language, the equivalent function would take an object of any type and call that object's walk and quack methods. If the object does not have the methods that are called then the function signals a run-time error. It is this action of any object having the correct walk and quack methods being accepted by the function that evokes the quotation and hence the name of this form of typing.

      Obviously, what's described above can't possibly work in a statically typed language, inferred or otherwise, as the types of the parameters for the function are well known and enforced at compile time. In fact, the definition goes on to say:

      Duck typing is aided by habitually not testing for the type of arguments in method and function bodies

      And:

      Users of statically typed languages new to dynamically typed languages are usually tempted to add such static (before run-time) type checks, defeating the benefits and flexibility of duck typing, and constraining the language's dynamism.

      Given that, I really don't see how Haskell, OCaml, or C++ (templated or otherwise) can possibly be considered "duck typed".

      It's a curious listing, but I don't really understand why you wouldn't consider the listed languages to be duck-typed even under your, stricter definition (of dynamic typing + dispatch). Or am I missing something?

      Yeah, guilty as charged. It's what I get for not taking a bit more time to assemble my list. :) I should've at least included ocaml and Haskell in that list, in order to illustrate how broad such a definition (that would include statically typed languages) would be. And C# was an even poorer choice... I assumed that they were only adding support for compile-time type inference, but apparently they'll also be adding the ability to weaken compile-time type checking while relying on the run-time to catch errors, so C# will, in fact, be getting what I think of as true "duck typing" features.

      Since a cast to anything but the original pointer type (with a few exceptions, such as char* to get raw bytes) is U.B., such casting doesn't give you a mechanism to say "do X" on an object of an uncertain type, and have it done so long as "X" is somehow supported for the object (again, with a few edge cases, such as X being "copy all bytes constituting the object")

      Sure it does. Glib and Gtk build an entire polymorphic object model based on the fact that you can a) store function pointers in a struct, and b) cast one arbitrary pointer to another. The result is that, so long as your structs are laid out properly, you can polymorphically dispatch methods on types.

      So, I suppose it's more accurate to say that C along with some sort of appropriately built library allows C to operate in a duck-typed fashion. But I maintain that, at that point, the term is meaningless.

    57. Re:Why not just do duck typing? by Anonymous Coward · · Score: 0

      Refer to Stroustrup's DDJ article.
      http://www.ddj.com/cpp/218600111

    58. Re:Why not just do duck typing? by ultranova · · Score: 1

      In Java, you can cast a List<Double> to a List<Integer>, and the cast will succeed at run-time.

      In Java, casting from one generic type to another is meaningless, since they are the same class in runtime, so I'd imagine that the cast would be eliminated by the compiler, since it's just casting List to List. That is, IMHO, the biggest problem with Java generics, and shows them to be somewhat of a hack job.

      The individual citizen has no federal constitutional right to vote for electors for the President of the United States.

      Are you promoting amending the Constitution or disempowering the people here?

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    59. Re:Why not just do duck typing? by shutdown+-p+now · · Score: 1

      In Java, casting from one generic type to another is meaningless, since they are the same class in runtime, so I'd imagine that the cast would be eliminated by the compiler, since it's just casting List to List. That is, IMHO, the biggest problem with Java generics, and shows them to be somewhat of a hack job.

      I know the underlying reason, and I agree with your assessment of it being the biggest problem with generics.

      Are you promoting amending the Constitution or disempowering the people here?

      I am merely stating a fact that many U.S. citizens tend to forget. What to do about it is up to you guys (as I'm not a U.S. citizen or even resident), though from my perspective, I'd say the more realistic way to fix this would be to ditch electoral college (and the less realistic way would be to roll back the federal/state power balance to where it was before 1861).

  4. No need to dramatize by loufoque · · Score: 4, Interesting

    I've seen a lot of people dramatize about concepts being removed from C++0x.

    Really, it's no big deal. There are alternative solutions, like some based on SFINAE -- that has now been extended to arbitrary expressions --, that provide almost the same feature set, the same quality in error messages, and are not much harder or more verbose to write or use.

    Actually, getting rid of concepts was probably the best solution for C++0x, since they were a lot of work to implement on top of not being that well polished, not integrating that well with the rest (concepts are not types, nor are they templates, they're a whole new category of things) which would probably have led to different categories of compliance to the new standard.
    This even gives a new chance to more vital features, such as polymorphic lambdas (understand lambdas were the types of the arguments is not given and which thus exhibit parametric polymorphism), to now being reconsidered.

    1. Re:No need to dramatize by EsbenMoseHansen · · Score: 0, Redundant

      While I love the concept of concepts (sorry!), I too feel that leaving them out is for the best. Let us see an implementation first... like we have for lambdas, e.g.

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    2. Re:No need to dramatize by Suiggy · · Score: 1

      Agreed. I don't understand why people are using the removal of concepts from C++0x as some sort of signal that C++ is now dead or not worth it anymore. There's a lot more to C++0x than just concepts, concepts was only one of a few dozen of new language and library features.

    3. Re:No need to dramatize by EsbenMoseHansen · · Score: 1

      Actually, it would seem that the is an implementation, a fork of gcc. Well.

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    4. Re:No need to dramatize by ioshhdflwuegfh · · Score: 1

      [concepts a]re a whole new category of things

      Combining this with a Stroustrup's claim from TFA we may conclude:
      An idea of concepts is a whole new category of things.
      :D

    5. Re:No need to dramatize by BikeHelmet · · Score: 1

      This even gives a new chance to more vital features, such as polymorphic lambdas (understand lambdas were the types of the arguments is not given and which thus exhibit parametric polymorphism), to now being reconsidered.

      Oh, you mean like in Javascript?

      function add(a, b) { return a+b; }

      add(2,3); // 5
      add("Hello ", "Bob"); // Hello Bob

      Because when building some frameworks, if you could write code like that, it'd save you a lot of lines! I'm thinking back to when I was making a 2D SDL tile engine, and in C it was easily 3-4x longer than any other language.

    6. Re:No need to dramatize by loufoque · · Score: 1

      Oh, you mean like in Javascript?

      No, I mean like in ML or Haskell.
      JavaScript does runtime duck typing, so that kind of thing is irrelevant.

  5. The feature C++ REALLY needs. by fish_in_the_c · · Score: 1, Interesting

    If any one feature could ensure the continuation of C++ as a language it would be a standardized GUI library.
    ( i know I know, platform problems, implementation , the venders oppose it).

    but when it comes right down to it. If C++ had a set of GUI libraries that were part of the standard and could be counted on to be in every compiler ( even if they didn't always look the quite the same). It would go a long way to providing something most developers need and want that can't be found in a lot of languages.

    --
    âoeTolerance applies only to persons, but never to truth. Intolerance applies only to truth, but never to persons.
    1. Re:The feature C++ REALLY needs. by Desler · · Score: 1

      but when it comes right down to it. If C++ had a set of GUI libraries that were part of the standard and could be counted on to be in every compiler ( even if they didn't always look the quite the same). It would go a long way to providing something most developers need and want that can't be found in a lot of languages.

      What developers are out their complaining about C++ not having language native GUI libraries? Secondly, unless this would be done in the way Qt does it currently by using the native rendering engine of the platform, this is just a waste of time. What the world doesn't need is a bunch of C++ programs that are written that look alien on every platform it runs on like Java Apps do (yes Java 6 fixes this in quite a few ways but they still don't look entirely like native apps).

    2. Re:The feature C++ REALLY needs. by TheRealMindChild · · Score: 0, Troll

      If C++ had a set of GUI libraries that were part of the standard and could be counted on to be in every compiler...

      Hate to bust your bubble there sonny, but the new C++ specification has ALL SORTS of crap that won't translate to a lot of platforms. For instance, multithreading will be built into the language... but what about something like DOS where there is no threads? Or something that uses bazaar threading mechanisms like protothreads/contiki?

      --

      "When life gives you lemons, don't make lemonade. Make life take the lemons back!" -- Cave Johnson
    3. Re:The feature C++ REALLY needs. by betterunixthanunix · · Score: 2, Insightful

      The main reason for not making GUI part of the standard is that there are already plenty of GUI libraries for C++, and nobody on the standards committee will be able to agree on which one should be used. This is in contrast with, say, file-based IO, which is implemented in roughly the same way on all platforms.

      There are plenty of features that I would say are a lot more important than a GUI framework. A standard way to convert C style FILE pointers into an iostream would be a great feature, one that several vendors already implement as extensions. Even a standard way to open a network connection and represent it as an iostream would be a good thing to have, with the heavy focus on network applications these days. Also, move allocators out of the template argument list for containers, and representing them as class members instead -- if ever there was a perfect case for preferring composition, it is this. Also, improved i18n/l10n support (C++ is better than C in this regard, but there is a lot that remains to be done).

      --
      Palm trees and 8
    4. Re:The feature C++ REALLY needs. by Desler · · Score: 1

      but what about something like DOS where there is no threads?

      I think the bigger obstacle would be the lack of a compiler for C++0x for DOS. Until you get over that bigger hump first, your question is moot.

    5. Re:The feature C++ REALLY needs. by TheRealMindChild · · Score: 1

      That is sort of the point... you now CAN'T have a compliant C++0x compiler for DOS... or anything else that doesn't mesh with these new "additions"

      --

      "When life gives you lemons, don't make lemonade. Make life take the lemons back!" -- Cave Johnson
    6. Re:The feature C++ REALLY needs. by betterunixthanunix · · Score: 1

      You might as well have made the same argument about a standardize iostreams library -- after all, what about platforms that use record based IO?

      Nothing will work on 100% of platforms. For platforms that have no multithreading support, the code should just enter an error state (or throw an exception) if an attempt to spawn a new thread is made. For platforms that have unusual thread models...too bad, find a way to make those models fit into what the C++ standard calls for, or just don't support that particular feature and throw an exception when a program tries to use it. The C++ standard is meant to work for the general case, and the general case is neither DOS nor protothreads.

      --
      Palm trees and 8
    7. Re:The feature C++ REALLY needs. by Anonymous Coward · · Score: 0

      Sure you could. The complexity would be greater though as you'd have to create (and maintain) a runtime environment along with that compiler in order to support stuff like threading. My guess is that there would simply not be enough demand for DOS support to justify the effort required. Anyone doing anything is DOS these days is likely to be doing embedded work, and the vast majority of people who have moved beyond the limits of what DOS can do have already moved to Linux or some proprietary platform or other.

    8. Re:The feature C++ REALLY needs. by Anonymous Coward · · Score: 0

      >bazaar threading mechanisms

      do you buy them at the souk?

      or would that be too bizarre?

    9. Re:The feature C++ REALLY needs. by superdana · · Score: 0

      If any one feature could ensure the continuation of C++ as a language

      I see what you did there.

    10. Re:The feature C++ REALLY needs. by Desler · · Score: 1

      That is sort of the point... you now CAN'T have a compliant C++0x compiler for DOS...

      IT doesn't really matter since no one is going to create one anyway. Your entire scenario is completely moot.

    11. Re:The feature C++ REALLY needs. by MikeBabcock · · Score: 5, Insightful

      What on earth does a GUI have to do with a language? A GUI belongs in the C++ specification about as much as Java belongs in the kernel.

      Each has its place and is used when necessary and shouldn't be forced into a place it doesn't belong for convenience.

      --
      - Michael T. Babcock (Yes, I blog)
    12. Re:The feature C++ REALLY needs. by Anonymous Coward · · Score: 2, Informative

      Qt 4.5 has been released LGPL. As long as you link to the Qt's dynamic libraries, you can completely close the rest of your app. Qt has become the standard cross-platform GUI framework for C++.

    13. Re:The feature C++ REALLY needs. by gnud · · Score: 1

      Well, any c++0x runtime library for DOS would now have to do its own threads. Not impossible - but it makes it less likely any DOS c++0x compiler will emerge.

    14. Re:The feature C++ REALLY needs. by thetoadwarrior · · Score: 1

      Java looks close enough these days and, to be honest, I don't think people should be that bother about making boring GUIs that are 100% identical to all other GUIs.

      Plus, if people wanted that then themes for various programs (and the OS itself) wouldn't be so popular.

    15. Re:The feature C++ REALLY needs. by Fujisawa+Sensei · · Score: 1

      If C++ had a set of GUI libraries that were part of the standard and could be counted on to be in every compiler... Hate to bust your bubble there sonny, but the new C++ specification has ALL SORTS of crap that won't translate to a lot of platforms. For instance, multithreading will be built into the language... but what about something like DOS where there is no threads? Or something that uses bazaar threading mechanisms like protothreads/contiki?

      What about the Altair 8800? We have to make sure the new C++ spec supports it too!

      --
      If someone is passing you on the right, you are an asshole for driving in the wrong lane.
    16. Re:The feature C++ REALLY needs. by thetoadwarrior · · Score: 1

      OH NOES, there goes my new DOS project.

    17. Re:The feature C++ REALLY needs. by tepples · · Score: 1

      You might as well have made the same argument about a standardize iostreams library -- after all, what about platforms that use record based IO?

      Each line of a text file is a record. In most popular operating systems for workstations and servers, the record separator '\n' becomes a fixed sequence of bytes when it is written to a text file (e.g. {0x0D, 0x0A} on Windows or {0x0A} on *Linux, *BSD, or Mac OS X or {0x0D} on ProDOS or classic Mac OS). In others, each record starts with a length in bytes (e.g. non-stream text files in VMS or STR# resources in classic Mac OS). Or are you talking about systems where all records of all files are fixed-length?

    18. Re:The feature C++ REALLY needs. by Palshife · · Score: 1

      Your DOS C++ runtime would need to support threads. I imagine you'd have to write a scheduler that ran them sequentially rather than concurrently. Your performance wouldn't be as good as it would be on a multitasking OS, but that's sort of the point.

      At any rate, it doesn't mean that you can't implement the language, it just means that the language can't teach your OS new tricks.

      --
      Attention deficit disorder is a complicated issue, spanning several major... HEY LET'S GO RIDE BIKES!
    19. Re:The feature C++ REALLY needs. by GooberToo · · Score: 1

      but what about something like DOS where there is no threads?

      Hate to burst your bubble, but threads can be supported on DOS. I've even created thread implementations on DOS. Now then, exactly how threads workand their exact implementation details may or may not come as a surprise, but threads can be implemented on DOS.

    20. Re:The feature C++ REALLY needs. by Trepidity · · Score: 1

      There's a trend towards language platforms, rather than merely languages, which has some pros and cons. I do think that, for example, it'd be nice if C++ had network sockets in the standard library. Yes, it's strictly speaking an OS feature, but it's close enough to standardized that you can provide a portable abstraction layer in the standard library, which would simplify a lot of things. I agree, though, that a GUI is probably not really in that category.

    21. Re:The feature C++ REALLY needs. by mwvdlee · · Score: 1

      DOS supports threads, it's just limited to 1.

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    22. Re:The feature C++ REALLY needs. by mwvdlee · · Score: 1

      What about binary files?
      CR/LF doesn't separate binary file records on Win/*nix/OSX.
      z/OS does have records in binary files though.

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    23. Re:The feature C++ REALLY needs. by pnewhook · · Score: 1

      If any one feature could ensure the continuation of C++ as a language it would be a standardized GUI library.

      That would be OpenGL..

      --
      Tesla was a genius. Edison however was a overrated hack who liked to torture puppies.
    24. Re:The feature C++ REALLY needs. by pnewhook · · Score: 1

      Then they should have released it under BSD.

      --
      Tesla was a genius. Edison however was a overrated hack who liked to torture puppies.
    25. Re:The feature C++ REALLY needs. by fish_in_the_c · · Score: 1

      Sure you can. Just because you have a standard library doesn't mean the every standard library has to be useable in every platform. Do you think the standard Java 3D graphics libraries run on a smart cards? Any graphical calls compile down to noops in that kind of environment. You still have to test your app in any environment you want to be sure it works on. And you can't expect things to work that aren't supported in the O/S. That doesn't mean you can't compile just that you are going to throw compiler warnings and the functions you are trying to use won't be there, but there is no way around that.

      --
      âoeTolerance applies only to persons, but never to truth. Intolerance applies only to truth, but never to persons.
    26. Re:The feature C++ REALLY needs. by Juiblex · · Score: 1

      No modern language has this... why would you want a "standard" or "endorsed" GUI library when you're free to use Qt, wx, GTK, Microsoft MFC, etc...?

    27. Re:The feature C++ REALLY needs. by fish_in_the_c · · Score: 1

      I guess part of the point is that as a smart developer you can't expect code that requires a specific feature to work in an environment where it doesn't make sense. It is 'good enough' for it to work in every situation where it does make sense. The more places you can get your code to run on with little or no work , the more valuable your code is. Language choice is really all about return on investment(aka fastest, easiest, clearest) and something like this could make a decent percentage of the reasons for projects done only partially in C++ or not done in C++ go away.

      --
      âoeTolerance applies only to persons, but never to truth. Intolerance applies only to truth, but never to persons.
    28. Re:The feature C++ REALLY needs. by StackedCrooked · · Score: 2, Informative

      He means adding a GUI to the STL, not the C++ language.

    29. Re:The feature C++ REALLY needs. by Bill,+Shooter+of+Bul · · Score: 1

      Eh, depends on the word "Modern". Java has swing, Classic Visual Basic, Visual Fox Pro, and countless other wonderful "modern" languages have had "world Class" Gui libraries. Which is why we all love them and they are our first choice to use when ever possible. *Cough* , *cough*

      --
      Well.. maybe. Or Maybe not. But Definitely not sort of.
    30. Re:The feature C++ REALLY needs. by shish · · Score: 1

      What on earth does a GUI have to do with a language?

      What on earth does reading and writing files have to do with a language?

      While they are separate things, a language with no APIs is useless; and a language which uses different APIs on each platform, while useful, is a still much more of a pain in the ass than one which gives you a ton of functionality on every platform as standard.

      --
      I mod down anyone who says "I will be modded down for this", regardless of the rest of their comment
    31. Re:The feature C++ REALLY needs. by maxwell+demon · · Score: 1

      Couldn't the C++ library for DOS simply indicate failure whenever the creation of a second thread is attempted?

      --
      The Tao of math: The numbers you can count are not the real numbers.
    32. Re:The feature C++ REALLY needs. by bonch · · Score: 1

      "OH NOES"

      Go back to 4chan and leave the discussion to the adults.

    33. Re:The feature C++ REALLY needs. by Anonymous Coward · · Score: 0

      GCC 4.4.1 is available for DOS. I don't see any reason to assume that a C++0x-supporting version wouldn't be, once it exists at all, if the lack of threads wouldn't be a fatal obstacle.

    34. Re:The feature C++ REALLY needs. by ADRA · · Score: 1

      hmmm.. kernel byte-code instrumentation... sounds neat. The exposed JVM interfaces are similar to kernel API's anyways. I don't think the jump wouldn't be as crazy as you'd expect. Although, the magic of bootstrapping classpaths, sysproperties, etc.. would need a wild paradigm shift.

      [ /home/myhome ] # ls -l * /home/myhome/system.jar
      [ / ] # cd system.jar/com/command
      [ /home/myhome/system.jar/com/myprogram ] # ls -l * /home/myhome/system.jar/com/myprogram/Cat /home/myhome/system.jar/com/myprogram/Grep
      [ /home/myhome/com/myprogram ] # ./Cat file:///tmp/ThisIs.txt | ./Grep "ScarryHuh?"

      or just
      [ /home/myhome ] # export "PATH=/home/myhome/system.jar/com/myprogram:${PATH}"
      [ /home/myhome ] # Cat file:///tmp/ThisIs.txt | Grep "ScarryHuh?"

      --
      Bye!
    35. Re:The feature C++ REALLY needs. by thetoadwarrior · · Score: 1

      If you want to be treated as an adult having an adult conversation then you shouldn't use such a dumb argument like DOS support. There was a reason people modded you a troll.

    36. Re:The feature C++ REALLY needs. by Anonymous Coward · · Score: 0

      That is sort of the point... you now CAN'T have a compliant C++0x compiler for DOS... or anything else that doesn't mesh with these new "additions"

      In case anyone still cares...

      There were DOS Ada compilers with full support for tasking, Ada's language-level multi-threading/processing feature. On platforms which don't support multi-threading (or even multi-processing in the case of MS-DOS) it's the Ada implementation's responsibility to provide a work-alike. So, there's no reason the same couldn't be done for C++0x. There has already been vigorous commenting on whether that is likely or worthwhile...

      - T

  6. C+++=1 by Anonymous Coward · · Score: 0

    Stupid name, it should be

    C+++=1
    or is equiv
    C+=2

    C++0X is a syntax error!

    1. Re:C+++=1 by Tetsujin · · Score: 2, Funny

      Stupid name, it should be

      C+++=1
      or is equiv
      C+=2

      C++0X is a syntax error!

      Actually, the two forms aren't equivalent.

      I mean, I was pretty annoyed when they said, "Hey, here's C++! We added that increment operator to show you that we made C better!" But, then, wouldn't you know it... Yeah, they made a better C, but what they actually gave to us was the same old C, as it was before they improved it. Later on I kept checking back to see if C++ really was substantially different from plain old C: and it was, but each time I looked at C++, the result was something different from what I'd seen before!

      (C+++=1 simply wouldn't work, as C++ is an rvalue. Suppose D=C. Now, D == C++. But then, D != C++. And for that matter, C++ != C++. It's maddening, I tell you! And I don't think C+=2 is equal to anything at all...)

      --
      Bow-ties are cool.
    2. Re:C+++=1 by logixoul · · Score: 1

      Ugh. If I got a cent everytime people misunderstand rvalues...

      The following is valid code.
      struct A { A operator++(int) {return A();} A operator+=(int) {return A();} }; int main() { A C; C+++=1; }

    3. Re:C+++=1 by Tetsujin · · Score: 1

      Ah, OK, yeah, it is valid to use post-increment to increment something, return a copy of the old value, and then increment that, and throw it away...

      Point taken - code's not invalid as such, just fairly pointless as it does nothing. (Unless, of course, the operators are defined with side-effects... in which case it does something but it's probably a bad design...)

      --
      Bow-ties are cool.
  7. Uncluttered article (print = easy to read) by noidentity · · Score: 4, Informative

    Uncluttered article, without any extra crap and multiple pages. Printable = readable.

    1. Re:Uncluttered article (print = easy to read) by Anonymous Coward · · Score: 0

      Or just install AutoPager (what you aren't using FireFox?) (though finding the print version is a good one too)

    2. Re:Uncluttered article (print = easy to read) by noidentity · · Score: 1

      Or just install AutoPager (what you aren't using FireFox?)

      It won't run on the platform I'm using. And no, I'm not going to switch platforms simply so I can run Firefox (unless you'd like to give me several thousand dollars to replace all my equipment with some modern stuff).

  8. Re:Maybe the vendors don't want C++... by beuges · · Score: 3, Informative

    Do you realise that most of the guts of Windows is actually written in C++? And that the secretary of the C++ Standards Committe, Herb Sutter, works for Microsoft?
    Are you even a C++ developer at all?

  9. Re:Maybe the vendors don't want C++... by Desler · · Score: 2, Interesting

    I would be willing to bet that some vendors that make more than one language are probably not too crazy about doing more with an open language like C++. Not that I would make any association with a large software vendor founded in the 1970s that leveraged a pretty good BASIC interpreter into operating system and tools dominance... but

    Yeah, Microsoft is so uninterested in C++ that for the Visual C++ 2010 release that they've added in a whole bunch of new features including partial support for this new standard.

  10. Re:Maybe the vendors don't want C++... by Desler · · Score: 1

    Oh, and that's not even getting to the fact that Microsoft still uses C++ extensively throughout it's products. Yes, clearly that is a sign of a company that isn't crazy about C++ anymore.

  11. Dynamic allocation and data types. by Eravnrekaree · · Score: 1

    I believe some features that might help C++ is automatic memory allocation (where objects are automatically resized and freed when they go out of scope), and dynamic types (which automatically convert according to some rules based on the context they are used in), basically to give it the same effects as Ruby. This would be optional and avialable alongside present manual systems. It would be an interesting concept rather than just hardcoding this, instead allow it to be implemented on top of some API, sort of the tie() interface on Perl, that whenever an object goes out of scope or something is stored into it, a callback is triggered where a plugin can handle the desired features. This would allow greater flexibility. These objects would be aware of the data type of the data stored in them, like ASCII or binary integer. If it were used in an arithmatic operation, a certain callback could be triggered provided by the objects controller object, which could convert the value from ASCII into binary required by arithmatic operator. Perhaps even a seperate set of string operators should be considered as well.

    1. Re:Dynamic allocation and data types. by Desler · · Score: 1

      I believe some features that might help C++ is automatic memory allocation (where objects are automatically resized and freed when they go out of scope),

      The future 10 years ago!

    2. Re:Dynamic allocation and data types. by Tony+Hoyle · · Score: 1

      I believe some features that might help C++ is automatic memory allocation (where objects are automatically resized and freed when they go out of scope

      Even C had that.

      You mean smart pointers? About 10 minutes work to implement... and anyone who's used C++ probably has one in their arsenal somewhere.. not that I'd want them except where they can do some good.. too much overhead for general use.

      C had typing rules too. So does C++.

      henever an object goes out of scope or something is stored into it, a callback is triggered where a plugin can handle the desired features

      Google for 'destructors'.

    3. Re:Dynamic allocation and data types. by Tetsujin · · Score: 1

      I believe some features that might help C++ is automatic memory allocation (where objects are automatically resized and freed when they go out of scope

      Even C had that.

      You mean smart pointers? About 10 minutes work to implement...

      Well, until it's time to do it right... If, for instance, you need to be sure that the assignment operators will allow assignment from compatible types, but not from incompatible types (admittedly, various compiler bugs complicate this) - or provide thread safety, things like that.

      --
      Bow-ties are cool.
  12. Concepts aren't enough! by Stuntmonkey · · Score: 5, Funny

    Can't we just skip "concepts", and move straightaway to "meta-concepts"? After all, a "concept" is just a concept itself, so with meta-concepts we'll be able to define "concepts" recursively. Which doesn't sound like a win, until you realize then you can redefine concepts to fit your own idiosyncratic needs. Like how in my code, the first thing I always do is overload "+" to mean "*", and vice versa. I've always liked them the other way around, not sure why. Anyway, back on point: Concepts by itself is like the 4-blade razor, a lame, stupid half-measure. The real prize, the 360-dunk-off-the-free-throw-line, is 5 blades on a razor. I move we skip "concepts" and go for the big win. Those effeminate Python dorks will have no answer to this, they'll be stunned to see just how inferior they really are. Who's with me on this?

    Broader point: I'm sick and tired of these language designers not giving us enough features. For the last 20 years I've been waiting for a language that will allow me to redefine keywords. If that too much to ask? What if I don't happen to like "for", or "while", or "return"? Do you people lack vision, or competence, or both? Second thing on my must-have list is a pre-pre-processor. I'm tired of writing all these header files all the time. I want a way to generate them programmatically, at compile time. A small embedded scripting language would do fine, just make sure it has templates and operator overloading and multiple inheritance, so I can stretch my legs and get comfy with it. Come on people, start earning your paychecks and get some of this stuff done!

    1. Re:Concepts aren't enough! by shutdown+-p+now · · Score: 4, Insightful

      All that you want exists already, no need to wait 20 years - in fact, it was there already when you've started waiting! It's called Common Lisp.

      It's the only language I know of where you can use its macro facility (reader macros, to be specific) to fully implement another language with arbitrary complex syntax. In other words, a program written in any textual language can be a Common Lisp program if you insert a corresponding CL reader macro definition at the beginning of the code.

      Come to think of it, maybe the fact that it hasn't taken over the world yet has something to do with that...

    2. Re:Concepts aren't enough! by cptdondo · · Score: 2, Informative

      Broader point: I'm sick and tired of these language designers not giving us enough features. For the last 20 years I've been waiting for a language that will allow me to redefine keywords. If that too much to ask? What if I don't happen to like "for", or "while", or "return"?

      Unless my memory fails me, SNOBOL4 could do this 30 years ago.

    3. Re:Concepts aren't enough! by Timothy+Brownawell · · Score: 1

      Second thing on my must-have list is a pre-pre-processor. I'm tired of writing all these header files all the time. I want a way to generate them programmatically, at compile time.

      That would actually be kinda cool. Have something that will take your file and pull out function declarations, pull out the public parts of your class definitions, and rewrite your classes to use the pimpl idiom to hide the private parts properly. It'd also be good to have it get rid of slicing problems, but first you'd have to be able to overload the "." operator and determine the base classes of your template parameters.

    4. Re:Concepts aren't enough! by Anonymous Coward · · Score: 1, Funny

      Pfft, you lack vision. We need a meta-language, where you program what you want programmed.

    5. Re:Concepts aren't enough! by Anonymous Coward · · Score: 0

      You really are a fucking moron, aren't you? First of all, you can't redefine operators for existing types. Second, if you purposely define your operators to mean something completely backwards from what your users expect, why is that the language's fault? I really hate you kiddie programmers and your idiotic logic: I can misuse feature X, so X must be bad and any language that can do X is bad.

    6. Re:Concepts aren't enough! by Anonymous Coward · · Score: 0

      Renaming keywords is just an opportunity for obfuscation. *Everyone* knows what 'if' means in C++ programs. If you rename it 'when', and someone else sees your code 'when (x == 1)', is that obvious it's a renamed if? Could it be a renamed 'while'? It just creates ambiguity, so I think it would be a really, really bad idea.

    7. Re:Concepts aren't enough! by Icegryphon · · Score: 1

      This has to be one of the most wonderfully funny posts I have read.
      You Sir are a Genius if you know it or not.

    8. Re:Concepts aren't enough! by Anonymous Coward · · Score: 0

      Perl can do this, too, using source filters. ;)

    9. Re:Concepts aren't enough! by Anonymous Coward · · Score: 0

      We need a meta-language, where you program what you want programmed.

      It's called Indian English. Unfortunately, most existing implementations are defective to various degrees.

    10. Re:Concepts aren't enough! by Anonymous Coward · · Score: 1, Funny

      For the last 20 years I've been waiting for a language that will allow me to redefine keywords.

      C and C++ have supported this forever, for example:

      #define if while

      Kiss my ass Python lusers!

    11. Re:Concepts aren't enough! by Anonymous Coward · · Score: 0

      Disclaimer: I only read the first two sentences.
        Click here and look for the word "axiom". :)

    12. Re:Concepts aren't enough! by BikeHelmet · · Score: 1

      Broader point: I'm sick and tired of these language designers not giving us enough features. For the last 20 years I've been waiting for a language that will allow me to redefine keywords. If that too much to ask? What if I don't happen to like "for", or "while", or "return"? Do you people lack vision, or competence, or both? Second thing on my must-have list is a pre-pre-processor. I'm tired of writing all these header files all the time. I want a way to generate them programmatically, at compile time. A small embedded scripting language would do fine, just make sure it has templates and operator overloading and multiple inheritance, so I can stretch my legs and get comfy with it. Come on people, start earning your paychecks and get some of this stuff done!

      Oh man. You just outlined some of what I fleshed out for my "ideal language". Years ago I was talking with a bunch of other programmers, and rambling about what I'd like, and concluded that I wanted many of the things you just listed. Why? Well for one thing, I prefer Java keywords to C keywords. I also find the pre-processors in every single language abysmally weak, and templates require far too much syntax to be a big time saver.

    13. Re:Concepts aren't enough! by ShakaUVM · · Score: 1

      >>Second thing on my must-have list is a pre-pre-processor.

      I know you're joking, but have you ever looked at M4? It's a pre-pre-processor. We used to use them to generate arrays of N dimensions, where N could be defined at compile time. Most C programmers just define a single dimension array and then index into it with a function, but we actually generated code (nested for loops and everything) to arbitrary dimension with M4.

    14. Re:Concepts aren't enough! by Jamie+Lokier · · Score: 1

      [LIsp] is the only language I know of where you can use its macro facility (reader macros, to be specific) to fully implement another language with arbitrary complex syntax. In other words, a program written in any textual language can be a Common Lisp program if you insert a corresponding CL reader macro definition at the beginning of the code.

      Perl can do it too.

    15. Re:Concepts aren't enough! by ultranova · · Score: 1

      For the last 20 years I've been waiting for a language that will allow me to redefine keywords. If that too much to ask? What if I don't happen to like "for", or "while", or "return"?

      More importantly, these redefinitions should be context-sensitive. For example, it should be possible to define an "if" block that follows a "while" block to increment a variable before it's executed, or perhaps before the "true" block is executed. Similarly, it should be possible to have a function or any functions call another function the first thing it does if it is/they are executed from a "while" loop but not otherwise, without having to code it to every function separately.

      Second thing on my must-have list is a pre-pre-processor. I'm tired of writing all these header files all the time. I want a way to generate them programmatically, at compile time. A small embedded scripting language would do fine, just make sure it has templates and operator overloading and multiple inheritance, so I can stretch my legs and get comfy with it.

      But what happens when you want to generate these scripts automatically? No, let's do it right: The pre-processor processes its input, and if the resulting output differs from input, it re-evokes itself as its output as input to the new run, continuing until a stable state is reached.

      I'm not sure that the pre-compiler should be separate from the compiler itself, thought. What happens if I want my include files to have hand-coded assembly routines for generating the files for the next generation of compilation? For that matter, the compiler should have a virtual file system for temporary mid-compile files, threading support, a built-in SQL database engine with option of using third-party backends, OpenGL support with built-in widgets for making attractive progress screens and virtual reality configuration utilities, and network support for use with distributed or cloud compile farms.

      And while we're at it, let's add sound and joystick support so I can have my include files represent me with Doom with the source code acting as input to a level generator. That's visual debugging done the right way, and gives a whole new meaning to fighting bugs!

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  13. Re:Maybe the vendors don't want C++... by goose-incarnated · · Score: 2, Insightful

    as it is, I think C++ is pretty much dead as it is, and its' probably going to have to be up to gcc to just grab the bull by the horns and implement new features by fiat and create a defacto standard.

    Well, that's how it used to be - the standards committee generally checks what all the major implementations implement that isn't specified by the standard, and then try to get the common non-standard parts into the next standard. Basically - see what the industry is doing, and if they all seem to agree then standardise it.

    --
    I'm a minority race. Save your vitriol for white people.
  14. Re:Maybe the vendors don't want C++... by godrik · · Score: 4, Insightful

    C++ is far from dead in all piece of code that need performances. Intel released a C++ library called TBB to use multi-core architecture a few years ago. They do not believe it is dead. Parallel programming framework such as cilk stoped using C to use C++ to gain templates.

    Don't get me wrong, for most task people don't care about the performance provided by a low level language and thus don't need it. It is even harmful to use C++ if you are not going to do it properly.

  15. fnord (snippets) by Timothy+Brownawell · · Score: 1

    Which conclusions do you draw, if any, from the failure of concepts? How do you feel about this whole affair?

    You mean from the decision not to ship concepts more or less as is for C++0x? I am not of the opinion that concepts have failed. My position was that we needed only a few weeks to "fix" what in my opinion were serious usability problems. Obviously, a majority of the committee didn't agree with that timescale. [...] Things could have been much worse. In particular, we could have made the seriously flawed "concepts" part of the standard.

    The specification of concepts has taken seven years. By contrast, the standardization of the entire STL took about half that time. What is so complicated about concepts?

    I count the concepts work as started in 2002; I presented my first design papers in 2003. In 1994 Alex Stepanov presented a complete implementation of the STL to Andrew Koenig and me, but 2002-to-2009 and 1994-to-1998 are not comparable time lines. Alex had been working on the STL from at least 1976.

    So perhaps the conclusion is that concepts were doomed to fail because they try to fix so many things at once, by transforming C++ into an almost new language? After all, the whole notion of templates is a bit problematic in C++â"what the programmer writes or reads is quite different from the actual (unseen) code that the compiler generates and parses when it processes a template instance.

    No. I don't think that concepts were doomed to fail. Also, I don't think concepts were trying to fix many things or to transform C++ into an almost new language. [...] I do not think that templates are "a bit problematic." For starters, they are not macros. Programmers should no more worry about the transformations a compiler performs on template code to produce executable code than they do about the transformations compilers do for non-template code to produce executable code

    In March 2009, several months after the acceptance of Concepts into the WD, Howard Hinnant was the first to ask: "What is the risk in requiring Joe Coder to be concept-aware? What is the benefit?" It's surprising that these questions hadn't arisen much earlier during the design process. Doesn't that indicate the committee should have more checks and balances, especially when it comes to adding a new feature that is as pervasive as concepts?

    I suspect some members of the committee will seriously resent those questions and consider them proof of ignorance or ill will. [...] The committee operates according to ISO rules. Those are quite ponderous and biased in favor of not upsetting status quo. [...] I don't think we need more formal "checks and balances." If anything, the balance may have tilted too far toward caution for the long-term good of the language.

    However, the committee has no similar "field research lab" for core language features. Consequently, pervasive core language features might be incorporated into the WD without sufficient experience and testing. That's what happened with concepts I believe. Would a "staging core C++" organization be feasible and useful?

    You are wrong in your characterization of what happened to concepts. In that case, we did have a "staging lab." It was conceptGCC, the people working on concepts (mostly at Indiana and Texas A&M universities), and the people trying to use concepts in libraries (many from Boost).

    know I'm going to get a lot of flak for this but I'm starting to sense a Concepts déjà vu with rvalue references. Initially, rvalue references were meant to be transparent for most users but that's no longer the case. Joe Coder will probably have to know what a move constructor is; that function overloading rules have changed;

    I object to the "Joe Coder" moniker. At best, it is patronizing. Realistically we are all "Joe Coder" outside our little comfort zones.

    It's no secret that I've never been fond of concepts. However, I can understand and perh

    1. Re:fnord (snippets) by ioshhdflwuegfh · · Score: 1

      What's up with the quote?

    2. Re:fnord (snippets) by Timothy+Brownawell · · Score: 1

      A few bits from the "article" that seemed interesting, like the interviewer was being a bit of an ass. Approximately every other paragraph is supposed to be italicized, and in fact does have the <i></i> tags, but that somehow doesn't seem to be showing up.

  16. Re:Maybe the vendors don't want C++... by Suiggy · · Score: 2, Informative

    And let's not forget Intel C++. Intel hates C++0x so much that they decided to add the following C++0x features in Intel C++ 11.0 which has been available since November 2008: - Empty macro arguments - Variadic macros - Type long long - Trailing comma in enum definition - Concatenation of mixed-width string literals - Extended friend declarations - Use of ">>" to close two template argument lists - Relaxed rules for use of "typename" - Relaxed rules for disambiguation using the "template" keyword - Copy constructor does not need to be callable on direct reference - Binding to class rvalue - "extern template" to suppress instantiation of an entity - "auto" type specifier - decltype operator - static_assert - compliant __func__ - lambda expressions

  17. Concepts and design by contract by afidel · · Score: 1

    Is there some reason that they couldn't have taken some of the work from Eiffel on design by contract and used it for C++0x? Eiffel already compiles to C on its way to object code so I would assume that all of the Eiffel framework stuff could be made to work in C++. Once you've programmed in a design by contract language you really miss it because almost all of the stupid class of bugs go away because they get flagged at compile time.

    --
    There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
  18. Re:Maybe the vendors don't want C++... by oldhack · · Score: 1

    Yeah, legacy is a bitch.

    --
    Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
  19. C++0x0A by jDeepbeep · · Score: 2, Funny

    and we'll all be calling it C++10.

    I, for one, will be calling it C++0x0A.

    --
    Reply to That ||
    1. Re:C++0x0A by BuR4N · · Score: 1

      Heretic !!

      Its C++012 !!

      --
      http://www.intellipool.se/ - Intellipool Network Monitor
    2. Re:C++0x0A by maxwell+demon · · Score: 1

      What about 0xC++?

      --
      The Tao of math: The numbers you can count are not the real numbers.
  20. Re:BIG need to dramatize by rockmuelle · · Score: 5, Interesting

    It is a big deal. The two most important things concepts were going to do was make generic programming in C++ (1) explicit and (2) accessible.

    Currently, generic programming in C++ is supported through a number of template meta-programming patterns and practices, most of which exist as Boost tribal knowledge - hail King Dave!* It is implicit in many library designs, but there is nothing enforcing it at the language level. If you're not familiar with the concepts of generic programming (pun intended), it's easy to mistake what's going on in the standard libraries as something else. This is especially true if your primary use of the STL is to have polymorphic container classes - you might just design a generic extension to another language that completely misses the point of generic programming (see Java Generics).

    At a more fundamental level, a lot of the power in generic programming comes from the specializations that are possible when you meet type requirements. Right now, there is no way, outside the documentation, to state requirements and possible specializations. Making this explicit in the language makes it clear to the library user what the requirements are and what specializations are available.

    This leads into the accessibility problem. Generic Programming using template meta-programming is difficult. To use it, you have to understand both the template system and generic programming. The former is defined in the standard, but the latter, as mentioned above, is tribal knowledge. By making generic programming explicit in the language, it immediately becomes accessible to a large number of developers who didn't have the time, patience, or fortitude (dealing with the Boost mailing list requires a large supply of this) to become proficient with template-based generic programming.

    As an analogy: consider object-oriented programming in C. Prior to (and even after) C++, lots of OO code was been developed in C. But, each object system was different and based on local best-practices. C++ (and Objective-C) took those practices and codified them into a language extension. As soon as that occurred, one method for OO was standardized. Developers no longer had to implement their own object systems and adhere to documented (but not language enforced) policies. And, with a standard set of rules around this flavor of OO, many other developers felt comfortable jumping in the the fray.

    Concepts in C++ should have had the same effect for Generic Programming in C++ that C++ had for Object Oriented Programming in C. The should have democratized generic programming and brought forth a renaissance in C++ library design. Instead, petty politics killed the most exciting change to C-like languages in years.

    -Chris

    *(Dave - I mean that in the nicest sense... you've done a great job with Boost (oh, we need to jam again, too)).

  21. Re:Maybe the vendors don't want C++... by Anonymous Coward · · Score: 0

    They wouldn't be continuing to actively develop Visual C++ and implement new C++0x features if they were going to drop C++.

  22. Runtime vs. compile-time checking by tepples · · Score: 4, Informative

    The main difference that springs to mind is that duck typing in Python is dynamic (resolved at runtime), where-as the type system in C++ is static (resolved at compile-time).

    Compile-time checking has two purposes: enforce contracts between methods and allow for optimization. I'll cover each of these in turn:

    Dynamic languages have more overhead to dispatch a method call. But then static languages have to duplicate the template code for each type that it handles. It is disputed whether the more direct dispatch outweighs the overhead of loading the duplicated instructions into the CPU's instruction cache.

    Types of arguments to methods make up part of a contract between a method and methods that call it. It's good to have a compiler that can verify some of a contract at compile time, but the halting problem implies that not all parts of all contracts can be expressed in a way that can a machine can verify. Fans of dynamic languages claim that purpose-written unit tests can verify contracts more thoroughly than a compiler's built-in checking, but fans of static languages claim that properly done static typing writes half the unit test for you.

    1. Re:Runtime vs. compile-time checking by EvanED · · Score: 4, Informative

      It is disputed whether the more direct dispatch outweighs the overhead of loading the duplicated instructions into the CPU's instruction cache.

      Keep in mind that if you can statically determine what function is going to be called, you can potentially inline it. This is important for the stereotypical object-oriented designs where you have a lot of small functions (like getters and setters). This eliminates not just the function call overhead entirely, but will often enable other optimizations. (Of course, virtual functions make determining the function to be called hard or impossible in many cases.)

      So it's not just the increased call overhead that dynamic languages have to deal with, it's the lack of ability to perform a bunch of other optimizations as well. Given C++ templates vs. a true interpreted language, I would wager C++ templates would win virtually every time, I-cache pressure and all.

      However, not all is lost; JIT compilers start introducing a lot of the benefits from static typing back into the dynamic context once it decides to for-real compile part of the code. Once it does that, dynamic languages can pick up most of the benefits of the static language. (And my understanding is sometimes more, because the JIT compiler has some dynamic information while the static compiler has to make safe assumptions.) Of course, not all languages have true JIT compilers (e.g. Python (specifically CPython, the typical implementation) is bytecode-interpreted with no JIT compiler).

    2. Re:Runtime vs. compile-time checking by oldhack · · Score: 1

      As you noted, static type checking is a half measure for enforcing contract. I suppose the pluses and minuses of that can be argued until the cows come home.

      --
      Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
    3. Re:Runtime vs. compile-time checking by tepples · · Score: 1

      (Of course, virtual functions make determining the function to be called hard or impossible in many cases.)

      obj.method() has three steps:

      1. Look up obj's __vtable field.
      2. Look up method's entry point in __vtable.
      3. Call method.

      In a typical C++ implementation, __vtable is an array, and each virtual method corresponds to an element of this array indexed by a constant number. But in Python, __vtable (actually called __dict__) is an unordered map from each method names (as a string) to its entry point. Computing a string's hash value for a vtable lookup takes time, so unless you have a JIT (and CPython does not), it can slow down method calls.

    4. Re:Runtime vs. compile-time checking by EvanED · · Score: 1

      Right; I know that. If your post was meant as a response to me (to dispute something I said or something like that), I think you just misunderstood what I meant. For instance, in C++ consider the following code:

      class B { virtual void foo() { ... } };
      class D1 : public B { virtual void foo() { ... } };
      class D2 : public B { virtual void foo() { ... } };
       
      blorz(B const & obj) {
        obj.foo();
      }

      All I'm saying is that you can't resolve the call to foo inside blorz, because it could be any of B::foo(), D1::foo(), or D2::foo(). Unless you generate code for blorz that is specific to the dynamic type of obj (and I have no reason to think that compilers do this), the call could be to any of the three functions so you can't inline it or do any of the other fancy stuff.

    5. Re:Runtime vs. compile-time checking by samael · · Score: 1

      But then static languages have to duplicate the template code for each type that it handles.
      That's not how Generics are handled in .Net - the code is duplicated for value types, but the same code is re-used for reference types.

    6. Re:Runtime vs. compile-time checking by shutdown+-p+now · · Score: 1

      All I'm saying is that you can't resolve the call to foo inside blorz, because it could be any of B::foo(), D1::foo(), or D2::foo(). Unless you generate code for blorz that is specific to the dynamic type of obj (and I have no reason to think that compilers do this)

      Actually they do just that. If a compiler can inline blorz for a particular call, and that call is for a specific instance with well-known type (i.e. not itself a reference), then it can definitely do a non-virtual call. In fact, I just checked that with VC10 with /O2, and sure enough, it inlined blorz when I called it first for D1 and then for D2, and transformed the calls to direct non-virtual ones. I would be surprised if g++ didn't do the same.

    7. Re:Runtime vs. compile-time checking by EvanED · · Score: 1

      If a compiler can inline blorz for a particular call, and that call is for a specific instance with well-known type (i.e. not itself a reference), then it can definitely do a non-virtual call.

      That doesn't surprise me; what I don't think any of them will do is, when compiling blorz on its own, create specialized versions. (E.g. it'd be theoretically possible to do something like:

      blorz(B const & obj) {
          if (obj is actually a B) {
              obj.foo(); // inlined B::foo();
          }
          else if (obj is actually a D1) {
              obj.foo(); // inlined D1::foo();
          }
          else if (obj is actually a D2) {
              obj.foo(); // inlined D2::foo();
          }
      }

      (Assuming D1 and D2 are the only subclasses of B. You could add a default case though.)

      This could give a benefit if the body of blorz was bigger and the benefits from inlining and enabled optimizations from that were greater than the cost of the checks.

      I should have been more clear.

      (By contrast, I think JIT compilers will do stuff like this. They might notice that blorz is almost always called with a D1 object, create a compiled and optimized version for that, and add a dynamic check for it.)

    8. Re:Runtime vs. compile-time checking by Anonymous Coward · · Score: 0

      Dynamic languages have more overhead to dispatch a method call.

      That depends on how method dispatch is implemented in the virtual machine. JIT compilers can replace an expensive indirect call with a compare + direct call pair at all call-sites (Hotspot, for example, does this) which makes method dispatch overhead go away. Look up inline caching on Wikipedia or read the polymorphic inline caching (PIC) paper if you are interested in the details.

    9. Re:Runtime vs. compile-time checking by n+dot+l · · Score: 1

      Visual C's profile-guided optimizations do actually do this, in cases where profiling shows obj to be one of a small number of types during the vast majority of invocations.

  23. Interviewer acted like an ass by Logic+and+Reason · · Score: 4, Insightful

    Kalev's questions came across as ignorant and belligerent, but Stroustrup answered all of them intelligently, thoroughly and patiently. It's good to know that there are men like Stroustrup still working hard on C++, even though I no longer do much work in it.

    1. Re:Interviewer acted like an ass by Anonymous Coward · · Score: 0

      I still don't get what Stroustrup wants to achieve with axioms. There were about one reasons why I thought they could be useful:
      By stating an axiom I can give the compiler some more room to play with. Maybe the compiler can prove that he can safely remove some code.

      I thought this was very bloated but at least I could see a use in it. Then Stroustrup says it is not meant to do that. What he says sounds like axioms are only some kind of documentation. But C++ already contains syntax for documentation. I really see how concepts are superior to documentation and I looked forward to it. But I don't see how axioms are superior to documentation.

      I suspect the whole axiom shit was only introduced because someone wanted to write papers about it.

    2. Re:Interviewer acted like an ass by syousef · · Score: 1

      Kalev's questions came across as ignorant and belligerent, but Stroustrup answered all of them intelligently, thoroughly and patiently. It's good to know that there are men like Stroustrup still working hard on C++, even though I no longer do much work in it.

      It's called being a professional. Rare these days, I know. Good to see though.

      --
      These posts express my own personal views, not those of my employer
    3. Re:Interviewer acted like an ass by jgrahn · · Score: 1

      Kalev's questions came across as ignorant and belligerent, but Stroustrup answered all of them intelligently, thoroughly and patiently. It's good to know that there are men like Stroustrup still working hard on C++, even though I no longer do much work in it.

      It's called being a professional. Rare these days, I know. Good to see though.

      He was clearly annoyed by the questions (or the way they were phrased, or what was implied by them), though. And he didn't try to hide it. Maybe he should have.

  24. What are they supposed to say by codegen · · Score: 4, Insightful

    They are supposed to make the claim against the area for which their language is most appropriate. Although to be fair, it is often the people who are marketing the self-help books that tend to be the most vocal advocates of a particular language. I remember picking up an early O'Reilly book on Perl in a bookstore and reading the introduction and putting it back on the shelf in disgust because of the zealousness of the advocacy in the introduction.

    I have also been down the "should not" path on several languages much to my chagrin. Fortunately, I've paid the price allowing me to spare my students the pain.

    --
    Atlas stands on the earth and carries the celestial sphere on his shoulders.
    1. Re:What are they supposed to say by DrWho520 · · Score: 1

      Document you experience, please. I think that would be a most excellent book to add to my shelf, "Language X Was Never Meant to do Y." If that is not enough material, fill in with what it was supposed to be used for.

      --
      The cancel button is your friend. Do not hesitate to use it.
    2. Re:What are they supposed to say by Anonymous Coward · · Score: 0

      Seems you've avoided the zealotry of HTML5 fans, Ruby fans, and especially Objective-C/any apple-centric technology

    3. Re:What are they supposed to say by PiSkyHi · · Score: 1

      A computer language should be empowering, there is no reason why a computer language should annoy you a little in all of its details enough to want to try all alternatives in balance for each minor point.

      Most people who put enough effort into 1 language, will find that Turing complete language covers all their needs with what they now know already. Advocacy is the inevitable result of this empowerment and the only people who don't advocate a language are the ones who spend their time searching for a better Turing complete language rather than improving their own code.

      Not that searching for a better language is a bad thing, it does keep us on our toes, but unless you just can't do something you strongly believe should be possible, it is usually just a waste of coding time IMO.

    4. Re:What are they supposed to say by Pseudonym · · Score: 1

      They are supposed to make the claim against the area for which their language is most appropriate.

      Then you run into the opposite extreme, which is that some programming languages develop an implicit theory about what they are "for" and then get stereotyped in that domain. You know, C is "for" systems programming on Unix. Java is "for" deploying untrusted applets over the Internet. Perl is "for" batch/reporting jobs that require a slightly thicker layer of glue than a shell script. PHP is "for" web scripting jobs that are slightly more demanding than SSI. Haskell is "for" writing its own compiler in.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  25. The C+- Language by Anonymous Coward · · Score: 5, Funny

    The C+-* Language

    * pronounced "C, more or less."

    Unlike C++, C+- is a subject oriented language. Each C+- class instance known as a subject, holds hidden members, known as prejudices or undeclared preferences, which are impervious preferences, which are impervious to outside messages, as well as public members known as boasts or claims. The following C operators are overridden as shown:

    > better than
      < worse than
      >> much better than
      << forget it
      ! not on your life
      == comparable, other things being equal

    C+- is a strongly typed language based on stereotyping and self-righteous logic. The Boolean variables TRUE and FALSE (known as constants in less realistic languages) are supplemented with CREDIBLE and DUBIOUS, which are fuzzier than Zadeh's traditional fuzzy categories. All Booleans can be declared with the modifiers strong and weak. Weak implication is said to "preserve deniability" and was added at the request of the D.O.D. to ensure compatability with future versions of Ada. Well-formed falsehoods (WFFs) are assignment-compatible with all Booleans. What-if and why-not interactions are aided by the special conditional evenifnot X then Y.

    C+- supports information hiding and, among friend classes only, rumor sharing. Borrowing from the Eiffel lexicon, non-friend classes can be killed by arranging contracts. Note that friendships are intransitive, volatile, and non-Abelian.

    Single and multiple inheritance mechanisms are implemented with random mutations. Disinheritance rules are covered by a complex probate protocol. In addition to base, derrived, virtual, and abstract classes, C+- supports gut classes. In certian locales, polygamous derivations and bastard classes are permitted. Elsewhere, loose coupling between classes is illegal, so the marriage and divorce operators may be needed:

    marriage (MParent1, FParent1);
    // child classes can now be derrived
        sclass MySclass: public MParent1, FParent1
    // define MySclass
        sclass YourSclass: public MParent1, FParent2
    // illegitimate
        divorce (MParent1, FParent1);
        marriage (MParent1, FParent2);
        sclass YourSclass: public MParent1, FParent2
    // OK now

    Operator precedence rules can be suspended with the directive #pragma dwim, known as the "Do what I mean" pragma. ANSIfication will be firmly resisted. C+-'s slogan is "Be Your Own Standard."

    http://baetzler.de/humor/c_more_or_less.html

  26. Script Language Kiddies by Anonymous Coward · · Score: 0

    It's Slashdot.

    95 percent of the posts are going to be from script language kiddies who have never written a single line of commercial quality production code on a medium to large scale product.

  27. Re:BIG need to dramatize by Timothy+Brownawell · · Score: 1

    Concepts in C++ should have had the same effect for Generic Programming in C++ that C++ had for Object Oriented Programming in C. The should have democratized generic programming and brought forth a renaissance in C++ library design. Instead, petty politics killed the most exciting change to C-like languages in years.

    Given "Things could have been much worse. In particular, we could have made the seriously flawed "concepts" part of the standard." and "By building directly on the pre-Frankfurt concepts and applying modifications along the lines I suggested in "simplifying the use of concepts" we could have had something acceptable (IMO) within months, but that will not happen now. Instead, we must re-evaluate the basics of concepts and rebuild more or less from scratch (relying on the experience gained so far)â"and experiment. My stated estimate is that that will take on the order of five years, but that it will happen.", I'm thinking that concepts being delayed (not killed) means they'll actually be significantly better that they would have been without being kicked out of this particular revision of the standard.

  28. Papering over the mold by Animats · · Score: 4, Interesting

    It's kind of sad. The C++ committee has taken the general position that the underlying defects of C++ should be papered over by making it possible to write templates that hide the problem. But the hiding never quite works; the mold always seeps through the wallpaper.

    The root of the problem is that C and C++ backed into a type system. Originally, C barely had types at all; there were ints and there were floats. Pointers and ints were almost interchangeable. Fields in structures were just offsets, and field names had to be unique across all structures. Gradually, C evolved into a strongly typed language. Sort of. "void *" was introduced as a sort of escape hatch for the type system.

    More importantly, there was never a clear distinction made between arrays and pointers. That single design decision is responsible for most of the buffer overflows in the world. We should have had syntax like

    int read(int fd, char buf[n]&, size_t n);
    to replace the old
    int read(int fd, char *buf, size_t n);

    which says nothing about the size of the array. Right there is the cause of most buffer overflows - the language doesn't properly support talking about the size of arrays.

    Part of the problem there was a major error in the original design of C++ - it didn't have "&" references. So you couldn't talk about a reference to an array; you had to use a pointer to the first element. That pointer has the type of the element, not of an array. Every time you write "char *buf" instead of "char buf[n]&", you're lying to the compiler. The cost of that lie is millions of crashes a day.

    Instead of fixing the mess underneath, C++ papered it over. Arrays were wrapped with classes in the Standard Template Library. The STL is a good thing, but it's not good enough to totally replace built-in arrays. So real-world programs remain a mixture of ambiguous built-in arrays, pointers to arrays, and STL arrays.

    Then the STL approached iteration as an extension of pointer arithmetic. For "compatibility" with C pointer arithmetic, iterators are not only unchecked, but are not explicitly bound to the collection over which they iterate. So the safety problems of C were carried over into STL arrays. This was another bad decision. Most modern languages approach iteration by providing a "do this to all that stuff" construct used for most common iteration cases. C++ does not.

    This is why I'm so critical of the C++ committee. If they'd focused on safety, instead of cool but obscure template features, software would be much better today.

    1. Re:Papering over the mold by Areyoukiddingme · · Score: 1

      The Java design team did focus on safety, and look where that got them.

      C++ is dangerous because it needs to be. There needs to be one high level language in the world that's like juggling operating chainsaws to code in it, because of the options that gives you.

      As the cliche has it, with great power comes great responsibility. C++ is greatly powerful. Using it correctly is a great responsibility.

    2. Re:Papering over the mold by Sir_Lewk · · Score: 1

      More importantly, there was never a clear distinction made between arrays and pointers.

      As any semi-competent C programmer will tell you, that's a feature.

      --
      "linux is just DOS with a UNIX like syntax" -- Galactic Dominator (944134)
    3. Re:Papering over the mold by Animats · · Score: 3, Informative

      C++ is dangerous because it needs to be. There needs to be one high level language in the world that's like juggling operating chainsaws to code in it, because of the options that gives you.

      Wrong. It's not essential that a language be unsafe to have low level constructs. Ada, Modula I/II/III, Clascal, Object Pascal, Eiffel, and other hard-compiled languages have been much safer than C++, with comparable power. You don't have to go to an interpretive environment to get safety. That's an illusion from Java, which was made interpretive because Sun wanted portability between their SPARC architecture and the competing Wintel systems.

    4. Re:Papering over the mold by Anonymous Coward · · Score: 2, Insightful

      I guess buffer overflows are a feature too then.

    5. Re:Papering over the mold by Impy+the+Impiuos+Imp · · Score: 1, Insightful

      DO WANT array bound limiting built into the language.

      DO NOT WANT static-size arrays.

      DO NOT WANT bound checking overhead at runtime.

      That's the problem. It's a tradeoff between speed, space, and bullet-proof code.

      --
      (-1: Post disagrees with my already-settled worldview) is not a valid mod option.
    6. Re:Papering over the mold by Tetsujin · · Score: 1

      We should have had syntax like


      int read(int fd, char buf[n]&, size_t n);

      to replace the old


      int read(int fd, char *buf, size_t n);

      The problem there is, who checks to see that "buf" is sufficiently large, when, and how?

      The choice not to do that sort of thing at runtime is pretty fundamental to the design of C as a minimal-overhead language. Checking that kind of assertion at compile time is a nearly intractable problem - I would argue that the benefits wouldn't have been worth the cost. Still, I do agree that making that relationship between the buffer and its size explicit in the code is a good thing.

      Instead of fixing the mess underneath, C++ papered it over. Arrays were wrapped with classes in the Standard Template Library. The STL is a good thing, but it's not good enough to totally replace built-in arrays. So real-world programs remain a mixture of ambiguous built-in arrays, pointers to arrays, and STL arrays.

      I think it's worth noting the precise reasons why STL containers aren't "good enough" to "totally" replace arrays:

      • Extra overhead from carrying information about the array's size in addition to its data address
      • Lack of syntax support for declaring elements of a vector
      • Use of built-in arrays didn't end due to the continued need for the zero-overhead methods for dealing with memory

      Then the STL approached iteration as an extension of pointer arithmetic. For "compatibility" with C pointer arithmetic, iterators are not only unchecked, but are not explicitly bound to the collection over which they iterate.

      That decision wasn't for compatibility with C pointer arithmetic (note, for instance, that it's entirely possible to implement an iterator in C++ which does the kind of checking you suggest, but still has the same interface as a C pointer) - but rather, for efficiency. For instance, consider the following loop:


      std::vector x(10000000); // Get the value of x from somewhere...
      for (std::vector::const_iterator i = x.begin(). i != x.end(); i++)
      { // do something...
      }

      Now, we damn well know that, barring memory corruption or a serious bug in the STL, that this won't overrun the boundaries of the container. So why should i be range-checked ten million times?

      --
      Bow-ties are cool.
    7. Re:Papering over the mold by DissociativeBehavior · · Score: 0

      Checking that kind of assertion at compile time is a nearly intractable problem

      Some tools are good at it. Professional versions of Visual Studio 2005 and above have an integrated code verifier that can detect buffer overruns and null pointer deferences at compile time.

    8. Re:Papering over the mold by Anonymous Coward · · Score: 0

      I agree with the second part, but the first part is confusing me because you don't say why C++'s type system is bad, or what you'd recommend as an alternative.

    9. Re:Papering over the mold by AdamHaun · · Score: 1

      More importantly, there was never a clear distinction made between arrays and pointers.

      That's because at a low level there isn't one. If you write assembly code, you refer to arrays using a base address (aka a pointer) and an offset (aka an index). This is not so great for applications but is excellent for systems/embedded programming, which C was designed for. In those domains, an array may not represent a fixed-size buffer in SRAM. You can use array notation to address memory-mapped hardware registers, for instance. Many of C's features didn't really make sense to me until I started doing embedded programming.

      --
      Visit the
    10. Re:Papering over the mold by Anonymous Coward · · Score: 0

      The problems with arrays are resolved. There is std::vector for dynamic arrays and std::tr1::array for static arrays. Both are made possible due to templates. The only reason to use C arrays are due to the limits of aggregate initializers and this is resolved in C++0x.

      While iterators are not required to be checked, there are library implementations that provide for checked iterators. The Microsoft Visual C++ compiler has them.

      C++ has the ability to do a for each on a general container; std::for_each. Like most features this is provided as a library instead of a language extension. This can be a little difficult to use due to needing a functor, but C++0x provides lambdas making it at least as good as other language's built-in construct.

      It is not possible to fix all of the C problems without either breaking C compatibility or introducing a new non-orthogonal language within C++. Instead, C++ has added general purpose features that can fix the C problems and be used for other purposes through libraries. These "obscure template features" are what makes safe container usage and type safety possible in C++. They are general enough that they can be used for many other purposes including ones they weren't intended for (e.g. meta-programming). Library support like the Standard C++ Library and Boost make it possible for novice programmers to take advantage of these features. It would be nice if C didn't have a lot of problems, but C++ has the ability to work around most of them with minimal difficulty.

    11. Re:Papering over the mold by shutdown+-p+now · · Score: 1

      Part of the problem there was a major error in the original design of C++ - it didn't have "&" references. So you couldn't talk about a reference to an array; you had to use a pointer to the first element.

      I don't see how that affects anything. You can have a pointer to an array in C++ just like you can have a reference to an array. Heck, you can have one in C:

      void foo(int (*xs)[3]);
       
      int main()
      {
          int xs[3], ys[4];
          foo(&xs); // okay
          foo(&ys); // type mismatch, wanted int(*)[3], got int(*)[4]
      }

      References don't change this one bit.

      For "compatibility" with C pointer arithmetic, iterators are not only unchecked, but are not explicitly bound to the collection over which they iterate.

      It was not done for compatibility, it was done because "you don't pay for that which you don't use", which is one of the main C++ design principles.

      Besides, nowhere in ISO C++ standard it actually says that iterators should be unchecked, or that they should not be aware of the collection they iterate over. An implementation with checked iterators would still be entirely ISO C++ conformant. An example of such is Visual C++, which has checked iterators and collections by default in debug builds, and allows you to enabled them in release builds if you're willing to pay the performance penalty. With that enabled, you get all the same checks for STL iterators as you would for them in Java and C# - out-of-bounds check, invalidation checks (such as when you modify a collection and then use the iterator), comparing iterators belonging to different collections, and so on.

      Most modern languages approach iteration by providing a "do this to all that stuff" construct used for most common iteration cases. C++ does not.

      Really? I thought that's the whole point of header <algorithm>, and specifically of std::for_each.

      This is why I'm so critical of the C++ committee. If they'd focused on safety, instead of cool but obscure template features, software would be much better today.

      If you want a language that doesn't let you shoot yourself in the foot, then you should just look elsewhere. C++, just like C, is for those scenarios where you absolutely must avoid the overhead of the safety checks that are necessary to prevent such an occurence. Even so, as pointed out above, you can have a safe C++ implementation (heck, you can have an implementation with fat bound-checked raw pointers!), and there are existing implementations that work that way.

    12. Re:Papering over the mold by Sir_Lewk · · Score: 1

      So you're saying that steering wheels are a design flaw of cars because of car accidents?

      --
      "linux is just DOS with a UNIX like syntax" -- Galactic Dominator (944134)
    13. Re:Papering over the mold by neonsignal · · Score: 0

      I think you misunderstand the intent of the language. C++ is aimed at significant software projects, infrastructure, and embedded programming. Performance is an important component of this, as is backward compatibility. So what you call 'papering over the mold' is actually an attempt to evolve a language that continues to work for hundreds of thousands of programmers in real world applications.

      The C family of languages have always been statically typed, for good reason; it improves performance, and it catches a particular class of bugs at compile time. Just because the original system is underspecified does not mean that there was no static type system. C++ is a more explicitly typed language.

      The major change with C++ was to provide language support for object oriented concepts (rather than programmers using ad-hoc conventions). The second major addition was to provide language support for generic programming concepts. These are not wallpaper; they have helped us to avoid dated language tricks (such as pre-processor macros and untyped pointers). If you are making a lot of use of non-templated arrays and void pointers in your code, you have a lot to learn about using C++.

      C++ is not a tame language. It will not prevent you using language facilities that are unsafe. As you say, even the STL containers do not prevent bounds violations. To check for such things requires implicit run-time checking which would be an unacceptable performance cost in many of the application areas where C++ is being used. Of course, the language also allows you to implement your own libraries that do have bounds checks (though often this is better done at the interface to object methods at a higher level, rather than within the container).

      There is legacy support for aspects of C that would be best removed from the C++ language, but why break all that existing code? If you really want an ideal language, there are plenty of academic toy language experiments. Do you realize how useful it is to be able to write a C++ program on a Linux system, and not have to worry about whether it will make best use of the system resources, or whether someone has implemented bindings to the legacy C code in the operating system, or whether there will be major compatibility issues on some other system.

      If you have such fundamental problems with the language design as the concept of pointers, then I would suggest that perhaps you have chosen the wrong language to write code in. If you want more safety in the languages used to program systems, then you need to suggest a language, and help to rewrite all the legacy code. Perhaps you can start on all the lines of C code out there before you start worrying about C++.

    14. Re:Papering over the mold by Cassini2 · · Score: 2, Interesting

      Fortran is a much older language than C++, and it supports variable sized arrays with known sizes in calling functions. It is also one of the few languages that are faster than C on supercomputer number crunching applications.

      C++ should be several different languages, that can be compiled and linked together. The source files should have DEFCON levels to show how dangerous / fast they are.

      DEFCON 5 - Peace. The most passive Java/Python/Scriptish code imaginable; run-time types; and built-in automatic memory management.
      DEFCON 4 - Forces compile-time type checking.
      DEFCON 3 - Adds Multi-processing / Cluster computing.
      DEFCON 2 - Fast code; direct access to all member variables; none of the get/put call slowness; memory management is banned (no new or delete); and no aliased variables. Numerical code as fast as Fortran. Code automatically configured to work well with MPI / Cluster configurations.
      DEFCON 1 - Pointers. Manual memory management.

      With DEFCON levels on the source files, bugs can be contained to areas of code, and the class/optimization level of the code can become clearly visible.

    15. Re:Papering over the mold by Anonymous Coward · · Score: 0

      To check for such things requires implicit run-time checking which would be an unacceptable performance cost in many of the application areas where C++ is being used.

      Why? If you wanted optimized code, you have C as an assembly abstraction. The problem is that it fails to scale without proper practices and the dependency on a high level of competency. I don't see why a performance hit for a speed up in development time is unreasonable if you can provide interoperability. Asynchronicity is a whole other problem that has to be dealt with, regardless of performance differences between components.

    16. Re:Papering over the mold by wiredlogic · · Score: 1

      C was meant to be close to the hardware and have no unnecessary overhead at execution time. This was normal behavior at the time C was designed and it's initial evolution to ANSI C. The distinction between arrays and pointers only exists at compile time precisely because it was deemed an unnecessary burden to carry extra metadata around on array parameters at execution time.

      --
      I am becoming gerund, destroyer of verbs.
    17. Re:Papering over the mold by Anonymous Coward · · Score: 0

      In c++ you should use containers not arrays.

    18. Re:Papering over the mold by benhattman · · Score: 1

      Pointers and ints were almost interchangeable.

      Good news my friend, now pointers are completely interchangeable with size_ts. No "almost" about it. Cheers!

    19. Re:Papering over the mold by thechao · · Score: 1

      I don't even know where to begin a serious criticism of this. Let me start by asking a question: which computer is it, exactly, that you use supports a native array type? In x86 I suppose the closest would be a 4-way SSE vector? This only captures a subset of the cases you mention. Let me continue point by point:

      (1) Escape hatch. Name a real language without an escape hatch? Haskell, O'Caml, LISP, Java, C#, VB, Cobol, FORTRAN, etc. can all link to C-binaries.
      (2) Distinction between arrays and pointers. Misinformation: the problem is that an array decays to its equivalent pointer type with little effort. Any conformant C++ compiler can, will, and does reject passing an explicit array, i.e., char-string literals, to a parametric type expecting a scalar; even GCC does this.
      (3) "Responsible for most buffer overflows". Is it? Data? My recent reading of bug-sources in the literature does not support this.
      (4) "C++ didn't have &". Again, C++ inherited the array-decaying-to-pointer from C. Maybe this is a bad idea. If you could please write a short document explaining a backwards-compatible fix for this, that'd be great.
      (5) I don't really understand your STL comment. At what point is the STL --- an algorithms library --- going to replace a data-structure? Perhaps you mean that the limited set of containers in the std namespace don't fully replace an array? Perhaps. I think there are some missing random-access containers: fixed-length arrays and wrappers around raw pointer-buffers are examples. There is also a regrettable lack of trie's, R-trees, quadtrees, 2-3-trees, and the rest.
      (6) "Most modern languages approach iteration...". Sure. That's why C++0x is introducing a for (i : X) [foreach] construct.
      (7) "Safety." First, there is no definition of "safety." Second, even if I admit there is a workable definition of "safety", it has never been a concern for C or C++.

    20. Re:Papering over the mold by jgrahn · · Score: 1

      Instead of fixing the mess underneath, C++ papered it over. Arrays were wrapped with classes in the Standard Template Library. The STL is a good thing, but it's not good enough to totally replace built-in arrays. So real-world programs remain a mixture of ambiguous built-in arrays, pointers to arrays, and STL arrays.

      There is no thing called "STL array". Do you mean std::vector?

      I think it's worth noting the precise reasons why STL containers aren't "good enough" to "totally" replace arrays:

      • Extra overhead from carrying information about the array's size in addition to its data address
      • Lack of syntax support for declaring elements of a vector
      • Use of built-in arrays didn't end due to the continued need for the zero-overhead methods for dealing with memory

      Minor inconveniences, which rarely apply. I don't use C arrays much in my programs; std::vector is so much more easier to handle. The third bullet above sometimes applies -- if I need a 20-char buffer inside foo() and foo() gets called a million times per second, I wouldn't like to malloc memory every time. But that's a local thing which doesn't spread globally throughout the code. Maybe the Boost array type would help here, but I haven't used it so I wouldn't know.

      The main cause for C arrays in C++ code today is, I think, that there are /still/ programmers who haven't learned to use the standard containers.

      And finally, we cannot remove C arrays anyway. The grandparent seems to be one of those guys who pretend we could ignore all existing code, throw C compatibility out the window, and start from scratch. Well, we can't. And besides, the C compatibility is one of the big assets of C++.

    21. Re:Papering over the mold by Anonymous Coward · · Score: 0

      C99 actually does have that, so you can do: long read(int fd, char buf[lim], int lim)

      The problem is, people complain about overflows, but don't actually care to use the new syntax (or demand wider support for it).

    22. Re:Papering over the mold by ultranova · · Score: 1

      Extra overhead from carrying information about the array's size in addition to its data address

      Ironically enough, if C or C++ had language-level support for getting the size of a given array, it would take no overhead to implement: arrays are memory blobs as is, and each such blob must have its size recorded somewhere, because otherwise it couldn't be freed properly. The stack-allocated arrays are the only exception, but even that only means a single extra local variable on the function that uses one.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  29. Re:Maybe the vendors don't want C++... by Tony+Hoyle · · Score: 1

    Yet they released Visual Studio 2008 with a showstopper bug that stopped large C++ projects being compiled (it barfed about being unable to read the pdb file halfway through, then just gave up).

    They've made it that unless you #define a load of stuff to switch the crap off or start using proprietary Windows extensions none of your code will compile without warnings.

    They deprecated huge chunks of both the C and C++ standards without asking any of the standards committees.

    Oh, and they *still* haven't caught up with C99.

  30. C++: even iostream is doing it wrong by tepples · · Score: 3, Insightful

    It is even harmful to use C++ if you are not going to do it properly.

    For example:

    • Improper: Hello world using <iostream>. I tried compiling and linking hello world with a recent version of MinGW (a port of GCC to Windows), and the binary was over 400 KB. Using shared libstdc++ doesn't help if I have to distribute an 800 KB DLL with every application. Nor does it help in embedded systems that don't already have libstdc++ in ROM: compiling hello world using <iostream> for devkitARM produced a binary nearly 180 KiB in size for a machine with 256 KiB RAM.
    • Proper: Hello world using <cstdio>. The same g++ versions produced a binary of size 5,120 bytes on MinGW (libc is msvcrt.dll) or 25 KB on devkitARM (libc is static Newlib with its own terminal emulator).
    1. Re:C++: even iostream is doing it wrong by godrik · · Score: 1

      I wrote homebrew code for the nintendo ds. I'll make some test to see how it changes. I definitely liked using C++ there to change data structure easily. I started with generalist STL structures and changed the slowest for more dedicated/optimized ones.

      I do not recall wheter I used iostream or not (probably not)

    2. Re:C++: even iostream is doing it wrong by cortana · · Score: 1

      $ /usr/share/misc/config.guess
      x86_64-unknown-linux-gnu

      $ cat h.cpp
      #include <iostream>

      int main () {
          std::cout << "hello, world\n";
      }

      $ size h
         text       data        bss        dec        hex    filename
         2030        608        296       2934        b76    h

      That's with GCC 4.3.3, no optimization, stripping the executable after compiling it.

      The problem with mingw is that it doesn't yet support linking to libstdc++ dynamically. Even if you manage to build an executable that appears to link to it dynamically, it still includes a bunch of code statically anyway. Hence the apparent bloat in your executable.

      The definition of 'improper' and 'proper' really do depend on your exact requirements. On a PC, who cares if you are linking to one more library that is already on the target system? If you are developing code to run on a GBA then yes, you probably don't want the overhead you mention. But even the DS? That has 4 MB of RAM. That is a lot! If using features from libstdc++ means that you finish your program faster, then you have more time to debug it, and add extra features, etc.

    3. Re:C++: even iostream is doing it wrong by shutdown+-p+now · · Score: 1

      Improper: Hello world using . I tried compiling and linking hello world with a recent version of MinGW (a port of GCC to Windows), and the binary was over 400 KB. Using shared libstdc++ doesn't help if I have to distribute an 800 KB DLL with every application. Nor does it help in embedded systems that don't already have libstdc++ in ROM: compiling hello world using for devkitARM produced a binary nearly 180 KiB in size for a machine with 256 KiB RAM.

      I've tried it with the compiler that I have at hand (which is Visual C++ 2010). Here's the code:

      #include <iostream>
      int main() {
          std::cout << "Hello, world!" << std::endl;
      }

      And the compiler flags (/MT means statically link, /0x means optimize for speed and screw the debugger):

      cl /EHsc /O2 /MT hello.cpp

      The resulting binary is 90kb. If I use stdio.h and printf instead, with the same compiler options, I get 41kb - granted, there's still a difference, but it's nowhere near the order of magnitude that you claim.

    4. Re:C++: even iostream is doing it wrong by tepples · · Score: 1

      Using shared libstdc++ doesn't help if I have to distribute an 800 KB DLL with every application.

      The problem with mingw is that it doesn't yet support linking to libstdc++ dynamically.

      Even if MinGW could link to GNU libstdc++ dynamically, I'd have to include a copy of the DLL because Windows doesn't include GNU libstdc++.

      The definition of 'improper' and 'proper' really do depend on your exact requirements.

      I agree, but a lot of people are under the misconception that a C++ program that uses <cstdio> is automatically a C program in C++ clothing. They apparently haven't read item 23 from Scott Meyers' More Effective C++: consider alternative libraries if they would improve efficiency.

      On a PC, who cares if you are linking to one more library that is already on the target system?

      GNU libstdc++ cannot be assumed to be on the target Windows PC, unless I'm severely missing something.

      But even the DS? That has 4 MB of RAM. That is a lot!

      I could torture you by mentioning a platform with 2 KB of RAM plus 8 KB of battery-backed RAM on the game media, but bringing the NES into the discussion just wouldn't be germane, so I won't do it.

      If using features from libstdc++ means that you finish your program faster, then you have more time to debug it, and add extra features, etc.

      It can also mean that I don't finish my project faster because I have to spend so much more time optimizing the rest of the program for space. An extra 200 KB on a DS could mean that I can preload entire sound effects rather than streaming them from the card (or, in a multiplayer game, over the WLAN). Or it can mean I can use more frames of animation. In my experience, the perceived advantages that (say) std::ostringstream provides over std::sprintf (or Newlib siprintf) fail to justify the space.

    5. Re:C++: even iostream is doing it wrong by Cassini2 · · Score: 1

      For some embedded applications, a program size of 90kb to 41kb would result in a very large Christmas Bonus. It would be considered an order-of-magnitude reduction, and you would be a hero.

    6. Re:C++: even iostream is doing it wrong by shutdown+-p+now · · Score: 1

      2x is not an order of magnitude reduction by definition of "order of magnitude", unless you count everything in binary. Then again, I do not know, perhaps it's normal among embedded developers :)

      In any case, streams are a really poor example (or good, if you are after spreading FUD) - it's the single worst thing in terms of size of compiled code (and performance, actually) in the entire C++ standard library. There are many reasons for this, such as overcomplicated stream API in general, and the combined use of virtual functions and virtual base classes and templates. On the other hand, containers are much more lightweight in terms of generated code (especially something like vector or list), and you'll be hard-pressed to do better by hand-coding. And things like pair or auto_ptr are absolutely free - and yet can be very handy at times.

    7. Re:C++: even iostream is doing it wrong by Cassini2 · · Score: 1

      When you count pennies, dimes are an order-of-magnitude. Reducing the memory usage from 91K to 41K could be a micro-controller versus a micro-processor and external memory. It could be the difference between a chip that costs $11 and one that costs $8. When you are trying to find ways of eliminating 1 cent capacitors, eliminating chips represents big dollars. The embedded people think about things differently.

      Linksys rewrote changed the entire software stack for the WRT54GL. They even switched operating systems, simply to halve the number of memory chips in the design.

    8. Re:C++: even iostream is doing it wrong by Suiggy · · Score: 1

      Yeah, most developers I know of that do embedded C++ work avoid the use of C++ iostreams, locales, and turn off exception handling and RTTI at the compiler level. They do make use of STL containers and algorithms, however.

    9. Re:C++: even iostream is doing it wrong by ashmeister · · Score: 1

      As always, when programming, you should understand your libraries and use it accordingly. Iostreams are when of the best misunderstood concepts because everyone tries to use it as a one size fits all solution.

      Iostreams are template code. So yes, they will increase the size of your binary because everything is inline. If you're fretting about binary size, then you shouldn't even be considering using them.

      You shouldn't base effectiveness of C++ on MinGW - there are alot of other factors contributing to problems with MinGW and quite likely you're missing the target point. I believe the posters above discussed this in more detail.

      Iostreams are there for pure convenience. They're great if you just want to quickly code with a minimum of hassle. To do anything more complicated than that (like streaming for devices) is a bit of a nightmare. The iostream classes are fairly heavy, slow and do alot of format checking and other things that reduce it to a crawl. If you're just writing a quick program for a desktop pc, they're fine. But if you want a fast, lightweight embedded program, or want streaming for devices...you should shelve them.

      It is possible to create streaming classes that run more than 100% faster than iostreams and even printf. We built some internally for our company.

      What I'd really like now that its possible to start scaling up computation on embedded boards, is c++ libraries whose primary focus first is speed and *then* convenience. Boost is great for some things, but quite often it swaps those priorities around (see ublas).

    10. Re:C++: even iostream is doing it wrong by jgrahn · · Score: 1

      Even if MinGW could link to GNU libstdc++ dynamically, I'd have to include a copy of the DLL because Windows doesn't include GNU libstdc++.

      And this is iostreams' problem ... how?

    11. Re:C++: even iostream is doing it wrong by tepples · · Score: 1

      Even if MinGW could link to GNU libstdc++ dynamically, I'd have to include a copy of the DLL because Windows doesn't include GNU libstdc++.

      And this is iostreams' problem ... how?

      If the standard is so complex that the whole free software community doesn't know how to make it small, then there's a problem.

    12. Re:C++: even iostream is doing it wrong by Anonymous Coward · · Score: 0

      java version: 407 bytes

      runtime including startup of virtual machine on a 4 year old computer: 0.145 seconds...

      Yeah Java's terrible just like they say. People just make me laugh.

    13. Re:C++: even iostream is doing it wrong by tepples · · Score: 1

      runtime including startup of virtual machine on a 4 year old computer: 0.145 seconds

      How much memory does the JVM use while it is running? Not everybody has the luxury of even a 4-year-old PC; some widely used handheld devices are roughly equivalent to a 12-year-old PC.

    14. Re:C++: even iostream is doing it wrong by Anonymous Coward · · Score: 0

      With the GNU compiler, the iostream library is hampered from being tied to the C library. Look for the mystical macro that turns it off, you'll see a big difference.

    15. Re:C++: even iostream is doing it wrong by guardia · · Score: 1

      Not much, if you have the right hardware.. http://www.arm.com/products/multimedia/java/jazelle.html

    16. Re:C++: even iostream is doing it wrong by Stiletto · · Score: 1


      # Hello world using iostream: 400 KB.

      # Proper: Hello world using cstdio. 25 KB

      WOW! A difference of 375,000 bytes. Let's see. Using today's prices, $73.50 / terrabyte for hard disk and $6.75 / gigabyte for RAM, that BLOATED C++ version cost you $0.0000275625 more to store on disk, and $0.00253125 more to store in RAM. Boy, that language and library overhead is going to totally break the bank.

      Even if you're storing it on some kind of exotic gold-plated, diamond-encrusted EEPROM, you're barking up the wrong tree.

    17. Re:C++: even iostream is doing it wrong by tepples · · Score: 1

      Using today's prices, $73.50 / terrabyte for hard disk and $6.75 / gigabyte for RAM

      That's the price for desktop PCs, not handhelds.

    18. Re:C++: even iostream is doing it wrong by spitzak · · Score: 1

      I don't think iostreams uses virtual functions or base classes.

      It is using templates which causes it's problems.

      This was caused by the ludicrous idea that it would be used to write streams of objects other than bytes. About the only reasonable thing to write is UTF16 and even that is pretty much obsoleted by using UTF-8 to write Unicode. Writing larger or arbitrary objects looks nice initially but you quickly realize that it is entirely pointless to use an API designed for string constants to write objects that are not letters.

      There are alternative iostream implementations that ditch the types (and also the allocator arguments) and work significantly better and are much much smaller. Unfortunately they are not standard.

      Template specialization may help here but we need to get the considerable subset of developers who are not really writing real code and thus think writing UTF-16 with iostreams is important to be recipients of the clue stick before that will ever happen...

    19. Re:C++: even iostream is doing it wrong by shutdown+-p+now · · Score: 1

      I don't think iostreams uses virtual functions or base classes.

      I'll just quote the spec, alright?

      27.4.2[lib.ios.base]:

      namespace std {
        class ios_base {
      ...
          virtual ~ios_base();
      ...
        };
      }

      27.5.2[lib.streambuf]:

      namespace std {
      ...
        class basic_streambuf {
      ...
          virtual ~basic_streambuf();
      ...
      // 27.5.2.4 virtual functions:
      // 27.5.2.4.1 Locales:
          virtual void imbue(const locale& loc);
      // 27.5.2.4.2 Buffer management and positioning:
          virtual basic_streambuf<char_type,traits>*
          setbuf(char_type* s, streamsize n);
          virtual pos_type seekoff(off_type off, ios_base::seekdir way,
      ios_base::openmode which = ios_base::in | ios_base::out);
          virtual pos_type seekpos(pos_type sp,
      ios_base::openmode which = ios_base::in | ios_base::out);
          virtual int sync();
      // 27.5.2.4.3 Get area:
          virtual streamsize showmanyc();
          virtual streamsize xsgetn(char_type* s, streamsize n);
          virtual int_type underflow();
          virtual int_type uflow();
      // 27.5.2.4.4 Putback:
          virtual int_type pbackfail(int_type c = traits::eof());
      // 27.5.2.4.5 Put area:
          virtual streamsize xsputn(const char_type* s, streamsize n);
          virtual int_type overflow (int_type c = traits::eof());
        };
      }

      27.6.1.1[lib.istream]:

      namespace std {
        template <class charT, class traits = char_traits<charT> >
        class basic_istream : virtual public basic_ios<charT,traits> {
      ...
        };
      }

      And the same for basic_ostream.

      It is using templates which causes it's problems.

      Not as such, no - after all, with templates, you only get stuff linked that you actually use. However, virtualness + templates combo is deadly, as the compiler now has to create vtables for every instantiated template in the assumption that someone, somewhere, is going to call this function via a vtable.

      This was caused by the ludicrous idea that it would be used to write streams of objects other than bytes.

      Agreed. Well, there's nothing wrong with character streams as such (in the same way as TextWriter is distinct from Stream in .NET), and it makes sense to specialize for various character types there, but there should be a raw byte stream underneath - and there isn't one in C++, as streambufs are still character-oriented.

    20. Re:C++: even iostream is doing it wrong by spitzak · · Score: 1

      Well that really sucks. Did not realize it was as bad as that.

      I can certainly see how there could be a design with a single virtual flush() function plus a pointer and length of buffer in the base class, and a virtual destructor. But not the mess you are showing me there.

      The template problem is that it makes it so complicated you cannot even see this, and they are not taking any advantage of the templates to remove the virtual functions. Though I guess using templates that way would make it impossible to pass an arbitrary new stream object to an existing function. Gah.

      Agreed. Well, there's nothing wrong with character streams as such (in the same way as TextWriter is distinct from Stream in .NET), and it makes sense to specialize for various character types there, but there should be a raw byte stream underneath - and there isn't one in C++, as streambufs are still character-oriented.

      I don't quite understand what you are getting at. My complaint is that streambufs are NOT character-oriented, in that they take a template argument of the data type. I think it would be much better if they were char-only.

    21. Re:C++: even iostream is doing it wrong by shutdown+-p+now · · Score: 1

      The template problem is that it makes it so complicated you cannot even see this, and they are not taking any advantage of the templates to remove the virtual functions. Though I guess using templates that way would make it impossible to pass an arbitrary new stream object to an existing function. Gah.

      I believe they've put all that virtual stuff there (rather than e.g. using the curiously recurring template pattern) so that clients can pretend that there are no templates there at all, and use stream classes much as they'd use stream interfaces in higher-level languages. Of course, this only highlights the deficiency of the API - if 99% of all clients don't even know about the existence of basic_stream (and most of the remaining 1% who do know never use it), then why is it even there?

      I don't quite understand what you are getting at. My complaint is that streambufs are NOT character-oriented, in that they take a template argument of the data type. I think it would be much better if they were char-only.

      By "character oriented" here I actually meant "text oriented", that is treating streams as streams of text data first and foremost, and not raw byte streams. With respect to streambufs, I believe the same thing that you have stated: that they should only deal with chars (and treat them as bytes with no text encoding). As it is, frankly, I do not understand the point of streambuf/stream separation at all.

    22. Re:C++: even iostream is doing it wrong by spitzak · · Score: 1

      Okay I understand. I was using "character" as "char".

      Trying to write a "character" stream is a big problem and seriously causing grief in programs now. One big peeve I have is with otherwise intelligent programmers who seem to become complete morons when presented with Unicode and start thinking it is impossible to manipulate it unless they can count the "characters" and they are all the same size, leading to horrid things like UTF-16 and multiple api's to everything. Raw byte streams are the way to go, containing UTF-8 or whatever, the only stuff that needs to look at "characters" are the actual display routines and text editors. This would get rid of an enormous mess of complexity and incompatability, mostly because errors in the UTF-8 could be deferred until they really matter. Lots of security problems would be fixed if you could know that two unequal byte streams will evaluate to two different objects, something that is not true for anything that translates them into a different internal representation.

    23. Re:C++: even iostream is doing it wrong by Anonymous Coward · · Score: 0

      Ok, lets try this. It's on a GCC 4.3.4 Debian Amd64.


      > cat hello.cpp
      #include <iostream>

      int main(int argc, char * argv[])
      {
              std::cout << "Hello, World!" << std::endl;
      }

      > g++ -O2 -Wall -o hcpp hello.cpp
      > ll -h hcpp
      11K

      > cat hello.c
      #include <stdio.h>

      int main(int argc, char * argv[])
      {
              printf("Hello, World!\n");
              fflush(stdout);

              return 0;
      }

      > gcc -O2 -Wall -o hc hello.c
      > ll -h hc
      9.1K

      So that's 11K for the C++ version, versus 9.1 K for the C version.
      Hmmm. Quite different from some other people's finding around here.

  31. The hell with concepts by wiredog · · Score: 1

    Fix the damned error messages. Seeing something referring to "std::vector>" when I used "vector" is bad enough. Having it at the end of a 255 character error message? Even worse.

  32. C++0x by AP31R0N · · Score: 3, Funny

    Is that some kinda of filthy ASCII art?

    --
    Utilizing the synergization of benchmark e-solutions to pre-workaround action items!
    1. Re:C++0x by Anonymous Coward · · Score: 2, Funny

      DISREGARD THAT I SUCK C++0x

    2. Re:C++0x by marciot · · Score: 1

      I always thought it looked like fish bones.

  33. Re:BIG need to dramatize by kigrwik · · Score: 1

    Nice explanation, especially the "OOP in C" analogy. Thanks.

    --
    -- don't discount flying pigs until you have good air defense
  34. Re:BIG need to dramatize by pnewhook · · Score: 1

    It's only a big deal to certain programming groups and applications. The programming I do cannot use templates so generic programming is useless to me and removal of concepts is not a big deal at all.

    --
    Tesla was a genius. Edison however was a overrated hack who liked to torture puppies.
  35. still no function pointers for me :( by Anonymous Coward · · Score: 0

    In my opinion, the main thing lacking in c++ is that it's not possible to get a pointer to a function in a class instance. This meant that any code based on the windows API could not be "eloquently" wrapped into objects. The GUI has suffered most because of this, because MFC just isn't really object oriented to me. Of course it is possible to put in workarounds using global functions and storing pointers in some unused spot of the class, but such stuff has always bothered me.

    1. Re:still no function pointers for me :( by Timothy+Brownawell · · Score: 1

      In my opinion, the main thing lacking in c++ is that it's not possible to get a pointer to a function in a class instance. This meant that any code based on the windows API could not be "eloquently" wrapped into objects.

      What do you mean? Are you saying that "void(X::*y)(int)" (declare y as a pointer to a member function of class X that takes an int and returns void) doesn't exist? That classes can't contain function pointers as member variables? Something else?

    2. Re:still no function pointers for me :( by Agronomist+Cowherd · · Score: 1

      I think he means that non-static member functions can't devolve to plain old function pointers, so you use them as callbacks. This is because they implicitly need an object on which to function, and most non-C++-specific callback APIs don't have a mechanism to pass the object. Also the types are C++-specific, so the API becomes C++-specific.

      That said, I think others have worked out how to build shims that integrate member function callbacks into C-style APIs, at a small extra cost (the shim needs to get called, then turn around and call the member function using an object the shim collected earlier).

      That's my take on that specific complaint, at least.

      --
      -DwS
  36. Re:Maybe the vendors don't want C++... by pnewhook · · Score: 1

    as it is, I think C++ is pretty much dead as it is

    So what in your opinion is a viable C++ replacement?

    --
    Tesla was a genius. Edison however was a overrated hack who liked to torture puppies.
  37. Re:Uncluttered article (print == easy to read) by Anonymous Coward · · Score: 0

    Uncluttered article, without any extra crap and multiple pages. Printable == readable.

    There fixed that for you.

  38. Re:Maybe the vendors don't want C++... by shutdown+-p+now · · Score: 1

    They've made it that unless you #define a load of stuff to switch the crap off or start using proprietary Windows extensions none of your code will compile without warnings.

    They deprecated huge chunks of both the C and C++ standards without asking any of the standards committees.

    I assume that you refer to the so-called "secure CRT" functions here, such as strcat_s. If so, there are two points to be made.

    First of all, those aren't proprietary extensions. It's an implementation of an ISO C++ TR 24731 (as most ISO standards, an electronic version of the final standard isn't available freely, but you can look at the final draft). Yes, the implementation in VC2005 preceded the final release of that TR, and rather went hand in hand with development of the spec; but virtually all C++ compilers did that for ISO C++ itself as well, before it was finalized in 1998.

    Regarding "deprecating", it's mostly a poor choice of words. The compiler would complain about "strcpy is deprecated", but it was never supposed to mean deprecation in ISO C++ standardeze meaning. Besides, it was a warning, not an error, and a conformant C++ implementation can produce all kinds of warnings so long as it compiles legal code - warnings are not regulated by the Standard in any way. In any case, you don't need to "#define a load of stuff" - as with any compiler, you can pass preprocessor definitions via compiler switches from command line (or makefile), and you only need a single define - _CRT_SECURE_NO_WARNINGS.

    Oh, and they *still* haven't caught up with C99.

    No-one has caught up with C99 yet. Even gcc still has quite a few features implemented only halfway, or even outright broken. Heck, VLAs - which is one major C99 feature - were still broken in gcc 4.3, and only properly supported in 4.4. If anything, this just points out how little people do care about most C99 stuff (which you know anyway if you actually follow the discussions on the matter).

    At the same time, VC++ supports C++ TR1, which has some more useful bits of C99 (such as stdint.h header with standard typedefs for things such as int32_t).

  39. Re:Maybe the vendors don't want C++... by shutdown+-p+now · · Score: 1

    Concepts are not too different from the way generics work in C#

    Concepts are very different from C# generics in one simple (but far-reaching) aspect.

    C# generics can be constrained by interfaces. An interface constraint is limited to specifying instance operations (properties, methods, events) available for this particular type only. For example, C# generic type parameter cannot be constrained to say "this type should support operator+", because overloaded operators in C# are static, and need not even belong to be a member of the type substituted as a type parameter. This means that you cannot e.g. write a Complex<T> class in C# which supports all arithmetic properly (well you can if you use reflection and other similar tricks, but performance will be dismal).

    C++ concepts are predicates operating on multiple types and compile-time expressions. For example, there was a basic concept called SameType, that would hold true if two types given to it as arguments represent the same type. Because of that, concepts can require all kinds of operations - static members, global functions, overloaded operators, etc.

  40. Kudos: Indignation +1 by stephanruby · · Score: 2, Informative

    Yukihiro Matsumoto of Ruby: "Why should you switch to Ruby? If you are happy with Perl or Python, you don't have to. But if you do feel there must be a better language, Ruby may be your language of choice." and then "I believe people want to express themselves when they program. They don't want to fight with the language. Programming languages must feel natural to programmers."

    Nice job quoting him out of sequence, and implying that his response regarding his guiding philosophy is even relevant to the question that's posed to him about switching. And also, nice job omitting the phrase "I tried to..." from his guiding philosophy. Since such a qualifier implies personal doubt that he even achieved such a goal, that doubt was endangered your thesis, so kudos removing it -- that makes his response (that you've already completely distorted by quoting out of sequence, and quoted from a totally different question then the one you've put before it) sound even more absolute.

    Stewart: Did you have a guiding philosophy when designing Ruby?

    Matz: Yes, it's called the "principle of least surprise." I believe people want to express themselves when they program. They don't want to fight with the language. Programming languages must feel natural to programmers. I tried to make people enjoy programming and concentrate on the fun and creative part of programming when they use Ruby.

    [...]

    Stewart: Why should someone already familiar with Perl or Python switch to Ruby?

    Matz: Why should you switch to Ruby? If you are happy with Perl or Python, you don't have to. But if you do feel there must be a better language, Ruby may be your language of choice. Learning a new language is harmless. It gives you new ideas and insights. You don't have to switch, just learn and try it. You may find yourself comfortable enough with Ruby to decide to switch to it.

  41. functionaly duck by Anonymous Coward · · Score: 0

    After skimming the article, what came to mind was:
    Is he trying to turn C++ into a functional programming language? Concepts == FP-ish behavior...
    With that, I rather choose Scala and it's VM safety net.

  42. "Concepts" is a poor name by chriso11 · · Score: 1

    I really wish they had chosen some other word - searching for "C++ concepts" gets a lot of introduction to c++ programming websites (yes, I know the trick is to search for "C+0x concepts"). When you pick a word to describe what you are doing, either pick a more accurate description that is unambiguous. Maybe they could have gone with something like "Formalized Templates".

    --
    No, I don't trust in god. He'll have to pay up front, like everybody else.
  43. "All Quack and no play makes Daffy a dull boy." by Tetsujin · · Score: 1

    Yes yes, I know, I was being too simplistic (I realized this after I hit submit). Duck typing == dynamic dispatch *and* dynamic typing. Either way, "duck typing" is a stupid marketing term, nothing more.

    So what if it is? Stupid or not, it's nevertheless an effective way of conveying a certain concept.

    The point is that these languages have taken those language features and used them to embrace a philosophy (Duck Typing) of how types should be used in the language. I would say that your equation isn't quite correct: Duck Typing isn't the combination of dynamic dispatch and dynamic typing: rather, that combination is one way to implement the concept. Duck Typing itself has more to do with removing the formal definition of a common interface, and the philosophy that if two modules happen to implement the same interface consistently enough that they could work interchangeably, then that is a common interface.

    Duck Typing is not specific to runtime. It's all about the concept that type compatibility is determined only by the set of operations that can be performed on a value.

    Basically it's a convenient form of sloppy, fragile programming, especially in the case of languages where an inconsistency in the interfaces of the "interchangeable" modules can't be detected except at runtime via a coverage test (as in Python). But it's nevertheless an idea that is used (by way of templates) quite a bit in C++. If you implement a function in C++ with a template argument, then the only thing about that argument that the programmer has to concern himself with is whether the usage of that argument inside the function fits the interface of the class used to implement the value passed in for that argument. In this case neither dynamic dispatch or dynamic typing would be used (C++ specializes the function at compile time) - but from the programmer's perspective it's the same concept as duck typing: all that matters is that whatever class is used as the value for that template argument has to match the usage of that argument inside the function body.

    --
    Bow-ties are cool.
  44. Failure of Concept by Anonymous Coward · · Score: 0

    What failed was the concept of C++. We didn't need it, and the people that wanted it were basically bored with producing software and wanted to play around with programming concepts instead. Here it is, decades later, and I'm coding "cloud computing" infrastructure stuff in C. If you want to write code, write code. If you want to fart around, fart around, but don't take yourself too seriously or trick yourself into thinking that your new paradigm actually is one. Also, don't fool yourself into thinking that .NET is more about producing software than it is about building revenue fences for Microsoft.

  45. I wrote the "dead-end" post on Lambda... by BCooley · · Score: 1, Troll

    I wrote the original post on Lambda calling C++ a dead end, and I think what the article says about the standardization process is pretty accurate.

    Essentially there are a set of issues real world C++ programmers must deal with when using the languages, particularly in large projects, that are never addressed by the standards committee. Enumerating a few by importance:

    1. Stability, security, and memory safety.

    Support for garbage collection, optional safe arrays, safe pointers, and bounds checking for sections of code. Code areas where reinterpret casts and other memory unsafe operations can be disabled and flagged as errors. Secure versions of the standard libraries. Etc.

    Can anyone honestly say that security and stability in C++ code is not the singular most important issue for C++ presently? How many times have security, stability, or memory safety been even mentioned in the C++ 0x standardization process? I've browsed through many of the papers and have yet to see it mentioned a single time (possibly there are one or two mentions in the GC papers).

    2. Ability to integrate with other languages, particularly managed and dynamic languages.

    Reflection support, decidably parsable declarations, support or standardization of in/out semantics on declarations, etc. I would say for many (if not most projects) dealing with the "C++ as an insular world unto itself" is one of the next most glaringly problematic aspect of the language. Few languages go to greater lengths to make integrating with the outside world more difficult.

    3. Issues with separate compilation, headers and macros.

    BS made a half hearted attempt to mitigate the issues arising from the use of the include file model, and macros in C++, but it was quickly abandon. The problems (particularly in large projects) with the separate compilation model, (increasing time involved in parsing large headers), problems with macro leakage, and other issues in the essentially broken C style compilation model are a major source of continuous pain for C++ programmers.

    There is no reason why the language can not continue to be backwards compatible with separate compilation and macros, but can be moved forward towards a more workable model for new code.

    4. The inability to ever "deprecate" features.

    The language can be progressively improved, but only by some sort of an official program of scheduling certain features for deprecation. Insecure C functions and libraries, unused standards, etc. This kruft unneccessarily complicates the introduction of new useful features, and makes it difficult to maintain production code (which typically become new code combined with a random collection outdated programming practices and library includes which must constantly be "code reviewed" out).

    5. The inability to add features from other languages that do actually work.

    What is important and "works" for one programmer is a superfluous and useless add-on for another. But there are features of java, C#, and dynamic languages that C++ would do well to imitate. These features are rarely even discussed in favor of serving the template meta-programming community and those who feel the language should add a host of other esoteric features to the corner case use scenarios of the language.

    I've been writing C++ for more than 20 years, and I've dealt first hand working with a huge C++ project when working with ILM's large code base that exposed more than a few of the gaping weakness of this language. I was looking forward to.. at least.. some help in dealing with the impossibility of maintaining large amounts of template code, of which that code base had multiple nested layers. An error in one template parameter class cascades downwards into an infinite incomprehensible mess of template substitution errors. But the committee says "No concepts for you!"

  46. operator= versus operator== by Tetsujin · · Score: 2, Insightful

    Uncluttered article, without any extra crap and multiple pages. Printable == readable.

    There fixed that for you.

    You know, this tends to bug me a bit...

    I mean, yeah, here we are talking about C++ in which "=" means assignment and "==" means an equality test... But the world at large is not governed by these definitions. An equation like "y = 3*x + 4" establishes a relationship in which the two sides of the equation are equal.

    If you want to apply the meanings of C operators to English text, then really neither meaning is correct:
    "Printable = Readable" - means "Henceforth, until further notice, 'Printable' will have the value that 'Readable' has now" (Assignment)
    "Printable == Readable" - means "I want to know if 'Printable' and 'Readable' have the same value". (It's an equality test, not an equality assertion)

    --
    Bow-ties are cool.
    1. Re:operator= versus operator== by Anonymous Coward · · Score: 0

      I mean, yeah, here we are talking about C++ in which "=" means assignment and "==" means an equality test... But the world at large is not governed by these definitions.

      Don't bother, the average Slashdot shit simply isn't capable of understanding such subtleties.

      If you want to apply the meanings of C operators to English text, then really neither meaning is correct:

      If he wants to apply the meanings of C operators to English text, he's a worthless fuckwit who should be thrown in a woodchipper.

  47. Language "marketing" by Tetsujin · · Score: 1

    What's really unfortunate is that he's one of the very few language maintainers out there that isn't of the mentality "Rah rah! My language/tool/design-philosophy/whatever is the solution to all your problems and will take over the world tomorrow."

    Care to actually provide the names of those other language maintainers, with appropriate citations, that make such claims?

    Very well. They don't out and out say that exact phrase but I'm sick of languages being marketed to me like an automobile. Here are a few after a bit of Googling. I don't really have time to dig more up: ...

    If I were in their shoes, I would explicitly say what the language is but also explicitly say what it is not. As someone who's tried to do video analysis in Java, I've been down the "should not" path and wasted my time.

    Java was very, very hyped, it's true. However I view the other cases rather differently. I have been working on a language design of my own, and as a result I have given this some thought.

    Basically, to a certain extent it doesn't matter how good a language or tool is if people don't try it. And it can be hard to get people to try something new and different for a variety of reasons: there's bound to be a learning curve involved, and even if the language is populated with concepts the user will ultimately enjoy, when they start out it'll all be rather alien. I believe that if you want people to use the language you've developed, you've got to "market" it - otherwise people will never get beyond those initial hurdles standing between themselves and their potential enjoyment of the language. For the language to have any chance at all of success, someone's got to be an advocate for it - if the language creator isn't doing this, then why should anyone else?

    As for keeping the proper perspective in this advocacy - that is tough because people involved in development often think in terms of what they want the tool to become rather than necessarily exactly what it is. In the case of independent software developers writing these things, they're often not your consultants either - they're not there to advise you on whether their tool might or might not be good for your task - they wrote something they're enthusiastic about, and they're excited to share it.

    As for the Matsumoto quote you cited: he was asked specifically in the interview if there was a philosophy that guided the development of Ruby, and that was his answer. Now, you could say that was a carefully crafted answer designed to win over the hearts of programmers - or you could say that this really was the idea that drove him to create a programming language, and guided its design. Who can say which is right? I read the quote and I see Matsumoto as someone who's enthusiastic about what he's created, and wants people to enjoy it...

    --
    Bow-ties are cool.
  48. Re:BIG need to dramatize by maxwell+demon · · Score: 1

    Sure. And for groups who could not use OOP C++ certainly wasn't a big deal either. And for people writing single-threaded programs, removal of multithreading wouldn't be a big deal either. And I guess people programming toasters don't have any use for the standard I/O facilities of either C or C++, so why not get rid of them?

    --
    The Tao of math: The numbers you can count are not the real numbers.
  49. Two separate type systems - static and dynamic by Ed+Avis · · Score: 1

    It seems to me that C++ has forked into two languages which coexist in the same spec, like fungus and alga in a lichen. One of the examples given for using concepts is as follows:
    template<Container C, Comparator Cmp>
    void sort(C& c, Cmp cmp);

    This was to specify that type C, used as the type of the first argument, must implement the 'Container' concept. But don't we already have classes and abstract classes for that?
    void sort(Container& c, cmp cmp);
    You define the abstract class 'Container' using the same boring C++ syntax that's been around since 1985 or so, and then the compiler will check that what you pass implements this interface. So what's the need for another type language? Is it because there is no abstract base class that specifies 'has an [] operator' or 'has ++ and * operators'? If so would it not be better to add that somehow rather than making new language syntax?
    Or is it because of the difference between static binding, accomplished with templates at compile time, and virtual functions, which must be looked up at runtime? Is it really worth constructing a whole new language syntax just for the fairly small performance saving of skipping a vtable lookup? C++ advocates point out how std::sort can be faster than C's qsort because of template code generation, but with only slightly more intelligent compilers surely we could write more normal-looking source code and have type-specialized object code generated when needed, if the types used can be determined at compile time.
    C++ templates are very useful, but they never seemed to integrate that well with the rest of the language. It's not clear that having them grow their own type system is the best mutation to make the language simpler and more powerful, though it may be the best way to move forward from the situation we have now.

    --
    -- Ed Avis ed@membled.com
  50. tribal knowledge? by reiisi · · Score: 1

    I'm not really up on C++0x (eh, well) concepts, but, while I appreciate the concept (ehem) of trying to help the guy reading the code to read the minds of the original developers, I have to question the wisdom of trying to shoehorn the wisdom of the ages into a programing language. Especially, if we try to shoehorn the wisdom of the ages in via a generic (erk) mechanism.

    Wisdom is experience, experience is what you get in specific application, after reflection.

    I could see some use, possibly, for making exceptional code explicit and keeping the generic stuff implicit, but only if we can all agree beforehand what is exceptional and what is generic. Huge semantic issues, huge context issues, and it seems to me we must be careful when trying to drag the entire mental state context of the programer into the code.

    We still seem to be fighting the battle of implicit linkage. How does a programer make the linkage explicit when he or she doesn't know what most of his or her assumptions were until after the third or forth major bugs with that section of code have been found? (Speaking of an example of the benefit of "many eyes", ....)

    (Oh, and, please don't tell me that somebody is still enamored with the concept of writing bug-free code in the first pass. When are we, as a profession, going to recognize that bugs are a necessary part of the design process?)

    Overloading English is not going to help, either, I think, although it will cause one set of problems for people fluent in English, and a different set for those who are not.

    (No, I'm not sure of what I'm trying to say, other than that putting something called concepts into C++ is probably byting off more than any committee I know of can chew.)

    --
    Computer memory is just fancy paper, CPUs just fancy pens with fancy erasers; the 'net is just a fancy backyard fence.
  51. C++ jumped the shark a long time ago by Cola+Junkee · · Score: 2, Interesting

    What follows is all IMHO, of course you are welcome to your own opinion as well.

    I've struggled with large C++ codebases on a number of different projects, and while I admit that it is a powerful language, the problem is that there are a half a dozen different ways to do things. The fact that they are trying to give the language even more expressive power is just adding to the amount of rope that we as developers can hang ourselves with.

    I yearn for a language which is functionally complete, compiled, small, fast, cross-platform, and oh, NO TEMPLATES PLEASE! Templates/Generics are a blight (a blight I say!) on modern programming -- to say I was pissed when they added them to C# and Java was an understatement. I like my languages without too much syntactic sugar, thanks.

    In general, OO programming was never fully grokked by the masses. People spent far too much time trying to make their objects re-usable, and not enough time solving the problem at hand. At least with a language like C you are not fooling yourself, you can write in a procedural style and be happy.

    Don't get me wrong, C has a lot of short-comings as well. D is almost perfect, but again, the template blight has reared its ugly head.

    I know, a lot of people love templates, and they will argue that they are faster, or they are safer because of type-safety. Faster? Maybe .. slightly .. but not enough for me to want them. Safer? Well not if you take into account the fact that you are using C++, probably the most dangerous language to work with of all. I'll cast the result of my collection operation manually, thanks.

    Plus, you make the compiler work really hard, and your project now takes 40 minutes to compile instead of 5. Thanks for the productivity gains, but no thanks!

    --

    f u cn rd ths, u r prbbly a lsy spllr.

    1. Re:C++ jumped the shark a long time ago by FlyingGuy · · Score: 1

      Hear! Hear!

      C was designed to be a very small and compact language with the most minimal amount of sugarl. It is lean, mean and it just works

      C++ never, and I mean never got the object model right. The closest anyone has ever come to getting the object model right was Borland OO Pascal and even then they fucked it up in later versions.

      While it is quite nice to encapsulate a lot of functionality and behavior into one call it is certainly not the end all be all of language paradigms.

      I cant think of one thing that C++ has that I would miss if it disappeared from the face of the earth 5 minutes from now.

      --
      Hey KID! Yeah you, get the fuck off my lawn!
    2. Re:C++ jumped the shark a long time ago by fnj · · Score: 1

      If you don't want templates, don't fucking use them. There, is that too hard? If you only want one way to do something, pick one way and don't use the other ways. Sheesh.

    3. Re:C++ jumped the shark a long time ago by Cola+Junkee · · Score: 1

      Ah.. I wish it were that simple!

      Unfortunately, because of third party libraries, you don't actually have a choice whether or not you want to use templates.

      Because of STL, you don't actually have a choice either.

      There are enough libraries using that junk that,as any developer of a large C++ system can attest, at some point you are forced to use them, unless you take the extreme stance that you are going to program everything yourself. That approach may work fine for (some) open source projects, but not in the real world.

      Also, most people will berate you if you try to write your own list or hash map, instead of the STL. So in essence, there is also a peer pressure to use them.

      So yes, while it is "techanically" possible to not use them, in practice, they always find a way into your project, like it or not. And I choose not to like it. :)

      --

      f u cn rd ths, u r prbbly a lsy spllr.

  52. Re:Maybe the vendors don't want C++... by tjstork · · Score: 1

    Do you realise that most of the guts of Windows is actually written in C++? And that the secretary of the C++ Standards Committe, Herb Sutter, works for Microsoft?
    Are you even a C++ developer at all?

    Yes, I am a C++ developer, and I'm watching C++ languish on Windows. Half of the new stuff Microsoft comes out won't even work with native code any more. Where's WPF bindings for native C++? Or how about WCF? All of the new technology initiatives are based on .NET.

    Sure, Microsoft might be on the committee, and sure Microsoft might be adding a few features to Visual C++, but that's not where the company is headed.

    --
    This is my sig.
  53. Re:BIG need to dramatize by Jerry+Coffin · · Score: 2, Insightful

    Concepts in C++ should have had the same effect for Generic Programming in C++ that C++ had for Object Oriented Programming in C. The should have democratized generic programming and brought forth a renaissance in C++ library design. Instead, petty politics killed the most exciting change to C-like languages in years.

    I think you're overstating things a bit. It's certainly true that Concepts would have been an improvement, and would have made life a whole lot easier for a whole lot of people -- but let's face it, "renaissance" implies that we're currently in a dark age, and that's overstating things quite a bit. Point one, there's pretty substantial work being done right now. Point two, concepts are not going to allow an average programmer to just decide that they're going to recreate something like Spirit or Proto or Xpressive this afternoon, or anything like that.

    I also the think "petty politics" is going overboard, at best. Howard Hinnant seems to have been the one who started the discussion at the last meeting that ultimately led to the removal of concepts from the draft standard -- and I find an accusation of his being involved with petty politics completely unbelievable. Quite the contrary, the (admittedly few) times I've talked with him, he struck me as a very level-headed person who was careful to evaluate ideas on their merits. Likewise, Beman Dawes, Bjarne himself, and (since you brought him up) Dave Abrahams don't seem to me exactly "petty politics" kinds of people either.

    I'd also note that when it came to a vote, the overwhelming majority of committee members voted to remove them -- including (for one example) Douglas Gregor, the primary author of ConceptGCC, and one of the coauthors of both N1758 and N1849 (the two versions of the Indiana Proposal).

    I think the vast majority of the committee simply believed that including concepts would delay the standard by a minimum of a couple years, and probably longer than that. A fair number of features originally intended to be included in C++0x have been removed for exactly the same reason, though quite a few others have localized enough effects that they're currently scheduled for a TR (Technical Report) rather than waiting for the next major update to the standard itself. Unfortunately, since they make fundamental changes to the type system, I don't think concepts can be added in the same way.

    *(Dave - I mean that in the nicest sense... you've done a great job with Boost (oh, we need to jam again, too)).

    I object your honor. Everybody knows a proper blues guitarist is short and fat, with black hair and a scraggly beard -- and this "Dave" is about as different from that as humanly possible! :-)

    --
    The universe is a figment of its own imagination.
  54. Re:BIG need to dramatize by loufoque · · Score: 1

    At a more fundamental level, a lot of the power in generic programming comes from the specializations that are possible when you meet type requirements. Right now, there is no way, outside the documentation, to state requirements and possible specializations.

    Sure there is. I do it just fine.
    See Boost.ConceptCheck for example (for now, the quality of the error messages is not very good, but I'll improve that whenever I have the time to do so). Instead of writing "requires SomeConcept<T, U...>" you write "BOOST_CONCEPT_REQUIRES(SomeConcept<T, U...>)" or "BOOST_CONCEPT_ASSERT(SomeConcept<T, U...>)" (depending on whether you want it in the signature or not).
    This is not fundamentally different and it does extensive type checking that is quite useful to find errors in generic programs.

  55. Re:BIG need to dramatize by Anonymous Coward · · Score: 0

    Currently, generic programming in C++ is supported through a number of template meta-programming patterns and practices, most of which exist as Boost tribal knowledge

    No.

    Meta-programming is not generic programming. Templates were meant strictly for the latter, but the fact that templates are Turing complete makes possible the former.

  56. Counter-opinion: too much political focus by Morgaine · · Score: 1

    The interviewer's questions did lack some tact and diplomacy, but they also contained some good insights that Stroustrup dismissed out of hand just because they weren't phrased in a politically-sensitive way.

    To my mind, Stroustrup is focussed more on maintaining a good diplomatic position than on producing a good language. The "best" C++ language is not the one that causes the least friction in the committee.

    And he is completely and utterly unable to see C++'s continued descent into becoming an unlearnable language.

    Maybe he needs to experience first-hand the collapse of a few commercial projects and the loss of time, effort and money through C++ complexity in order to shake up his wishful thinking a bit. Perhaps he's too close to the coal face to see the larger picture. Complexity causes failure.

    Programming in the large isn't about being clever. It's about being unclever, and hence producing maintainable code. That hasn't yet sunk in for our dear Bjarne.

    --
    "The question of whether machines can think is no more interesting than [] whether submarines can swim" - Dijkstra
  57. If hello world is the single worst thing by tepples · · Score: 1

    In any case, streams are a really poor example (or good, if you are after spreading FUD) - it's the single worst thing in terms of size of compiled code (and performance, actually) in the entire C++ standard library.

    There are programs that do nothing but call one method in this "single worst thing". C++ primers tend to push such programs as the first example of C++ code that someone ever reads.

    1. Re:If hello world is the single worst thing by shutdown+-p+now · · Score: 1

      There are programs that do nothing but call one method in this "single worst thing". C++ primers tend to push such programs as the first example of C++ code that someone ever reads.

      I would hope that people don't do embedded development after reading the first example of C++ code in their life. As a learning tool, it's perfectly fine. In fact, pretty much anywhere but in drivers and embedded, streams are fine as is. They may be overly bloated, but it simply isn't a big deal for most.

    2. Re:If hello world is the single worst thing by tepples · · Score: 1

      As a learning tool, it's perfectly fine.

      In other words: "<iostream> is like training wheels." I can live with that, as long as I don't get responses from the peanut gallery that "any I/O library but <iostream> is a Frankensteinian mix of C and C++".

  58. Re:BIG need to dramatize by jgrahn · · Score: 1

    It's only a big deal to certain programming groups and applications. The programming I do cannot use templates so generic programming is useless to me and removal of concepts is not a big deal at all.

    You do C++ programming and cannot use templates? How's that? Broken compiler/linker? A boss with irrational fears of anything younger than fifteen years? I cannot see any other reason; fear of code bloat is not a valid reason to ban /all/ templates, not even in tiny embedded systems.

    Note that templates isn't all about metaprogramming voodoo. It's also about some very simple, straightforward uses: small utility functions and classes which can make plain old C++ code more readable.

  59. Re:BIG need to dramatize by pnewhook · · Score: 1

    Because we do not do generic programming. There is no need of it. There is no need to go beyond the capabilities of a simple macro for the stuff I do.

    --
    Tesla was a genius. Edison however was a overrated hack who liked to torture puppies.
  60. Re:Counter-opinion: too much political focus by Jeremi · · Score: 1

    Programming in the large isn't about being clever. It's about being unclever, and hence producing maintainable code. That hasn't yet sunk in for our dear Bjarne.

    Let's imagine that poor deluded Bjarne follows your advice, sees the light, and realizes that C++ is a complicated mess. What would you have him do at that point? Lobby the C++ committee to strip out all the "difficult" features for the next version of C++, thereby creating a language called "C++" that nevertheless is incompatible with 80% of the C++ code that exists in the world, and guaranteeing that either nobody ever uses the new version, or that the C++ world gets forked into two opposing camps?

    Perhaps there is something you haven't realized yet as well -- that "learnability" is far from the only issue to consider when trying to improve a widely-used language. I think Bjarne is well aware of the many trade-offs that have to be made, and he has valid reasons for his decisions. But don't let that interfere with your armchair psychoanalysis.

    --


    I don't care if it's 90,000 hectares. That lake was not my doing.
  61. Subscript checking is cheap if done right. by Animats · · Score: 2, Informative

    Now, we damn well know that, barring memory corruption or a serious bug in the STL, that this won't overrun the boundaries of the container. So why should i be range-checked ten million times?

    It shouldn't. If the compiler, rather than the template library, knew about subscript checking, it could optimize much of it out. Most subscript checks in FOR loops can be hoisted out of the loop. Only a single check at loop entry is required, and that may resolve to a constant expression which is always true, eliminating the test entirely. Most C compilers today know how to hoist expressions and do basic strength reduction; that's why, for loops, pointer arithmetic and subscripts generate almost the same code in modern compilers.

    But because the language doesn't know how big arrays are, the compiler can't help out here.

    This is another price paid for papering over the problem with templates.

    1. Re:Subscript checking is cheap if done right. by Animats · · Score: 2, Informative

      See Optimizing Array Bounds Checks Using Flow Analysis. The Java JVM does some array bounds checking optimization. C and C++ don't, because the language doesn't know how big arrays are. And millions suffer because of that.

  62. C++ is a language of the past by Anonymous Coward · · Score: 0

    Modern languages need to be more flexible than c++. I have lost count of the number of companies I have contracted for who desperately struggle to make c++ a Functional, Array based language. They should use www.jsoftware.com (an APL) instead. That is the language of the future.

  63. c++ array len 2 ptr how to....apk by Anonymous Coward · · Score: 0

    "which says nothing about the size of the array. Right there is the cause of most buffer overflows - the language doesn't properly support talking about the size of arrays." - by Animats (122034) on Friday August 07, @02:49PM (#28989075) Homepage

    It's not that hard to determine the size of an array though... even in C++!

    HOW TO DETERMINE ARRAY SIZE/LENGTH, USING TWO POINTERS (1 is always DOUBLE the size of the other, 1st "++" vectors thru array, other is always double its size):

    ----

    1.) Make 2 pointers, starting @ the "Zeroeth array element" position (the start, in other words)

    2.) Advance the first by/to 1 & then, double the size of the 2nd pointer (to 2 in other words)

    3.) Then, advance the first one to 2, double the size of the 2nd pointer (to 4 in other words)

    4.) Continue this, always advancing the first pointer ++ by 1, & keeping the 2nd pointer DOUBLE ITS SIZE... do this, until the 2nd pointer can no longer advance... THIS YIELDS THE ARRAY's MIDPOINT!

    5.) Simply doubling the midpoint will yield the total # of array elements, & thus, its size...

    ----

    THAT'S HOW YOU CAN DETERMINE THE SIZE OF ANY ARRAY (or string) AND ITS LENGTH/SIZE - this "generic algorithm" works for that!

    APK

    P.S.=> AND, w/out using functions like StrLen (strings.h), for string lengths in NULL strings or otherwise (strings are, after all, nothing more than "Character Arrays" anyhow)... apk

  64. Re:Maybe the vendors don't want C++... by spitzak · · Score: 1

    A few points because I have also had to deal with those warnings:

    Microsoft wrote and forced through that standard.

    At the time they wrote it, other solutions like strlcpy were FAR more popular, and still are, yet they ignored them and purposely wrote an alternative with different behavior and the argument order rearranged.

    The behavior of truncating the destination buffer to an empty string on error is quite useless and can destroy data in the strcat replacement.

    They produce the "unsafe" warning for strncpy, which actually is not any less safe then their alternative.

    They do not produce the "unsafe" warning for thousands of other calls that can overwrite buffes, only mysteriously for a subset that happens to be in the cross-platform library.

    They produce the "unsafe" warning if you use any kind of macro to make _snprintf be called "snprintf" but don't do this if you directly call their function and thus have an unportable program.

  65. Re:Maybe the vendors don't want C++... by shutdown+-p+now · · Score: 1

    Microsoft wrote and forced through that standard.

    I've seen other company names backing it. Do you have any references to back up the "forcing it through" claim?

    Besides, the spec was made by WG14, which are the same guys that make the ISO C standard itself. It's not the phony OOXML committee - it actually has balanced representation from various C implementors (including e.g. Apple and IIRC someone from RedHat to speak for gcc) - pushing something through would be damn hard unless you manage to convince committee members that it's a good idea - but then it isn't really "pushing" anymore, is it?

    At the time they wrote it, other solutions like strlcpy were FAR more popular, and still are, yet they ignored them and purposely wrote an alternative with different behavior and the argument order rearranged.

    I haven't seen any code using strlcpy on Win32 in my practice. For that matter, I've heard that it doesn't have high acceptance on Linux, either. In any case, the design goals of strcpy_n are different from strlcpy.

    The behavior of truncating the destination buffer to an empty string on error is quite useless and can destroy data in the strcat replacement.

    The idea of those functions isn't to do any sort of auto-truncating, as e.g. strncpy or strlcpy do. The idea is to catch constraint violations immediately. Which is why the correct usage is to set a runtime constraint violation handler immediately upon the start of the program that will complain noisily and terminate - the same kind of behavior you get from varions string methods in Java or C# when you use out-of-bounds indices and such. In fact, the spec provides abort_handler_s precisely for that purpose. Note also that the default behavior on constraint violations is implementation defined: "The implementation has a default constraint handler that is used if no calls to the set_constraint_handler_s function have been made. The behavior of the default handler is implementation-defined, and it may cause the program to exit or abort." - the clear intent here is to use some standard error-reporting facilities, such as the usual exception/error crash report dialog on Windows. So, normally, you wouldn't ever see that truncated buffer.

    They produce the "unsafe" warning for strncpy, which actually is not any less safe then their alternative.

    strncpy does not always null-terminate, which is extremely error prone - it's why strlcpy was made, after all!

    They do not produce the "unsafe" warning for thousands of other calls that can overwrite buffes, only mysteriously for a subset that happens to be in the cross-platform library.

    Examples?

    I know for sure that a bunch of Win32 functions were similarly "deprecated" for the same safety reasons, and strsafe.h devised as a replacement.

    They produce the "unsafe" warning if you use any kind of macro to make _snprintf be called "snprintf" but don't do this if you directly call their function and thus have an unportable program.

    I just tried this, and I don't get a warning regardless of whether I call _snprintf directly, or "#define snprintf _snprintf" and then call snprintf. I don't see how the behavior you describe is possible at all, since "deprecation" warning modifiers are applied directly to function definitions, and VC headers simply don't contain a definition of snprintf.

    As for why _snprintf doesn't produce a warning - it looks like a bug of omission, and not something deliberate. It is properly documented as "deprecated as unsafe" in MSDN, and other similar functions, such as _vsnprintf, do produce the warning.

  66. Re:Maybe the vendors don't want C++... by spitzak · · Score: 1

    strlcpy does indeed return a clear "failure" result, because it returns the length of buffer that would be needed. This can be tested on the return value, and also provides information on exactly what needs to be done by the program to fix it.

    Here is an example of how to use it, as some people do not seem to understand strlcpy at all. No other function design lets you do this. (in case you don't understand this, please assume this is a function that needs to be very fast and that the programmer knows that 99.99999% of the time the string is less than 200 characters):


        func() {
            char localbuffer[200];
            char* bufferpointer;
            int n = strlcpy(localbuffer, x);
            if (n > 200) {
                bufferpointer = new char[n];
                strcpy(bufferpointer, x);
            } else {
                bufferpointer = localbuffer;
            do_something(bufferpointer);
            if (bufferpointer != localbuffer)
                delete[] bufferpointer;
        }

    This is immensely more useful than strcpy_s and strncpy.

    strlcpy is used in Linux, thousands and thousands of times. It is also used in Windows software just as much. The fact that Ulrich Depper hates strlcpy does not give an excuse for Microsoft. Yes there are asshats in Linux but that does not mean you can't complain about them also being at Microsoft.

    Actually _snprintf *DOES* produce a warning, unless they changed things more recently. My mistake. We did have some problem with macros but the switch to turn off the warnings did work for all of the interesting ones. There was some warning about the use of varargs that was unavoidable but is a different bug in vc++.

    The default behavior for the strcpy_s error handler is to return, with the buffer truncated. Since programs don't change this (and they can't if any library routines are relying on the behavior) then any theoretical advantages you list are moot.

  67. Re:Maybe the vendors don't want C++... by shutdown+-p+now · · Score: 1

    The default behavior for the strcpy_s error handler is to return, with the buffer truncated.

    First of all, the default behavior in the spec is implementation defined (I've already quoted the relevant part in my previous post). Any code that relies on any particular behavior without setting its own handler (or ignore_handler_s) is simply broken. Any library that relies on any definite behavior is even more broken, as the whole purpose of the thing is to let the application override this behavior. Libraries should not assume that they will ever get control back if they try to overflow the buffer, but should also check return values for error codes as specified (in case the current behavior is to return control).

    Simply put, all *_s functions are supposed to work the same way preconditions generally work in Design by Contract. It is caller's responsibility to ensure that precondition holds; the point of the check in the callee is not to work around this fact and somehow "fix" it (e.g. by truncating), but to immediately report the contract violation so that caller can be fixed.

    As for default VC behavior specifically, I've just tried this on VC9 and VC10:

    #include <string.h>
    int main() {
        char s[10];
        strcpy_s(s, 1, "foo");
    }

    It doesn't quietly return with buffer truncated. Rather, it produces a debug assertion with a message "Buffer is too small", and if you ignore that (or if you compile in release mode, so assertion doesn't get compiled in), it launches the usual Windows fatal error reporting procedure (Watson), which asks to attach the debugger if one is registered on the system, and terminates the process otherwise. Note that the latter happens even if compiled in release mode.

  68. Re:Maybe the vendors don't want C++... by spitzak · · Score: 1

    The standard docs pretty clearly state that the default error hander does nothing and returns to the function, and that the strcpy_s function truncates the buffer and then returns after the error handler returns.

    http://www.open-std.org/jtc1/sc22/wg14/www/projects#24731

    I never actually tried calling these things as I want to write portable software.

    Anyway I don't see how a DOS is much better than a buffer overflow.

  69. Re:Maybe the vendors don't want C++... by shutdown+-p+now · · Score: 1

    The standard docs pretty clearly state that the default error hander does nothing and returns to the function, and that the strcpy_s function truncates the buffer and then returns after the error handler returns.

    Okay, let's try this again. Here is the most recent draft. Look at 6.6.1.1 "The set_constraint_handler_s function", paragraphs 2 and 4. Here's what it says:

    2 The set_constraint_handler_s function sets the runtime-constraint handler to be handler. The runtime-constraint handler is the function to be called when a library function detects a runtime-constraint violation. Only the most recent handler registered with set_constraint_handler_s is called when a runtime-constraint violation
    occurs.

    4 The implementation has a default constraint handler that is used if no calls to the set_constraint_handler_s function have been made. The behavior of the default handler is implementation-defined, and it may cause the program to exit or abort.

    And also 6.1.4 "Runtime constraint violations":

    2 Implementations shall verify that the runtime-constraints for a function are not violated by the program. If a runtime-constraint is violated, the implementation shall call the currently registered runtime-constraint handler (see set_constraint_handler_s in ). Multiple runtime-constraint violations in the same call to a library function result in only one call to the runtime-constraint handler. It is unspecified which one of the multiple runtime-constraint violations cause the handler to be called.

    3 If the runtime-constraints section for a function states an action to be performed when a
    runtime-constraint violation occurs, the function shall perform the action before calling the runtime-constraint handler. If the runtime-constraints section lists actions that are prohibited when a runtime-constraint violation occurs, then such actions are prohibited to the function both before calling the handler and after the handler returns.

    4 The runtime-constraint handler might not return. If the handler does return, the library function whose runtime-constraint was violated shall return some indication of failure as given by the returns section in the functionâ(TM)s specification.

    I hope this is clear enough. I expect that you've just looked at the individual description of strcpy_s, and didn't find anything about runtime violations; but the paragraphs cited above apply to all functions for which there's a "runtime constraints" section.

    I never actually tried calling these things as I want to write portable software.

    But you do use strlcpy. I don't see how this is any different - in both cases, if you want to be portable, you have to use a third-party implementation on all platforms where this functionality isn't available out of the box (as neither is included in the base standard for the language). And yes, there is an independent, open-source (MIT license), cross-platform implementation of TR 24731 - the Safe C Library.

    Anyway I don't see how a DOS is much better than a buffer overflow.

    Well, it's obvious - a buffer overflow is a potential high-risk security exploit, while a DoS is just a DoS.

    Anyway, the philosophy is that if there is a problem in your application, it should be made obvious as early as possible. With strlcat, there are all kinds of interesting possibilities - perhaps someone used it but didn't check the error code, and, in fact, didn't bother to handle the truncation case specially at all. Depending on the circumstances, this may lead to a crash or other form of DoS down the line (e.g. when trying to parse the buffer expecting well-formed data, since it was already validated before the call to strlcat), but worse, it may lead to silent wrong behavior - imagine trun

  70. Re:Maybe the vendors don't want C++... by spitzak · · Score: 1

    I certainly did read 6.1.4.4, which is why I thought the default behavior was for the error handler to return. Certainly the description of strcpy_s implied that it returned because it spent some time describing exactly the value it returned.

    In any case I think you are underestimating the problem with the buffer being truncated to zero length. In your rm example, it is certainly plausable that it will now remove the ENTIRE DISK, because "" may be the name of the root filesystem. If you don't believe this, try looking at real code, concatenating a slash is really common. I greatly prefer the strlcpy result where the chances of hitting an actual filename are somewhat lower.

    I also think you are missing the fact that the DOS is likely to happen when the program is in use and that it could be far worse than the buffer overflow. The buffer overflow will probably crash, and may not be exploitable. The DOS is GUARANTEED to happen.

    The biggest problem is that everybody seems to ignore the fact that strlcpy returns a clear error indicator that contains useful information and that it is useful for actual fast code. If you are unconcerned about speed it is nonsense to use char* pointers at all, use some safe string object, this is another reason why I think warningsencouraging you to replace strcpy with some other slightly safer call is wrong, as it justs wastes programmers time when they should be doing a true replacement, or figure out how to use strlcpy correctly.

    Anyway, none of my complaints is about the _s functions, except they seem to be typical crap designed by committee. My complaint is about Microsoft putting warnings into their code to try to force people to alter it to be non-portable, that is pretty insidious and inexcusable.

  71. Re:Maybe the vendors don't want C++... by shutdown+-p+now · · Score: 1

    In any case I think you are underestimating the problem with the buffer being truncated to zero length. In your rm example, it is certainly plausable that it will now remove the ENTIRE DISK, because "" may be the name of the root filesystem.

    Quite likely, but if I'm going to use the *_s functions, I'd set up my own handler anyway which would ensure no-return (and thus the whole issue of what the buffer ends up with is moot).

    I also think you are missing the fact that the DOS is likely to happen when the program is in use and that it could be far worse than the buffer overflow. The buffer overflow will probably crash, and may not be exploitable. The DOS is GUARANTEED to happen.

    Well, that's kinda the point - as I mentioned earlier, I'd rather very much have any (potentially) incorrect behavior like that signaled ASAP, rather than it continue to run silently. In that sense, I wouldn't actually mind strlcat if it was called strlcat_trim_to_fit or something like that. But for plain concatenation, I don't want it to second-guess me.

    The biggest problem is that everybody seems to ignore the fact that strlcpy returns a clear error indicator that contains useful information and that it is useful for actual fast code. If you are unconcerned about speed it is nonsense to use char* pointers at all, use some safe string object, this is another reason why I think warningsencouraging you to replace strcpy with some other slightly safer call is wrong, as it justs wastes programmers time when they should be doing a true replacement, or figure out how to use strlcpy correctly.

    I can actually agree on that - strlcpy is clearly handy in that it lets one avoid the extra strlen call for when allocation is needed (as one has to do with strcpy_s). And I definitely consider all these solutions to be very much deficient, and the proper way to tackle this is to ditch null-terminating strings entirely and use ones with explicit length, a la Pascal/Java/C#. Extra 4 bytes are well worth the added convenience, it's much safer (as you always know the lengths in advance, and can always allocate exactly as much as needed without overhead of scanning the string to figure it out), and it can often improve performance as well, depending on what is done with the string. I consider both strlcpy and strcpy_s to be the last resort measures.

    Ideally, of course, I'd just write the whole thing in C++, and use the string classes.

    My complaint is about Microsoft putting warnings into their code to try to force people to alter it to be non-portable, that is pretty insidious and inexcusable.

    It should be noted that warnings aren't actually displayed by the compiler itself by default (i.e. "cl foo.c" with no compiler switches will not give "deprecation" warnings). The reason is that it's actually a level-3 warning - the default is level-1. Visual Studio does set warning level to 3 by default, however, so VC++ projects created in it display this.

    On the other hand, the error message, while confusingly using the term "deprecated", clearly indicates that this check can specifically be turned off, and even explains how:

    warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

    Even so, it could definitely explicitly mention that the proposed strcpy_s alternative is not ISO C/C++ conformant, both in the error message text, and in the documentation for it.

  72. Re:Maybe the vendors don't want C++... by spitzak · · Score: 1

    the proper way to tackle this is to ditch null-terminating strings entirely and use ones with explicit length, a la Pascal/Java/C#. Extra 4 bytes are well worth the added convenience, it's much safer (as you always know the lengths in advance, and can always allocate exactly as much as needed without overhead of scanning the string to figure it out), and it can often improve performance as well, depending on what is done with the string.

    A big advantage you forgot to mention is that all possible byte values (ie 0) can be put into the string.

    Pascal (for most of it's history, at least) used 1-byte counts so the string length was limited to 256 bytes. Until about 1990 it seems nobody thought it logical to waste 3 bytes storing the length, so everybody saw the choices as either limiting string length to 256 or not allowing nul, and everybody chose the latter.

    On current machines it makes perfect sense to use a length. If you want to save memory and have so many small strings that the space wasted by the length makes a significant difference, you can save far more memory by using either a hash table (because you must have lots of duplicates) or some cryptic compressed encoding.

    One advantage C strings have however is that the operation "return the tail of the string" is O(1). This is not true for any other string representation. This does not sound like a big deal but a lot of software depends on it for speed and this has derailed previous attempts to rewrite things away from C strings or into other languages.

  73. Can't always fall back on the shared library by tepples · · Score: 1

    So that's 11K for the C++ version

    Using iostream and other space-intensive C++ library features makes sense if you can rely on the presence of a shared library implementing the C++ standard library as part of the platform. But because PCs running Windows and embedded systems generally do not include a copy of shared GNU libstdc++, it would have to be distributed with each program, either as a .dll or statically linked into the executable. How big is libstdc++.so.* on your system?

    1. Re:Can't always fall back on the shared library by Anonymous Coward · · Score: 0

      Agreed. I assumed the presence of a shared standard c++ library.

      On Windows, I'd say the discussion is a moot point. Windows already ships with a C/C++ Runtime. And considering the availability of VS Express, using GCC on Windows does not make much sense.

      Now, for embedded systems this a complete different discussion. But then again, it's not as bad as some people here have tried to claim it is (there are embedded/light versions of the C++ standard library).

      Out of curiosity, are there many embedded system that have a decent enough C++ compiler, and yet that don't have enough space for having even a bloated libstdc++.so?

    2. Re:Can't always fall back on the shared library by tepples · · Score: 1

      Windows already ships with a C/C++ Runtime.

      In that case, if MinGW uses the C runtime that comes with Windows (msvcrt.dll), then why doesn't MinGW use the C++ runtime that comes with Windows?

      And considering the availability of VS Express, using GCC on Windows does not make much sense.

      OK then: Windows Mobile. The Windows Mobile SDK does not work with Visual Studio Express, only the paid versions of VS.

      Out of curiosity, are there many embedded system that have a decent enough C++ compiler, and yet that don't have enough space for having even a bloated libstdc++.so?

      STL isn't all that bloated, but iostream can be. A lot of these embedded systems don't even have a .so or .dll loader, but they can use STL containers with little size penalty.