Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Discussing C and C++

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

    Discussing C and C++

    Hey there folks.

    I've noticed that a lot of programmers say that they perfer C to C++. I've never purely done C, although in my opinion I learned to program C++ in quite a C-like way. So I'm wondering, why do some of you prefer C over C++.

    My guess is that it has something to do with the STL libraries, would that be close to the truth in anyones mind?

    And let's try not to flame each other guys.
    By the people, for the people.

  2. #2
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Discussing C and C++

    You can find some good reading on the below link .

    http://unthought.net/c++/c_vs_c++.html
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

  3. #3
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: Discussing C and C++

    Quote Originally Posted by codemaniac View Post
    You can find some good reading on the below link .

    http://unthought.net/c++/c_vs_c++.html
    I find this extremely funny. The guy writes a program to count the number of distinct words in a text file. Who ever writes programs for that? Nobody, that's who. The comparison is in general really flawed.

    Personally, I don't even really "prefer C over C++", because I know nothing in C++. Zero. I couldn't even write "hello world" with it.
    Last edited by Bachstelze; June 14th, 2012 at 05:40 PM.
    「明後日の夕方には帰ってるからね。」


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

    Re: Discussing C and C++

    obligatory FQA link: http://yosefk.com/c++fqa/

    I personally prefer C because of its simplicity. As a simple example, K&R is less than 300 pages long, while its cousin by Stroustrop is over 1000, and I think both go into similar levels of detail.

    Another reason I prefer C is the style. C++ created a lot of unnecessary constructs (many of which have been backported to C, but it is still not the C style to use them) such as inline functions instead of macros, references, const instead of #define, and a few more. Some C++ features are overused, like exceptions (only really needed for constructors, overloaded operators, and dtors), overloaded operators (such as bitwise shift operators for printing reading in iostream), dynamic_cast (the C++ style is to use this for everything, when it is only really needed for objects)

    The main reason that I do not use C++ when I don't have to, though, is that I just don't see the point. You use C when performance is absolutely critical. Even though you can write C-like code in C++, the purpose of the language is to provide high-level constructs for faster development when performance is not critical. The classic tradeoff of developer time vs. runtime. When performance is negotiable, Python wins over C++ in my book

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

    Re: Discussing C and C++

    Quote Originally Posted by codemaniac View Post
    You can find some good reading on the below link .

    http://unthought.net/c++/c_vs_c++.html
    An interesting piece, but I'd like to offer a counterpoint.

    The author looks at simple problems that benefit from the high-level features of C++, and notably the STL. He then goes on to say that this makes C++ a better language.

    For problems like the ones described, I would not even consider using C. If you are presented with a problem like counting word frequencies, and your first inclination is to use C, it's probably because C is the only language you know. The same applies for C++. I can write a Perl script that does the same thing in under a minute. Is it faster? Maybe, maybe not; it probably doesn't matter, because programmer time is usually more valuable than machine time.

    C used to be a great all-around general purpose language. With the advent of higher level languages its niche shrunk. Now (aside from old programs written in C) it's mainly the domain of hardware drivers, kernels, low-level system utilities, and embedded systems.

    C++ is now in the situation C was in a few decades ago: its niche is shrinking. But C++ doesn't have a fallback. On the one hand, it can't effectively compete with higher level languages for speed of development; on the other, it can't compete with C and assembly for size and agility.

    I think C++ is dying a very slow and painful death. Most of the programs that would traditionally be good applications for C++ have succumbed to cheaper, faster computers and can be done for less investment overall in Java or Python. Like Microsoft is mostly abandoning C++ in favor of .NET.

    That's not to say there isn't a market for C++ programmers -- there is, and there will be for decades to come. There's still a market for COBOL programmers, for crying out loud. But the linked article ignores the technological implications of C++ as opposed to C in favor of just saying "C++ is a better language."

    @OP: I like C better than C++ personally because it has a cleaner design and I prefer the style of good C programs over that of good C++ programs. If I find C doesn't meet my needs, I turn to Python, not C++.

  6. #6
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: Discussing C and C++

    Quote Originally Posted by trent.josephsen View Post
    For problems like the ones described, I would not even consider using C. If you are presented with a problem like counting word frequencies, and your first inclination is to use C, it's probably because C is the only language you know. The same applies for C++. I can write a Perl script that does the same thing in under a minute. Is it faster? Maybe, maybe not; it probably doesn't matter, because programmer time is usually more valuable than machine time.
    Even Perl is overkill IMO. I would just do

    Code:
    cat file | tr ' ' "\n" | sort | uniq | wc -l
    EDIT: I just tried this on a txt of the complete works of Shakespeare from Project Gutenberg:

    Code:
    firas@av104151 ~ % time (cat shakespeare.txt | tr ' ' "\n" | sort |uniq|wc -l)
       83715
    ( cat shakespeare.txt | tr ' ' "\n" | sort | uniq | wc -l; )  1.20s user 0.03s system 5% cpu 22.494 total
    So performance isn't even that bad.
    Last edited by Bachstelze; June 14th, 2012 at 08:18 PM.
    「明後日の夕方には帰ってるからね。」


  7. #7
    Join Date
    Sep 2009
    Beans
    217

    Re: Discussing C and C++

    Additionally, the C++ examples are only clearer to read due to the "standard" nature of the library code used. I could easily write a library that cleans up the C code to the same level of clarity. The only reason you might not understand it at first glance would be because this library in question isn't "standard."

    In that regard, the STL is "better" than the standard libraries of C. However, standard libraries != the language itself.

    As an aside, I find the namespace syntax to be hideous. There's really no reason that namespaces couldn't use the same syntax as structures (like, you know, every other language that has a qualified import concept.) I realize that you can use "using namespace ..." but having to work around the language seems like a waste of time to me.

  8. #8
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: Discussing C and C++

    Quote Originally Posted by trent.josephsen View Post
    If I find C doesn't meet my needs, I turn to Python, not C++.
    This is exactly why I don't know C++ and have no intention of learning it. C, Python, and the shell tools provide everything I need for any kind of serious programming. And for non-serious programming, Haskell or Ada are a lot more fun than C++ seems to be.
    「明後日の夕方には帰ってるからね。」


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

    Re: Discussing C and C++

    Quote Originally Posted by satsujinka View Post
    Additionally, the C++ examples are only clearer to read due to the "standard" nature of the library code used. I could easily write a library that cleans up the C code to the same level of clarity. The only reason you might not understand it at first glance would be because this library in question isn't "standard."

    In that regard, the STL is "better" than the standard libraries of C. However, standard libraries != the language itself.
    I agree with your conclusion, but not your reasoning, so I'm going to play devil's advocate for a moment and defend C++. <shudder>

    A programming language is only as good as the libraries available for it, and what a language makes easy is largely limited by what's possible without installing a ton of third-party libraries. One of Python's most widely touted strengths is its large standard library (often described by the phrase "batteries included").

    Furthermore, C++ has flexibility: you can write C-like, close-to-the-hardware code one minute and turn around to use high-level constructs and advanced techniques the next. Using C++, you can write computationally intensive modules that run nearly as fast as possible, linking them directly to flexible high-level code without having to switch between languages or interface them together. That's why C++ is often used for games and complex desktop applications: it provides excellent performance where needed along with a large standard library and a grab bag of advanced language constructs that speed development time.

  10. #10
    Join Date
    May 2007
    Beans
    251

    Re: Discussing C and C++

    One of the reasons why C++ is still going strong has more to do with its abilities in simplifying modelling of application-domain concepts into code (which coupled with compiled-to-native-code nature of C++ makes for an excellent performing implementation).

    In case of C, you end up viewing everything from computer memory's point-of-view - everything as data and functions.

    This, I believe, is the primary reason why C++ is vastly popular for implementing GUI toolkits (compare QT (C++) with gtk+ (C)).

    Again, I'm of the opinion that what tool to use depends on both the developer's own preferences as well as the problem-at-hand itself.
    Some problems may have simpler solutions when implemented using C++ than C.
    Last edited by the_unforgiven; June 15th, 2012 at 05:48 AM.
    The Unforgiven

Page 1 of 3 123 LastLast

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
  •