Thread: C++++

  1. #1
    Shadow12345
    Guest

    C++++

    From C we went to object oriented programming. No language is perfect, but C++ seems to be the most accomodating of any. What will happen after C++? What will be added onto the new language, if it ever comes out? What changes would YOU like to see made to C++? I have read posts catering to some flaws with object oriented programming (having, I think to do with multiple inheritance, Davros made a lengthy paper on this, but I don't remember the problems specifically).

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    I don't really see any problems with multiple inheritance.

    The "problem" I see is the fact that there is no separation between the datatypes pointer to method, and pointer to virtual method.

    Without the differentiation it makes it literally impossible in C++ to call a version of a virtual function from a parent of the class by using a pointer to a virtual method on a child.

    I would suggestseparating it into 3 types
    1) non-virtual member function pointers -- which have similar qualities as function pointers, except they act on objects
    2) virtual member function pointers -- which work with polymorphism
    3) all encompasing member function pointers -- this is the standard type right now, one which can point to both kinds, but forces dynamic binding on virtual methods

    The types would all be related in a way similar to inheritance:

    a non-virtual member function pointer can be converted to an all-encompasing member function pointer but NOT to a virtual member function pointer

    a virtual member function pointer can be converted to an all-encompasing member function pointer but NOT to a non-virtual member function pointer

    an all encompasing member function pointer can be converted to neither non-virtual nor virtual member functions

    EDIT: Another thing that I think would be very useful is templated typedefs. There are ways right now of working around that problem (nesting a typedef in a templated class), but there is no logical reason why templated typedefs can't be directly supported by the language

    EDIT2: Also, just pointing out that the topic name isn't valid C++ code because C++ doesn't return an l-value which is a requirement for both types of operator++.
    Last edited by Polymorphic OOP; 01-15-2003 at 04:41 PM.

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Have you worked with any other OO langauge than C++? It's probably the least programmer friendly object orientated langauge there is.

    I'd like to see Andrei Alexandrescu design a langauge for generic programming, perhaps based off of C++.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    C++ sacrifices "programmer friendliness" for functionality.

    Other languages make things "easier," but they limit what you can do. It's a double-edged blade.

    For instance -- java makes things "simpler" by making absolutely no methods statically bound, and it is not capable of multiple inheritance. Sure, it makes it "easier to program," but it completely ignores a lot of other functionality that is provided in C++.

  5. #5
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    I think C++ sacrifices programmer friendliness for speed and compatibility with C, not functionality. If you want to take advantage of polymorphism, you must use dynamic memory.

    The multiple inheritance tradeoff was more of a balance for average uses. It is generally pretty ugly, and the langauge designers felt that getting rid of all the ugly cases was worth cutting off the rare times when it is the cleanest design.

    http://www.javaworld.com/javaqa/2002...heritance.html

    I've personally never used MI of two non-abstract classes.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  6. #6
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    C++ needs some kind of modules/units system built into the language (like Java or Pascal).

    No modern language should have to use preprocessor hacks:
    Code:
    #ifndef UNIQUE_LONG_NAME_123419112
    #define UNIQUE_LONG_NAME_123419112
      #include "whatever.h"
    #endif

    BTW, how often do you advanced/intermediate C++ programmers actually use multiple inheritance? I never do that "irl".
    Last edited by Sang-drax; 01-15-2003 at 06:18 PM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  7. #7
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I also think the C++ standard library is too small. It should be extended.
    Just look at the Java standard library: everything is there! (threads, gui, etc.)

    Currently, you can do almost nothing with plain C++; you have to download custom libraries and/or code unless you want to reinvent the wheel over and over.

    Thread support should definatly be a part of the language (synchronizing, exceptions).
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  8. #8
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    I completely agree with Sang-drax, the C++ standard while good now could be and should be enlarged.

  9. #9
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    Originally posted by Polymorphic OOP
    For instance -- java makes things "simpler" by making absolutely no methods statically bound,
    What do you mean by this? In java you can have static methods. But maybe i'm just misreading your comment.

  10. #10
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    He means that every method in Java is implicitly marked as 'virtual'.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Bleh, The C++ standard library is fine how it is. This isn't java, C++ is not completely portable. You have not really solved very much by making the standard larger. You put weight on the library makers for having to create whole new thread interface, widget set, etc. What makes you think they will choose the right one?

    I think the standard is large enough and does it's job fine.

  12. #12
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by SilentStrike
    If you want to take advantage of polymorphism, you must use dynamic memory.
    That's not true at all. You don't have to use ANY dynamic memory allocation to use polymorphism.

    And if you personally don't like multiple inheritance, there is nothing written that says you HAVE to use it. Don't use it if you don't want to.

    Originally posted by beege31337
    What do you mean by this? In java you can have static methods. But maybe i'm just misreading your comment.
    No, not static methods, statically bound method calls. As Sang-Drax restated, I was referring to the fact that all methods that can be "virtual" (in C++ terms) are made virtual.

  13. #13
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You can create objects on the stack and then pass their address to polymorphic functions, that may be reasonably useful. But you cannot do things like use a std::vector<base> polymorphically, which would be very useful.

    Polymorphism and memory management are almost always coupled in C++.

    I believe final will allow for static of a method resolution in the just in time compilition stage of a JVM.

    http://www.javaperformancetuning.com/tips/final.shtml

    But that is just a speed issue, not a 'This let's me write clear code' issue.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  14. #14
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    firstly if you want to you can always statically bind just by using an object instead of a pointer. Then you have static binding. Are you too lazy to simply dereference a pointer if you want static binding?
    Threads should not be part of c++ in my opinion. They are a function of the operating system and so belong in an API.Adding them to c++ would in no way make multithreaded programming any simpler except maybe a little less coding required especially if you target more than one operating system.
    As for additions to c++ I think the two most obvious additions at the next standards review will be the BOOST library and Andrei Alexandrescus wonderful Loki library as soon as compilers catch up to him!
    As for c++ as it stands I think they should do away with the export keyword because even if they finally make a compiler that fully supports it,it doesnt really do what it was introduced to do and professional developers will almost certainly ignore it even more than goto.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  15. #15
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by SilentStrike
    You can create objects on the stack and then pass their address to polymorphic functions, that may be reasonably useful. But you cannot do things like use a std::vector<base> polymorphically, which would be very useful.
    That's no different in Java, it's just that in Java you are forced to work with pointers and dynamic memory allocation, but it hides it from you. While polymorphism often times is used in conjunction with dynamic memory allocation, it's not always the case. There's nothing stopping you from creating a templated PolymorphismHandler class which would handle encapsulating a pointer and performing dynamic memory allocation for you so that one can be oblivious to implementation like in Java, but you also get the ability to work on a lower level as well. That's what I do and it works just fine, but you don't want to do that in all situations.

Popular pages Recent additions subscribe to a feed