learn C++ or C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Larry Smith

    #91
    Re: learn C++ or C#

    Multi-threading, GUI development is much easier in most of the other
    languages compared to the efforts you have to take in C++, because they
    support it out of the box. Fortunately C++ has Boost.
    To be fair, this has nothing to do with C++ as a language (which has no
    support for multi-threading or GUI whatsoever). You have to separate the
    tools from the language itself.
    The only programming paradigm I miss in the other languages is RAII.
    That's IMHO still a big plus of C++.
    RAII is also vastly superior to "IDispose" and "using" statements. OTOH,
    ..NET advocates will point out that the GC takes care of cleaning most
    resources so the programmer has to do nothing at all. IMO the C++ paradigm
    is still a better design but the reasons run too deep to get into here.
    A simple example:
    >
    How do I ensure in C++ that I have successfully overridden a base class
    virtual function and that the compiler throws an error if the base class
    implementation has changed ?
    C++ has many warts, many a legacy of C itself. From cast issues (very
    dangerous) to forgetting to handle newly added class members in your
    existing copy constructors and copy assignment operators. Templates are also
    an incredible source of difficulty and potential errors (very difficult to
    understand, read, and get right beyond the basics - some things will be
    improving in C++0x but it's really too late). The use of #includes and
    headers in general (from C) is also a hornets nest of serious problems. Not
    to mention the usual issues of pointer handling, the cryptic nature of the
    syntax itself (from C style arrays to function pointers to many types of
    arcane C++ constructs like binders, adapters, etc. - did I mention
    templates?). The dizzying array of rules and trap doors in general is very
    difficult to master.

    I also have some serious pet peeves. Why didn't they permit local classes to
    be passed as template arguments. I once asked Stroustrup about this at a
    conference but I wasn't satisfied with his terse response. The fact is that
    many templates are useful for small local tasks. Why should I use the
    "for_each" template for instance (among many others) if the tiny function
    object I want to pass has to be declared outside the function itself (where
    I'm using "for_each") . It would be so much cleaner to just declare the
    function object locally. C# allows me to use anonymous methods which is so
    much cleaner. The issues surrounding C++ go on and on.

    Don't get me wrong, C++ is still a very powerful and flexible language with
    incredible versatility (and very elegant design constructs in spite of all
    the problems). The trade-off is that it's very difficult to master and
    therefore prone to many serious problems. Even very experienced developers
    have to continuously bend their minds out of shape and remain on guard years
    after learning the language. This is not the hallmark of a successful
    language in spite of C++'s "stellar" reputation and the millions who
    continue struggling with it.


    Comment

    • Giovanni Dicanio

      #92
      Re: learn C++ or C#


      [Larry Smith]
      >The only programming paradigm I miss in the other languages is RAII.
      >That's IMHO still a big plus of C++.
      >
      RAII is also vastly superior to "IDispose" and "using" statements. OTOH,
      .NET advocates will point out that the GC takes care of cleaning most
      resources so the programmer has to do nothing at all.
      The GC is fine for memory resources - it runs a garbage collection process
      when under memory pressure.
      But, what about non-memory resources (like sockets, textures, files, etc.) ?
      I think that GC is designed for memory resources only, and has very little
      clue about non-memory resources.

      Instead, if you use RAII and a smart pointer (like shared_ptr, or some
      intrusive reference count smart pointer) to manage non-memory resources,
      they will be released as soon as the ref count becomes 0, making a very
      efficient use of precious resources.

      Yes, C# is a very well designed language, which incorporates lots of lessons
      learned from C++, Java and Visual Basic.
      But C# has not discovered destructors yet :)

      Giovanni



      Comment

      • Larry Smith

        #93
        Re: learn C++ or C#

        The GC is fine for memory resources - it runs a garbage collection process
        when under memory pressure.
        But, what about non-memory resources (like sockets, textures, files, etc.)
        ?
        I think that GC is designed for memory resources only, and has very little
        clue about non-memory resources.
        Yes, that's what "IDisposabl e" is for as previously mentioned. The "using"
        statement is just a compiler-generated wrapper around it, putting your code
        in a "try/finally block behind the scenes and calling
        "IDisposable.Di spose()" for you. RAII is clearly much better than this.
        Instead, if you use RAII and a smart pointer (like shared_ptr, or some
        intrusive reference count smart pointer) to manage non-memory resources,
        they will be released as soon as the ref count becomes 0, making a very
        efficient use of precious resources.
        >
        Yes, C# is a very well designed language, which incorporates lots of
        lessons learned from C++, Java and Visual Basic.
        But C# has not discovered destructors yet :)
        Actually it has destructors but they're not the same as C++ destructors
        (they're just compiler-generated wrappers for "Object.Finaliz e()"). I
        already agree that object creation/destruction in C++ is cleaner and more
        natural IMO. This hardly makes up for the many problems in C++ however. Like
        many others, I have a love/hate relationship with it but objectively
        speaking (IMO anyway), it's still a failure for the reasons I mentioned
        previously.


        Comment

        • Andre Kaufmann

          #94
          Re: learn C++ or C#

          Larry Smith wrote:
          >Multi-threading, GUI development is much easier in most of the other
          >languages compared to the efforts you have to take in C++, because they
          >support it out of the box. Fortunately C++ has Boost.
          >
          To be fair, this has nothing to do with C++ as a language (which has no
          support for multi-threading or GUI whatsoever). You have to separate the
          tools from the language itself.
          I don't think so. What would C++ be without the standard library ?

          And that GUI development is easier in other languages has IMHO something
          to do with the language. C++ isn't IMHO fast enough in compilation to be
          a good RAD language - at least you don't have the same developing
          experience in C++ as in other languages.
          [...]
          RAII is also vastly superior to "IDispose" and "using" statements. OTOH,
          Yes. Using is fine if I hold a resource in a control block, but if the
          resource is held by let's say multiple lists, I have to use some kind of
          smart pointers to handle the resources efficiently. In C# I can rely on
          the GC to free the memory - so far that's fine. But resources should be
          freed immediately, if they aren't used anymore.
          .NET advocates will point out that the GC takes care of cleaning most
          resources so the programmer has to do nothing at all. IMO the C++ paradigm
          is still a better design but the reasons run too deep to get into here.
          >
          >
          [...]
          understand, read, and get right beyond the basics - some things will be
          improving in C++0x but it's really too late). The use of #includes and
          headers in general (from C) is also a hornets nest of serious problems. Not
          I don't think that it's too late, C++ modules could fix many problems.
          But since they aren't in the upcoming standard I perhaps have to agree -
          it will be too late.
          [...]
          Andre

          Comment

          • Peter Duniho

            #95
            Re: learn C++ or C#

            On Thu, 24 Jul 2008 06:43:30 -0700, Giovanni Dicanio
            <gdicanio@_nosp am_email_dot_it wrote:
            [Larry Smith]
            >
            >>The only programming paradigm I miss in the other languages is RAII.
            >>That's IMHO still a big plus of C++.
            >>
            >RAII is also vastly superior to "IDispose" and "using" statements. OTOH,
            >.NET advocates will point out that the GC takes care of cleaning most
            >resources so the programmer has to do nothing at all.
            >
            The GC is fine for memory resources - it runs a garbage collection
            process
            when under memory pressure.
            But, what about non-memory resources (like sockets, textures, files,
            etc.) ?
            I think that GC is designed for memory resources only, and has very
            little
            clue about non-memory resources.
            This distinction has nothing to do with the _language_. If the OS was
            entirely garbage collected, then these "non-memory resources" wouldn't be
            an issue. They would be managed the same way memory is in .NET and you'd
            never have to worry about disposing them.

            Now, with certain types of objects you'd still have to deal with closing,
            flushing, etc. But that's not something that RAII inherently solves; it
            just happens that C++ classes can take advantage of that to handle those
            operations. The OS API itself isn't based on C++ and requires the program
            to deal with managing those operations.

            In C++, RAII provides a convenient way to deal with that, and in C#, the
            "using" statement does the same. You may prefer one syntax over the
            other, but I personally don't see a difference between the two that would
            justify an argument of superiority one way or the other. Larry's claim of
            "vastly superior" seems particularly baseless. Vastly? Pure hyperbole.

            Pete

            Comment

            • Larry Smith

              #96
              Re: learn C++ or C#

              >>Multi-threading, GUI development is much easier in most of the other
              >>languages compared to the efforts you have to take in C++, because they
              >>support it out of the box. Fortunately C++ has Boost.
              >>
              >To be fair, this has nothing to do with C++ as a language (which has no
              >support for multi-threading or GUI whatsoever). You have to separate the
              >tools from the language itself.
              >
              I don't think so. What would C++ be without the standard library ?
              It would be another language since it must include the library by
              definition. Contrast this to C# whose basic support is primitive (see the
              standard for yourself). In any case, the claim that GUI development is
              "easier" in C# compared to C++ has nothing to do with the languages
              themselves. It's the rich set of classes in MSFT's framework combined with
              better development tools that make C# easier (noting that C# is a natural
              fit for the framework unlike C++). Provide an equivalent C++ library and
              better tools and it will be just as easy (not taking into account the actual
              language differences).
              And that GUI development is easier in other languages has IMHO something
              to do with the language. C++ isn't IMHO fast enough in compilation to be a
              good RAD language - at least you don't have the same developing experience
              in C++ as in other languages.
              >
              >[...]
              >RAII is also vastly superior to "IDispose" and "using" statements. OTOH,
              >
              Yes. Using is fine if I hold a resource in a control block, but if the
              resource is held by let's say multiple lists, I have to use some kind of
              smart pointers to handle the resources efficiently. In C# I can rely on
              the GC to free the memory - so far that's fine. But resources should be
              freed immediately, if they aren't used anymore.
              The "using" statement is ugly compared to RAII. Moreover, in theory your
              unmanaged resources may never be released if you neglect to call
              "IDisposable.Di spose()". Other problems also exist with this pattern.
              >
              >.NET advocates will point out that the GC takes care of cleaning most
              >resources so the programmer has to do nothing at all. IMO the C++
              >paradigm
              >is still a better design but the reasons run too deep to get into here.
              >>
              >[...]
              >understand, read, and get right beyond the basics - some things will be
              >improving in C++0x but it's really too late). The use of #includes and
              >headers in general (from C) is also a hornets nest of serious problems.
              >Not
              >
              I don't think that it's too late, C++ modules could fix many problems. But
              since they aren't in the upcoming standard I perhaps have to agree - it
              will be too late.
              The core language is in place. Enhancements won't change that. The problems
              inherent in C++ will remain forever unless it morphs into a different
              language (but then it won't be C++ anymore).


              Comment

              • Giovanni Dicanio

                #97
                Re: learn C++ or C#


                "Peter Duniho"
                In C++, RAII provides a convenient way to deal with that, and in C#, the
                "using" statement does the same. You may prefer one syntax over the
                other, but I personally don't see a difference between the two that would
                justify an argument of superiority one way or the other.
                Destructor and "scope" syntax in C++ is cleaner, simpler and more elegant
                than C# bloated 'using'.

                Moreover, there is big difference between C++ RAII and C# "using".

                In Andre's words:

                <quote>
                Using is fine if I hold a resource in a control block, but if the
                resource is held by let's say multiple lists, I have to use some kind of
                smart pointers to handle the resources efficiently.
                </quote>

                For example: I think that there is nothing like shared_ptr in C#.
                With shared_ptr you can have a *deterministic* resource manager, and you can
                wrap also non-memory resources in classes and store shared_ptr to these
                class instances into STL containers, and that works fine and is very elegant
                and simple.

                And there are also intrusive smart pointers, you may consider Eugene
                Gershink's implementation here:


                BTW: I'd like to make it clear that I'm saying neither that C++ is better
                than C#, nor that C# is better than C++. Simply, both languages have pros
                and cons.

                Giovanni


                Comment

                • Larry Smith

                  #98
                  Re: learn C++ or C#

                  In C++, RAII provides a convenient way to deal with that, and in C#, the
                  "using" statement does the same. You may prefer one syntax over the
                  other, but I personally don't see a difference between the two that would
                  justify an argument of superiority one way or the other
                  That's hardly a valid argument, considering that RAII requires no "using"
                  statement whatsoever. This alone justifies an argument that there is a
                  difference in favour of C++ (in contrast to your assertion).
                  Larry's claim of "vastly superior" seems particularly baseless. Vastly?
                  Pure hyperbole.
                  Point conceded. Scratch the word "vastly".


                  Comment

                  • Peter Duniho

                    #99
                    Re: learn C++ or C#

                    On Thu, 24 Jul 2008 10:25:47 -0700, Giovanni Dicanio
                    <gdicanio@_nosp am_email_dot_it wrote:
                    "Peter Duniho"
                    >
                    >In C++, RAII provides a convenient way to deal with that, and in C#, the
                    >"using" statement does the same. You may prefer one syntax over the
                    >other, but I personally don't see a difference between the two that
                    >would
                    >justify an argument of superiority one way or the other.
                    >
                    Destructor and "scope" syntax in C++ is cleaner, simpler and more elegant
                    than C# bloated 'using'.
                    Purely subjective. That sort of claim has no place in a technical
                    discussion.
                    Moreover, there is big difference between C++ RAII and C# "using".
                    >
                    In Andre's words:
                    >
                    <quote>
                    Using is fine if I hold a resource in a control block, but if the
                    resource is held by let's say multiple lists, I have to use some kind of
                    smart pointers to handle the resources efficiently.
                    </quote>
                    RAII doesn't _inherently_ support "smart pointers", nor does a garbage
                    collecting system prevent one from implementing "smart pointers".

                    As I pointed out before, in a 100% GC-ed system, "smart pointers" become
                    unnecessary anyway. But in a mixed system (i.e. pretty much any current
                    platform), it's entirely possible to implement "smart pointers", and they
                    can work in a very similar way to that implemented with RAII.

                    Which only brings us back to your purely subjective complaints about
                    "using".

                    Pete

                    Comment

                    • Peter Duniho

                      Re: learn C++ or C#

                      On Thu, 24 Jul 2008 10:35:59 -0700, Larry Smith <no_spam@_nospa m.com>
                      wrote:
                      >In C++, RAII provides a convenient way to deal with that, and in C#, the
                      >"using" statement does the same. You may prefer one syntax over the
                      >other, but I personally don't see a difference between the two that
                      >would
                      >justify an argument of superiority one way or the other
                      >
                      That's hardly a valid argument, considering that RAII requires no "using"
                      statement whatsoever. This alone justifies an argument that there is a
                      difference in favour of C++ (in contrast to your assertion).
                      You save a whole line of code. Wow! Yup...that definitely outweighs any
                      advantage that garbage collection has with respect to simplifying and
                      improving the robustness of memory management. After all, that's what
                      programmers really care about. I'd much rather save a line of code than
                      make it more likely that my code is correct.
                      >Larry's claim of "vastly superior" seems particularly baseless.
                      >Vastly?
                      >Pure hyperbole.
                      >
                      Point conceded. Scratch the word "vastly".
                      Replace it with "insignificantl y", and then _maybe_ you've got a point.

                      Personally, I think a discussion comparing/constrasting languages should
                      be limited to things that actually matter.

                      But hey, if you guys want to keep wasting time arguing about pointless
                      differences, be my guest.

                      Pete

                      Comment

                      • Larry Smith

                        Re: learn C++ or C#

                        But hey, if you guys want to keep wasting time arguing about pointless
                        differences, be my guest.



                        Comment

                        • David Wilkinson

                          Re: learn C++ or C#

                          Peter Duniho wrote:
                          This distinction has nothing to do with the _language_. If the OS was
                          entirely garbage collected, then these "non-memory resources" wouldn't
                          be an issue. They would be managed the same way memory is in .NET and
                          you'd never have to worry about disposing them.
                          >
                          Now, with certain types of objects you'd still have to deal with
                          closing, flushing, etc. But that's not something that RAII inherently
                          solves; it just happens that C++ classes can take advantage of that to
                          handle those operations. The OS API itself isn't based on C++ and
                          requires the program to deal with managing those operations.
                          >
                          In C++, RAII provides a convenient way to deal with that, and in C#, the
                          "using" statement does the same. You may prefer one syntax over the
                          other, but I personally don't see a difference between the two that
                          would justify an argument of superiority one way or the other. Larry's
                          claim of "vastly superior" seems particularly baseless. Vastly? Pure
                          hyperbole.
                          Not only is the "using" mechanism less convenient/elegant for the client of the
                          class than RAII (not to mention the possibility of forgetting to do it), but a
                          C# Dispose'd object can still be used (unlike a C++ object that goes out of
                          scope or is delete'd). This places an additional burden on the writer of an
                          IDisposable class.

                          IMHO, any use of a Dispose'd object should automatically cause a
                          "ObjectIsDeadEx ception" rather than relying on the author to test and throw an
                          ObjectDisposedE xception in every method.

                          --
                          David Wilkinson
                          Visual C++ MVP

                          Comment

                          • Peter Duniho

                            Re: learn C++ or C#

                            On Thu, 24 Jul 2008 11:23:49 -0700, David Wilkinson
                            <no-reply@effisols. comwrote:
                            Not only is the "using" mechanism less convenient/elegant for the client
                            of the class than RAII (not to mention the possibility of forgetting to
                            do it), but a C# Dispose'd object can still be used (unlike a C++ object
                            that goes out of scope or is delete'd).
                            I was comprehending your post until "or is delete'd". There's nothing in
                            C++ to stop someone from trying to use an object that's been deleted, and
                            depending on how the memory was allocated and what the class does in its
                            destructor, doing so might even work for awhile.
                            This places an additional burden on the writer of an IDisposable class.
                            I don't see how it's any more burden than already exists in C++. There's
                            no requirement that a disposable class actually catch post-disposal uses.
                            It's nicer, but then so too would it be nicer for a C++ class to catch
                            uses that occur after destruction. And I think it's easier for a C# class
                            to do so, because the object is still actually allocated and the code in
                            the class can behave predictably; in C++, sometimes using an object after
                            destruction will fail immediately, and sometimes it won't.
                            IMHO, any use of a Dispose'd object should automatically cause a
                            "ObjectIsDeadEx ception" rather than relying on the author to test and
                            throw an ObjectDisposedE xception in every method.
                            I don't disagree that RAII allows for an object to simply "disappear" when
                            the scope is exited, but this is how "using" works in C# too. Variables
                            declared in the "using" statement are valid only for the scope of the
                            block of that statement.

                            And just as in C#, the reference to the variable declared in the "using"
                            statement could "escape" by being passed to something else, so too could a
                            pointer to a stack-allocated C++ object escape. RAII in C++ doesn't
                            actually guarantee that you can't use the object reference after the
                            object itself has been destroyed. It just ensures that the object is
                            destroyed outside a particular scope, just as "using" does.

                            If anything, at least with a garbage collecting system, you know that if
                            you have a reference to something, that's a valid reference. The object
                            itself might be in an unusable state, but it will always be able to tell
                            you that one way or the other.

                            Again, in terms of any practical difference between the two, any
                            difference is negligible and not a point worth worrying about in terms of
                            comparing the languages. One might save a little typing over the other
                            (and there are other examples going the other direction), but in the
                            greater scheme of things, that's just not important.

                            Pete

                            Comment

                            • Andre Kaufmann

                              Re: learn C++ or C#

                              Larry Smith wrote:
                              >>>Multi-threading, GUI development is much easier in most of the other
                              >>>languages compared to the efforts you have to take in C++, because they
                              >>>support it out of the box. Fortunately C++ has Boost.
                              >>To be fair, this has nothing to do with C++ as a language (which has no
                              >>support for multi-threading or GUI whatsoever). You have to separate the
                              >>tools from the language itself.
                              >I don't think so. What would C++ be without the standard library ?
                              >
                              It would be another language since it must include the library by
                              definition. Contrast this to C# whose basic support is primitive (see the
                              standard for yourself). In any case, the claim that GUI development is
                              "easier" in C# compared to C++ has nothing to do with the languages
                              The RAD tools have to parse the source code, which is more complex in
                              C++ and therefore there aren't that much (good) RAD tools for C++ or
                              they feel somewhat sluggish.
                              So let's restrict the "easier" part on development of good RAD tools not
                              on using them.
                              themselves. It's the rich set of classes in MSFT's framework combined with
                              better development tools that make C# easier (noting that C# is a natural
                              fit for the framework unlike C++). Provide an equivalent C++ library and
                              better tools and it will be just as easy (not taking into account the actual
                              language differences).
                              With easier I meant the whole development experience - so it was perhaps
                              somewhat misleading to use the word "easier".
                              With development experience I mean Intellisense / refactoring / fast
                              compilation and so on.

                              There are GUI frameworks supported by different languages including C++:

                              C++ (/CLI): WinForms, VCL
                              C# : WinForms
                              Delphi : VCL

                              But IMHO the development experience in C#, Delphi is better than in C++,
                              just because of the compilation speed. It makes a huge difference if you
                              wait multiple minutes after having touched the GUI or just a few seconds.

                              Andre



                              Comment

                              • Andre Kaufmann

                                Re: learn C++ or C#

                                Peter Duniho wrote:
                                On Thu, 24 Jul 2008 11:23:49 -0700, David Wilkinson
                                <no-reply@effisols. comwrote:
                                [...]
                                I don't disagree that RAII allows for an object to simply "disappear"
                                when the scope is exited, but this is how "using" works in C# too.
                                Variables declared in the "using" statement are valid only for the scope
                                of the block of that statement.
                                [...]
                                For scoped resource handling I think "using" is a good alternative for
                                RAII. But I miss RAII sometimes in C#:

                                E.g:

                                list (a) - holds a file object (f)
                                list (b) - holds the same file object (f)

                                When I remove (f) from list (a) I have to check if list (b) holds the
                                file object too or rely on GC to close it - but I think that wouldn't be
                                a good idea, since the file would be open, till the GC has disposed the
                                object.

                                In C++ I can use RAII smart pointers to ensure that the file is closed
                                as soon as it's not used anymore. In C# I have no automatism to handle
                                this.

                                I see that there are benefits in GC over RC = reference counting, but
                                IMHO both are relevant:

                                GC - for memory
                                RC - for resources


                                Andre

                                Comment

                                Working...