Page 3 of 3 FirstFirst 123
Results 21 to 27 of 27

Thread: Discussing C and C++

  1. #21
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Discussing C and C++

    Quote Originally Posted by Simian Man View Post
    C is a very elegant language for what it was designed to be: a portable assembly language. It is great for systems programming tasks. Unfortunately, for whatever reason, people use C for many other programming domains where it is horribly wrong-footed, like desktop applications. This led to people discovering that they wanted things like classes, exceptions and templates to make their lives easier. Instead of finding a language that fit their problem domain better, they bolted the features they wanted onto C, which has given us the horrible amalgamation known as C++.
    The main reason for C's popularity in such domains is that before many of today's languages were invented, C often was the best choice.

    Similarly, C++ still makes sense for a shrinking niche of applications. I mentioned games before because many game programmers really do need to worry about combining excellent performance with object-oriented design. In such a case, I wouldn't condemn the use of C++.

    What I'm really trying to say can be summed up rather succinctly:

    1) There is currently no viable replacement for C in systems and embedded programming.
    2) C++ is less well designed than C, but that fact alone does not make C better than C++ for any given purpose.
    3) Other languages exist that are often preferable to C or C++, trading performance for ease of use.
    4) Cheaper, faster computers will continue to make the concern of code performance less and less relevant.

  2. #22
    Join Date
    Oct 2011
    Location
    Chicago, IL
    Beans
    419
    Distro
    Xubuntu 10.04 Lucid Lynx

    Re: Discussing C and C++

    Quote Originally Posted by CptPicard View Post
    It is very rare that I find myself "defending" C++, but IMO this is wrong. The difference comes from the strict typing of C++ that C does not have; in C code you often end up writing lots of pointer indirection that you have to eventually cast out of. C++ allows carrying around more strict type information, especially with templates, that in the end allows for more compiler inlining.
    That's a good point. I should have explained myself better. I did not mean to suggest that the two languages are the same. My point was that when people begin to use C++ to match the runtime performance of C, their style becomes more similar to the C style (e.g. raw pointers instead of STL containers). I consider C++ features such as const/inline/new, which admittedly allow for more type safety than #define/#define/malloc, to be a matter of preference rather than a significant shift in style. On the other hand, the OO approach of using "smart pointers" and STL in the C++ style rather than primitives in the C style offers a much sharper contrast. When people really need to squeeze out constants and fit the memory footprint of a small device, the OO approach starts to get in the way, and people opt for the programming style preferred by C developers.

    Quote Originally Posted by Simian Man View Post
    C is a very elegant language for what it was designed to be: a portable assembly language.
    I agree almost entirely with your post, but C also has a huge advantage over assembly in expressive power, not just portability.

  3. #23
    Join Date
    Apr 2008
    Location
    Australia
    Beans
    276
    Distro
    Ubuntu

    Re: Discussing C and C++

    Quote Originally Posted by 11jmb View Post
    That's a good point. I should have explained myself better. I did not mean to suggest that the two languages are the same. My point was that when people begin to use C++ to match the runtime performance of C, their style becomes more similar to the C style (e.g. raw pointers instead of STL containers). I consider C++ features such as const/inline/new, which admittedly allow for more type safety than #define/#define/malloc, to be a matter of preference rather than a significant shift in style. On the other hand, the OO approach of using "smart pointers" and STL in the C++ style rather than primitives in the C style offers a much sharper contrast. When people really need to squeeze out constants and fit the memory footprint of a small device, the OO approach starts to get in the way, and people opt for the programming style preferred by C developers.
    Interestingly enough, I've always preffered to use dynamic arrays to STL containers. I've also never bothered to use smart pointers. And I specifically only use (const wherever convinient) references to pass variables around in place of pointers so that I know not to free them.

    I think that'd be why I struggle to see the difference between C and C++. I'm getting a little bit sick of C# though, designed to be hard to do the low level stuff.
    By the people, for the people.

  4. #24
    Join Date
    Oct 2011
    Location
    Chicago, IL
    Beans
    419
    Distro
    Xubuntu 10.04 Lucid Lynx

    Re: Discussing C and C++

    Quote Originally Posted by dagoth_pie View Post
    Interestingly enough, I've always preffered to use dynamic arrays to STL containers. I've also never bothered to use smart pointers. And I specifically only use (const wherever convinient) references to pass variables around in place of pointers so that I know not to free them.

    I think that'd be why I struggle to see the difference between C and C++. I'm getting a little bit sick of C# though, designed to be hard to do the low level stuff.
    The big differences between the two languages boil down to high-level constructs that are intended to save developers' time at the cost of performance. As previous posts have pointed out, there are some niche areas where C++ is a good fit, but in general, there is almost always a better tool for the job.

    As for C#, it is more like Java than C or C++. It is better than either C or C++ for high-level tasks, but still not my favorite.

  5. #25
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: Discussing C and C++

    The problem is that C++ is a mess and its existence was safe until somebody came up with languages that did exactly the same without confusing and over-complex semantics. Its mess comes from the idea that you can coherently build a language that is both high- and low-level.

  6. #26
    Join Date
    Jun 2010
    Beans
    92

    Re: Discussing C and C++

    Quote Originally Posted by dagoth_pie View Post
    I'm getting a little bit sick of C# though, designed to be hard to do the low level stuff.
    C# was never intended to be low-level.

    C# was designed by Microsoft to be Microsoft's answer to Sun's Java. Since Microsoft did not own and control Java they replaced it.

  7. #27
    Join Date
    Mar 2009
    Location
    Western Hemisphere.
    Beans
    136
    Distro
    Ubuntu

    Re: Discussing C and C++

    For my own personal use, I have trouble coming up with projects which aren't better handled by C, Python, or some combination of the two than by C++. Python provides vastly faster development, and for critical portions of the code that need to run fast, I can drop into C and write an extension to do what I want.

    That said, I think people are being a little overly negative about C++ here. Specifically, for larger projects where all aspects of performance are critical, C++ really does shine.

    As an example, C++ is the natural language for writing a web browser. It's notable that both Firefox and Chromium are written in C++. The way people use web browsers you want the maximum possible performance for every operation, and that rules out most high level languages, but the project is complex enough that writing it all in C would be much more difficult.

    Another example is word processors. I'm not a big fan of Microsoft, but Word is dramatically faster and more stable than OpenOffice Writer, and I think a lot of that is probably attributable to the choice of C++ over Java.

    Anyway, for the most part I agree with the sentiments of this thread. I certainly avoid C++ if I can. But I think C++ is going to be around for a while yet!

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •