Thread: C++ violates, what does it mean?

  1. #1
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246

    Question C++ violates, what does it mean?

    Quote Originally Posted by http://www.adahome.com/Resources/Languages/contrast_ada_cpp.html
    C++ violates the separation of contract and implementation when inline functions are declared.
    Ada does not.
    What does it mean?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    This is a class contract:
    Code:
    class X {
      public:
        X(int);
        ~X();
        int foo();
        int get_int();
        void set_int();
      private:
        int x;
    };
    Say for example that I wanted to inline foo(), for some reason. I could define the function in the class contract to achieve that; therefore, I've violated a common style guideline that states you should keep implementation of a class and definition of a class separate. I find it a weak argument, but that's me.

    In fact the whole way that page makes its point bothers me.
    Last edited by whiteflags; 09-15-2006 at 04:08 AM.

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    In fact the whole way that page makes its point bothers me.
    Of course it is Ada site. ;-)
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Particularly considering we can still define the function outside the class body. Inlined or not.

    Besides...

    55. C++ is widely used.
    Ada is not.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    C++ does that! Ada does this!
    <unstated>And Ada must be better because of this!</unstated> Okay, but write something the critical reader can appreciate.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > C++ violates the separation of contract and implementation when inline functions are declared.
    That's the least of the problems - the fact that C++ classes have to list their private parts in the class for all the world to see should be more of a concern.

    I suppose you could do this
    Code:
    class foo_private;
    class foo {
      public:
        foo();
        ~foo();
      private:
        foo_private *private;
    };
    Where only foo.cpp implementation files get to include foo_private.h and all the things it offers.

    On the plus side, this may help to stop rebuild cascades when you change some base class and EVERYTHING has to be rebuilt because of it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That "Comparison of Ada and C++ Features" was done before C++ was standardised, so it is out of date.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by Salem
    I suppose you could do this
    Also known as the PIMPL idiom and widely used.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed