learn C++ or C#

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

    Re: learn C++ or C#

    >Yes... the big difference is that with C#, errors manifest themselves
    >as incorrect output or recognizable error messages rather than random
    >crashes or memory leaks.
    >
    At least you KNOW there's something wrong when you get a random crash ...
    Assuming it does crash. C++ can not only suffer from the same "incorrect
    output" as C# (and to a potentially much greater degree), but it can also
    result in very serious (and potentially "random") problems that may not
    manifest themselves until long after the problem has occurred (in ways that
    C# just isn't susceptible to). And you may never even notice it. You may be
    filling your DB with garbage, generating invalid reports, displaying
    incorrect information for users, etc., but it may not come to anyone's
    attention depending on the nature of the problem. And if (when) it does, it
    may be incredibly difficult if not (practically) impossible to track it
    down.
    that incorrect output you get from your C# program is really much more
    dangerous.
    >
    I think you and Larry and others here blowing the C# trumpet are vastly
    over-stating the case about C++ being hard to use and hard to get right.
    The fact is that bad programmers will write bad code in any language, and
    if you want good code you have to employ good programmers. Once you have
    those your problems will start to go away -- whatever language you are
    using.
    >
    Of course, you need good management, too. Bad management and irrational
    budgetary constraints can ruin a project just as easily as bad
    programming.
    Lol. You must have just graduated.


    Comment

    • Larry Smith

      Re: learn C++ or C#

      >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.
      >
      I think the answer to that is "it looked too hard at the time" ... and
      IIRC
      that constraint is to be removed an some future version of the standard.
      Too hard? Maybe too little time to work out the details at the time but it
      had something to do with the binding rules according to Stroustrup. I don't
      recall the limited details he provided off-hand.
      >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.
      >
      I think it's /only/ the very experienced developers (and those who aren't
      but think they are -- which is more worrying) who "continuous ly bend their
      minds out of shape" looking for new ways to use the expressive power of
      the
      language. These are the library builders, the Boost developers, the
      Alexandrescus of the world ... most C++ programmers just /use/ their work
      and are grateful for the way that it makes their lives easier and more
      pleasant.
      Most code in the real world is mediocre at best but usually much worse. It's
      usually indicative of people who don't have their heads wrapped around the
      language and how to program in general (opposed to pushing the limits of the
      language). Even very experienced (skilled) programmers still have to
      exercise a lot of caution and deal with complex issues not common in other
      languages (not always but frequently enough). Most C++ programmers may be
      "grateful" but the majority are causing serious problems for their
      companies, their colleagues, and their users. Most of them function in a
      state of ignorant bliss and management usually doesn't understand the scope
      of the problem.


      Comment

      • Andre Kaufmann

        Re: learn C++ or C#

        Peter Duniho wrote:
        On Thu, 24 Jul 2008 22:43:52 -0700, Andre Kaufmann
        <andre.kaufmann _re_move_@t-online.dewrote:
        [...]
        >I can include reference counting, but I can't use smart pointers.
        >
        Why not?
        Not in that way as they are used in C++.

        E.g. if I assign one smart pointer to another in C++ the reference is
        incremented. In C# I would have to use a method for the assignment.
        But I can't prevent one smart pointer accidentally be assigned to
        another one in C#.
        So I don't see that much value in smart pointers in C#, I then rather
        would prefer the AddRef method directly and not using a smart pointer.

        >I prefer GC memory handling, but for resources GC can't be used
        >effectively, because often resources have to be released directly.
        >I do a lot of multi threaded programming, there I permanently have the
        >need of some kind of reference counted resource handling.
        >
        For what it's worth, I've done a fair amount of multi-threaded
        programming in C# without needing ref-counting.
        For example in the following architecture:

        A simple shared buffer holding memory and resources: [b]

        [b] -Thread #1
        [b] ---[ReceiverThread] - passes --[b] -Thread #2
        [b] -Thread #3

        The buffer is passed to multiple receivers which "do something" with the
        buffer. After the last thread has finished it's operations it should
        release the buffer and store it into a central pool for reusing and
        should additionally release eventually used resources immediately.
        How do I know if the last thread has finished ?
        Not that I agree that ref-counting can't be done in C#, but I've found
        that in many cases, what's really needed is a different way of looking
        at the problem.
        Yes, reference counting can surely be done in C#. But I don't see how I
        could use reference counting with smart pointers in C# ---- outside of a
        control block.
        >>[...]
        > But there's nothing about C# that precludes using that
        > technique if you find yourself i
        >>
        >If you could add methods to value structures in C# I would agree.
        >
        I don't know what you mean here. What methods do you want to add? To
        what structure? How would that help?
        A structure is a value type in C# and therefore copied on assignment and
        immediately "freed" if the control block is left.
        If I could add an destructor and overload the assignment operator I
        would have a possibility to implement smart pointers like in C++.

        >But currently in C# you have to either use a temporary object in
        >combination with using or call the AddRef / Release functions by hand.
        >
        How is a smart pointer not a temporary object?
        Yes, that's the point. I know how to handle it temporarily in a control
        block, but when the smart pointer is added to a list of smart pointers
        and removed from the list I have no possibility to "force" the automatic
        release of the reference.
        I have to remove the smart pointer from the list and then manually call
        release. What's the point of a smart pointer in this case ? I could
        rather use the reference counted object directly
        [...]
        Why not just create a smart-pointer-like class or struct that does that
        with the "using" statement? Adds a ref when the object is created,
        decrements the ref on disposal, zero ref-count causes disposal of the
        wrapped object.
        Maybe I'm just being obtuse, but I don't see what the big problem is.
        I only have the feeling that just creating a new object to automatically
        call methods of another object in the Dispose method is somewhat
        overkill. The GC is fast, but why should I add pressure to it, by
        permanently allocating temporary objects ?

        I agree It's no big deal if the temporary object is created rarely or
        held for a long time.

        But additionally a smart pointer should behave like another ordinary
        pointer, with additional functionality that is under my control.
        Pete
        Andre

        Comment

        • Andre Kaufmann

          Re: learn C++ or C#

          Ben Voigt [C++ MVP] wrote:
          >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 ?
          >
          You can't do that in any language I'm aware of, so it's a non-issue. Did
          you mean "error if the signature of the function in the base class has
          changed"?
          Sorry yes - the signature - function declaration - not the definition or
          code inside the function itself.
          >
          >Andre
          Andre

          Comment

          • Peter Duniho

            Re: learn C++ or C#

            On Fri, 25 Jul 2008 09:35:20 -0700, Andre Kaufmann
            <andre.kaufmann _re_move_@t-online.dewrote:
            Peter Duniho wrote:
            >On Thu, 24 Jul 2008 22:43:52 -0700, Andre Kaufmann
            ><andre.kaufman n_re_move_@t-online.dewrote:
            >[...]
            >>I can include reference counting, but I can't use smart pointers.
            > Why not?
            >
            Not in that way as they are used in C++.
            >
            E.g. if I assign one smart pointer to another in C++ the reference is
            incremented. In C# I would have to use a method for the assignment.
            But I can't prevent one smart pointer accidentally be assigned to
            another one in C#.
            So I don't see that much value in smart pointers in C#, I then rather
            would prefer the AddRef method directly and not using a smart pointer.
            Ah, I see. So it's not that you can't do it. You just don't want to do
            it the way you'd need to in C#.

            You're right, assignment operator overload isn't available in C#. But
            such an overloaded operator's really just another method. There's no
            functional difference between simply implementing it as an explicit
            method. In fact, some will argue that there's a good reason to not allow
            overloading of the assignment operator and that making that sort of thing
            explicit is a _good_ "don't blow your leg off" sort of thing. :)
            For example in the following architecture:
            >
            A simple shared buffer holding memory and resources: [b]
            >
            [b] -Thread #1
            [b] ---[ReceiverThread] - passes --[b] -Thread #2
            [b] -Thread #3
            >
            The buffer is passed to multiple receivers which "do something" with the
            buffer. After the last thread has finished it's operations it should
            release the buffer and store it into a central pool for reusing and
            should additionally release eventually used resources immediately.
            How do I know if the last thread has finished ?
            There are any number of approaches you can take. But if you really like
            ref-counting, then the solution is to just ref-count the object. I don't
            know what the phrase "eventually used resources" means, but if you're
            pooling the object I don't see why you'd release its resources.
            Conversely, if you're releasing its resources, then just get rid of the
            object and be done with it.

            In either case, you may still want _some_ form of ref-counting, either
            managed by the pool manager itself, or as part of the object. But either
            way, it's much ado about nothing.
            [...]
            A structure is a value type in C# and therefore copied on assignment and
            immediately "freed" if the control block is left.
            If I could add an destructor and overload the assignment operator I
            would have a possibility to implement smart pointers like in C++.
            IDisposable can replace the functionality of the destructor (in
            conjunction with the "using" statement), and yes you'd have to have an
            explicit method instead of an overloaded assignment operator. I don't
            find those differences to be material.
            >>But currently in C# you have to either use a temporary object in
            >>combination with using or call the AddRef / Release functions by hand.
            > How is a smart pointer not a temporary object?
            >
            Yes, that's the point. I know how to handle it temporarily in a control
            block, but when the smart pointer is added to a list of smart pointers
            and removed from the list I have no possibility to "force" the automatic
            release of the reference.
            I have to remove the smart pointer from the list and then manually call
            release. What's the point of a smart pointer in this case ? I could
            rather use the reference counted object directly
            When the smart pointer is not stack-allocated, don't you have to manually
            delete the smart pointer in C++? What's the difference?
            [...]
            I only have the feeling that just creating a new object to automatically
            call methods of another object in the Dispose method is somewhat
            overkill.
            Well, certainly there is the question of just how important smart pointers
            are. Personally, I find them superfluous. You can still get ref-counting
            bugs even if you're using smart pointers, if you use them incorrectly.
            But inasmuch as there's some benefit to wrapping ref-counting in a
            clearer, more automatic API, that benefit is available in C#, just using
            slightly different syntax.
            The GC is fast, but why should I add pressure to it, by permanently
            allocating temporary objects ?
            The phrase "permanentl y allocating temporary objects" doesn't make sense
            to me. But regardless, the last thing you really need to worry about is
            pressuring the GC. Assuming you're using a reference type for your smart
            pointer (which may or may not be true anyway), the GC can handle the load
            just fine.
            I agree It's no big deal if the temporary object is created rarely or
            held for a long time.
            Au contraire. One of the GC's strengths is its ability to deal with large
            numbers of frequently allocated, short-lived objects.
            But additionally a smart pointer should behave like another ordinary
            pointer, with additional functionality that is under my control.
            To some extent, the real issue here is that there's a fundamental paradigm
            shift that needs to be made. If you don't want to make that shift, that's
            fine. But that's not an indictment of C#. The whole concept of "smart
            pointer" is related to the needs of unmanaged code (and especially COM).
            An application written to the strengths of C# and the .NET Framework will
            most often never run into ref-counting issues at all, and if and when it
            does happen, there are viable work-arounds.

            Again: much ado about nothing.

            Pete

            Comment

            • Jack Hanebach

              Re: learn C++ or C#

              Peter Duniho wrote:
              You save a whole line of code. Wow!
              Sorry, you just completely missing the point of RAII...

              In C++ I can write a class Thingie that employs RAII for resource
              management and then anybody can use it without caring about how it does
              it's stuff.

              In C# you can write the same Thingie but it's user is required to only
              use it in the context of 'using' statement (or it will leak resources).

              Comment

              • Andre Kaufmann

                Re: learn C++ or C#

                Peter Duniho wrote:
                On Fri, 25 Jul 2008 09:35:20 -0700, Andre Kaufmann
                <andre.kaufmann _re_move_@t-online.dewrote:
                >
                [...]
                You're right, assignment operator overload isn't available in C#. But
                such an overloaded operator's really just another method. There's no
                functional difference between simply implementing it as an explicit
                method. In fact, some will argue that there's a good reason to not
                allow overloading of the assignment operator and that making that sort
                of thing explicit is a _good_ "don't blow your leg off" sort of thing. :)
                May be. But I have to protect the smart pointer somehow, so preventing
                an assignment would be sufficient.
                [...]
                There are any number of approaches you can take. But if you really like
                ref-counting, then the solution is to just ref-count the object. I
                I don't like it that much, but I don't see a better solution for
                efficient resource handling.
                don't know what the phrase "eventually used resources" means, but if
                you're pooling the object I don't see why you'd release its resources.
                Conversely, if you're releasing its resources, then just get rid of the
                object and be done with it.
                To release the resources I too have to know when the last thread has
                finished. A resource could be for example a large memory buffer. IMHO it
                wouldn't be wise to frequently allocate - dispose large objects in C#.
                [...]
                When the smart pointer is not stack-allocated, don't you have to
                manually delete the smart pointer in C++? What's the difference?
                Smart pointers aren't allocated (normally) on the heap in C++.
                Everywhere you are using them, they are either stack allocated or
                embedded in an object. It's up to the compiler to generate the
                appropriate code to call the destructor.
                [...]
                >
                The phrase "permanentl y allocating temporary objects" doesn't make sense
                to me. But regardless, the last thing you really need to worry about is
                pressuring the GC. Assuming you're using a reference type for your
                smart pointer (which may or may not be true anyway), the GC can handle
                the load just fine.
                Yes, GC is quite fast - under Windows. I think under Mono it's somewhat
                different. But anyways I just want to call 2 methods of another object,
                it's IMHO just somewhat overkill to create a temporary object just for
                that.

                IIRC lock(..) in C# simply calls 2 methods. Would be fine if I could use
                the same functionality for other objects and methods.

                >
                To some extent, the real issue here is that there's a fundamental
                paradigm shift that needs to be made. If you don't want to make that
                I'm fine so far with C# - it has many strengths and I like it. But I
                only miss the control C++ offered me - sometimes.
                shift, that's fine. But that's not an indictment of C#. The whole
                concept of "smart pointer" is related to the needs of unmanaged code
                (and especially COM). An application written to the strengths of C# and
                the .NET Framework will most often never run into ref-counting issues at
                all, and if and when it does happen, there are viable work-arounds.
                The D language for example combines both - garbage collection and RAII.
                Additionally I can use C++/CLI which also supports RAII for managed
                programming.
                But the downside is, C++/CLI is damn slow in compilation compared to C#,
                because it's a full fledged C++ compiler. And regarding managed
                application development it's IMHO only a second class citizen.

                So I prefer C# anyways for this task.
                Again: much ado about nothing.
                Yes, it's not a vital feature. But the discussion was about RAII, which
                isn't used for smart pointers only.
                It would only be a feature, that would make C# more attractive to C++
                developers ;-)
                Pete
                Andre

                Comment

                • bjarne

                  Re: learn C++ or C#

                  On Jul 25, 5:45 am, Daniel James <wastebas...@no spam.aaisp.orgw rote:
                  In article <news:OPjv4tY7I HA.2072@TK2MSFT NGP04.phx.gbl>, Larry Smith wrote:
                  >
                  I also have some serious pet peeves. Why didn't they permit local
                  classes to be passed as template arguments. I once askedStroustrup
                  about this at a conference but I wasn't satisfied with his terse
                  response.
                  >
                  I think the answer to that is "it looked too hard at the time" ... and IIRC
                  that constraint is to be removed an some future version of the standard.
                  C++0x will support local types as template arguments. The implementors
                  who had problems have found a way.

                  Comment

                  • Daniel James

                    Re: learn C++ or C#

                    In article news:<OAyVnQk7I HA.4536@TK2MSFT NGP04.phx.gbl>, Larry Smith wrote:
                    Assuming it does crash. C++ can not only suffer from the same
                    "incorrect output" as C# ... but it can also ..
                    Certainly -- Point taken -- I didn't mean to suggest that it couldn't.

                    I was just pointing out that while bad C# code may give you a "nice warm
                    feeling" by not crashing you should not be lulled into a false sense of
                    security that it is actually doing the right thing.

                    C# code needs just as much testing for correctness (and just as much
                    careful design work to achieve correctness in the first place) as code in
                    any other language -- it would be wrong to suggest that it did not, or that
                    doing these things for C# was significantly quicker, cheaper, or easier
                    than doing them for C++.
                    Lol. You must have just graduated.
                    Flattery will get you nowhere -- it took me years to develop this much
                    cynicism!

                    Cheers,
                    Daniel.


                    Comment

                    • Larry Smith

                      Re: learn C++ or C#

                      C# code needs just as much testing for correctness (and just as much
                      careful design work to achieve correctness in the first place) as code in
                      any other language -- it would be wrong to suggest that it did not, or
                      that
                      doing these things for C# was significantly quicker, cheaper, or easier
                      than doing them for C++.
                      Far from it. While nobody would dispute that program correctness is
                      demanding in any language, C++ is significantly more demanding to get right
                      from a purely mechanical perpsective alone. It's also filled with more
                      trip-wires and gotchas than any other mainstream language. It's easier to
                      achieve programa correctness when you're strolling down a paved sidewalk
                      instead of hiking through the jungle.
                      >Lol. You must have just graduated.
                      >
                      Flattery will get you nowhere -- it took me years to develop this much
                      cynicism!
                      It's a strange brand of cynicism you're practicing if you really believe
                      that "good programmers" and "good management" exist in the real world (in
                      sufficient numbers to make an appreciable difference). Those who practice
                      the more conservative brand would simply tell you this is reality. The
                      panacea you're waiting for may exist somewhere, but it won't save the
                      majority of us.


                      Comment

                      • Ben Voigt [C++ MVP]

                        Re: learn C++ or C#



                        "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
                        news:op.uetjsnl l8jd0ej@petes-computer.local. ..
                        On Thu, 24 Jul 2008 15:14:38 -0700, Ben Voigt [C++ MVP]
                        <rbv@nospam.nos pamwrote:
                        >
                        >>>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.
                        >>
                        >It's quite objective. In C++, the burden is on the library developer,
                        >the
                        >user needs no extra syntax to benefit from automatic cleanup.
                        >
                        You don't seem to have read the statements you quoted.
                        >
                        I'm talking about the question of the syntax itself, not the semantics.
                        The need to include a "using" statement is not a "burden". It's just a
                        different way to write the same thing.
                        Yes, it is a burden. You have to remember the using block at every use of
                        the class. You have to remember which classes need using blocks and which
                        don't. And when you add a resource (unmanaged or IDisposable) to a class,
                        you have to add the IDisposable interface to that class and go back to every
                        single user and put in the using block.

                        That's not "a different way to write the same thing" any more than the empty
                        string is a different way to write a letter.

                        Or shall I claim that C++'s delete statement and the C# garbage collectors
                        are just different ways to call the deallocator? Of course they aren't, one
                        is automatic and the other is not.
                        >
                        >[...]
                        >>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
                        >>
                        >Nothing could be further from the truth.
                        >
                        Ah, more hyperbole. Yup...that really makes your point compelling.
                        >
                        >Lazy (or deferred, if you prefer)
                        >cleanup breaks access to shared resources, and does so
                        >non-deterministical ly.
                        >
                        In a 100% GC-ed system, a resource that's eligible for "cleanup" is not
                        "shared" by any code anywhere, by definition. Your statement makes no
                        sense.
                        That's why no real-world system is 100% GC-ed. Not .NET, not Java, not any
                        other. Files, for example, are part of a shared namespace and can't be
                        garbage collected. And no number of improvements to the garbage collector
                        are ever going to help with the problem of synchronizing file access. But
                        all the C# advocates keep pretending that you don't need deterministic
                        cleanup because you have GC. Yes, you do. A file access object needs to be
                        cleaned up by releasing a lock on the file, at the point the file access
                        ceases. Not when you run out of memory (if you run out of memory, if your
                        program doesn't deadlock waiting for the result of some process which needs
                        to access that file to continue.
                        >
                        >>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.
                        >>
                        >No, in C# it's not possible to create an object that automatically
                        >performs
                        >cleanup when it becomes unreachable.
                        >
                        I never said it was. But nice straw man.
                        If it isn't possible in C#, then it obviously isn't just a difference of
                        syntax as you keep insisting, now is it?
                        >
                        Pete

                        Comment

                        • Ben Voigt [C++ MVP]

                          Re: learn C++ or C#



                          "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
                          news:op.uetjw5j b8jd0ej@petes-computer.local. ..
                          On Thu, 24 Jul 2008 15:17:05 -0700, Ben Voigt [C++ MVP]
                          <rbv@nospam.nos pamwrote:
                          >
                          >The C# way is brittle. If C# let you use a using statement with types
                          >that
                          >don't support IDisposable, then it would be better. But right now,
                          >adding
                          >IDisposable support to an existing class is always an impermissible
                          >breaking
                          >change.
                          >>
                          >In C++, you can add a destructor without any changes to the code which
                          >references the class.
                          >
                          If C++ didn't have its own brittle behaviors (including limitations on the
                          use of stack-allocated classes), I might think your point has some merit
                          here.
                          C++ has quite a few brittle behaviors, but I'm not sure what you mean by
                          limitations on the use of stack-allocated classes.

                          Can you explain what you're talking about?
                          >
                          But it does, so I don't.
                          >
                          Pete

                          Comment

                          • Peter Duniho

                            Re: learn C++ or C#

                            On Sat, 26 Jul 2008 20:00:45 -0700, Ben Voigt [C++ MVP]
                            <rbv@nospam.nos pamwrote:
                            [...]
                            >>No, in C# it's not possible to create an object that automatically
                            >>performs
                            >>cleanup when it becomes unreachable.
                            >>
                            >I never said it was. But nice straw man.
                            >
                            If it isn't possible in C#, then it obviously isn't just a difference of
                            syntax as you keep insisting, now is it?
                            If we were talking about whether "it's possible to create an object that
                            automatically performs cleanup when it becomes unreachable", then your
                            statement would be relevant. But we weren't. So it's just a straw man.

                            The fact is, it's not possible in C++ to do that either. So your straw
                            man is particularly pointless.

                            But it is fairly indicative of the direction the discussion has gone,
                            which is to say it's being corrupted into something altogether different
                            from what I was pointing out. I'm not going to waste my time trying to
                            argue a point I never made in the first place, nor in trying to drag the
                            point back to what I _was_ talking about when it's clear that's not what
                            anyone else really wants to talk about.

                            Pete

                            Comment

                            • Andre Kaufmann

                              Re: learn C++ or C#

                              Peter Duniho wrote:
                              On Sat, 26 Jul 2008 20:00:45 -0700, Ben Voigt [C++ MVP]
                              <rbv@nospam.nos pamwrote:
                              >
                              [...]
                              If we were talking about whether "it's possible to create an object that
                              automatically performs cleanup when it becomes unreachable", then your
                              I think it is. Most objects in C++ are allocated in the way "structs"
                              are allocated in C# and they get automatically destroyed, if they aren't
                              reachable anymore.
                              statement would be relevant. But we weren't. So it's just a straw man.
                              >
                              The fact is, it's not possible in C++ to do that either. So your straw
                              man is particularly pointless.
                              In C++ you have heap allocation and about 8 additional different ways to
                              create an object.

                              The only allocation type you have to care about freeing in C++ is heap
                              allocation. The trick in C++ is to use objects not allocated on the heap
                              to care about the lifetime of the heap allocated ones.
                              Just like the "using" keyword in C# can be used to control the lifetime
                              of an object allocated in a control block.

                              The big difference in C++ is, that I'm not restricted to a control block
                              and don't have to care about the lifetime of the object, regardless
                              where I have allocated them. (for heap allocated objects you have to use
                              smart pointers surely)



                              It's just a different point of view:

                              - In C++ an object is responsible to care about it's resources
                              and free them in the destructor

                              - In C# the external code is responsible for calling Dispose
                              to free the resources of an object

                              -------------------------------------------------------------------

                              A small example:

                              List<objectl;
                              list<objectl;

                              In C++: l.erase(...) -the object gets automatically destroyed
                              (if no heap allocated object is used)

                              In C#: l.remove(...) -the object is not disposed. If you wish
                              to you have to call it manually

                              -------------------------------------------------------------------


                              For allowing the same automatic deallocation of objects in C# like in
                              C++, in C# you would need:

                              - Overloading of assignment operator or at least protecting it
                              - Destructor for structs


                              Andre
                              [...]
                              Pete

                              Comment

                              • Daniel James

                                Re: learn C++ or C#

                                In article news:<O#O8Hky7I HA.2064@TK2MSFT NGP02.phx.gbl>, Larry Smith wrote:
                                C++ is significantly more demanding to get right
                                from a purely mechanical perpsective alone.
                                C++ is harder, yes ... but is it actually hard in any absolute sense?

                                Given that your programs will never work correctly if you employ stupid
                                programmers you are going to have to employ smart people anyway ... so you
                                might as well let them use powerful tools.

                                I don't consider that C++ is harder than other languages by a sufficient
                                degree for that to be any reason not to prefer it over those languages.
                                There may be other reasons to choose another language over C++ for a
                                particular project ... but the fact that it is complex should not be one of
                                them.

                                If you don't agree with that we shall just have to agree to differ.

                                Cheers,
                                Daniel.



                                Comment

                                Working...