• Home

CodingExperiments.com

$ sudo make money

Search

Category:

  • Apple Inc.
  • Facts
  • Fun
  • Google
  • Google Android
  • Ideas
  • Internet
  • Linux
  • Microsoft
  • Programming
  • Rants
  • Security
  • Uncategorized
  • web 2.0

Archives:

  • April 2010
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007

Pages

  • About
  • About
    • The Authors
  • Commenting your code
  • How to Write Papers with Groff
  • ModCMS Anti-Spam Component Set
  • ModCMS Technical Specifications
  • Regular Expressions Guessing Game
  • Saving code directly to a web server
  • The (Almost) Perfect PHP 404 Page

Meta:

  • RSS
  • Comments RSS

Awesomeness tracker

CodingExperiments at Blogged View blog authority
Free Page Rank Tool

Why I Dislike C++

April 13th, 2008 by i80and

I’ve always been a big advocate of C. The simplicity of the language is elegant and beautiful. It’s clean, fast, and it’s everyplace. But “recently”, I’ve heard disturbing rumors of an upstart language attempting to capture C’s market share: C++. Having a reasonable amount of experience with C, and having taken a class on C++ at the University of Minnesota, I feel at least partially qualified to explain–in my usual cynical and aggressive way–why C++ is not conductive to streamlined program development. To open, I wish to quote Linus Torvalds, benevolent dictator and bigwig of Linux:

C++ is in that inconvenient spot where it doesn’t help make things simple enough to be truly usable for prototyping or simple GUI programming, and yet isn’t the lean system programming language that C is that actively encourages you to use simple and direct constructs.

C++ is a horrible language. It’s made more horrible by the fact that a lot of substandard programmers use it, to the point where it’s much much easier to generate total and utter crap with it.

Also I wish to quote Eric S. Raymond’s excellent The Art of Unix Programming:

…the language’s principal designer has conceded that he doesn’t expect any one programmer to grasp it all. Unix hackers do not react well to this; one anonymous but famous characterization is “C++: an octopus made by nailing extra legs onto a dog.”

  1. Performance – There’s persistent rumors that C++ programs are slower then C programs. This seems logical, seeing as how type polymorphism and other object oriented techniques are much harder–and in some places impossible–to optimize than simple procedural programs. This on its own is insufficient, however, as choosing a language purely based on performance is in many cases premature optimization. Therefore, I proceed.
  2. Beauty – C++ is, quite simply, ugly in my opinion. While the syntax of C can be learned in a few hours, the syntax of C++ can take days to fully understand. It’s filled with absurd and petty little rules, specifically in operator overloading, type polymorphism, inheritance, namespaces… in fact, let’s just say everything. This I imagine is debatable. However, as a student of the language who was already familiar with comparable languages such as C and Python, I found it to be a mess. Especially since many features of C++ are quite brittle and break if you don’t use OOP and only OOP. Try uses an enum with templates, and watch as your compiler starts yelling at you.
  3. Why? – This is a biggie. Quite simply, C++ fixes nothing. The big problem with C was memory management. Sure, you can boast about how automatic garbage collection is for wimps and whatnot (as I have), but pointers are one of the biggest sources of bugs in C. C++ did absolutely nothing to fix this. It’s like Subversion versus CVS (Watch Linus Torvald’s talk about git here); they missed the point.
  4. Debugging – I can easily imagine C++ programmers regularly having nightmares featuring compilation errors, and for good reason. While most languages like C and Python give fairly clear errors, a simple syntax blip in C++ can–and will–turn into a page of bizarre and non-readable errors that have absolutely nothing to do with the actual problem. To quote one of my TAs to the best of my ability (I took the class a while ago),

    That’s why some people hate C++ with a passion.

  5. OOP – Firstly, let me point out that I do, in fact, like OOP. I use and love it in Python. But I don’t lay awake at nights thinking “Gee, I wish C had classes!”. Rather, I lay awake at night thinking “Gee, I wish C didn’t make me manage my memory manually!”. This is much like point three; the designers of C++ missed the point. But that’s not what this point is about. I wish to quote again Eric S. Raymond in The Art of Unix Programming:

    They encourage architectures with thick glue and elaborate layers. This can be good when the problem domain is truly complex and demands a lot of abstraction, but it can backfire badly if coders end up doing simple things in complex ways just because they can. All OO languages show some tendency to suck programmers into the trap of excessive layering. Object frameworks and object browsers are not a substitute for good design or documentation, but they often get treated as one. Too many layers destroy transparency. It becomes too difficult to see down through them and mentally model what the code is actually doing. The Rules of Simplicity, Clarity, and Transparency gets violated wholesale, and the result is code full of obscure bugs and continuing maintenance problems.

    This isn’t a problem necessarily with OOP per se, but it does make it easy to shoot yourself in your own foot, which C/C++ already make quite easy via memory management. This topic is very complex and obviously full of political landmines (since, unfortunately, in non-Unix environments, C++ has been offered as The Solution). I highly suggest reading The Art of Unix Programming if you have the time.

I wish to emphasize that C++ has its place. It’s not uniformly bad, and in some situations such as games and GUI development, it will probably make the developer’s life much easier. But the point of this article is to suggest that in many cases, it’s better to steer clear of it.

EDIT:
I should clarify a little bit. C++ was not hard for me to learn (though truth be told my class didn’t get too deep into templates and didn’t cover namespaces.) I just don’t think that the extra complexity inherent in the language is worth the gain.


Posted in Uncategorized | View Comments

  • dasir
    yes, I agree with you ...
    C++ sucks :-D
  • ivag
    As I can see you did not learn C++ in Minnesota. For me that is the only explanation for what you said heare. I am C and C++ programer for a long time and when I have to debug some C code I have a migraine. For instance in C code I found situations where GOTO function is the only way to do something easy (and to kill the functionality of the code as well). Because of that for the last 2 years my job is translating C code in C++ in science institute I am workin at. We calculated that it is much cheaper to translate all the software to C++ then to maintain C code.
    Debuging C code larger then 1000 lines is harder then writing all code from the begining. I have no problem with debuging C++ code larger then 30000 lines that I did not write.
  • Guest
    In your dreams. Other than (unproven) academic credentials that are worth nothing in the world of coding, your prose brings no hard facts.

    So much for the pertinence of your 'reply'.
  • PierreGau

    The current trend is Web Applications (PHP is seen as 'sexy').

    But plain-old C can bring one thing or two in this area:

    TrustLeap G-WAN is a Web Application Server which is faster (in user-mode) than IIS 7.0 (in the kernel).

    G-WAN ANSI C89 ('edit & play') scripts are 5x faster than ASP.Net C#.

    G-WAN C scripts are 120x faster than PHP.

    G-WAN is up to 38x faster than Apache.
    G-WAN is up to 25x faster than Nginx.

    One of the reasons CPUs sold well was bloated code.

    No longer: with the CPU frequency halt, inefficient code will not longer scale on new CPUs because by using more Cores they are more powerful, but not faster, see:

    http://trustleap.ch/en_scalability.html

    So, whether the world (including youngs) will learn how to code properly or, well, they will have to buy twice as much servers to make their Web Applications work twice faster.

    Just adding CPUs (or CPU Cores) is a much less expensive proposition.

    As a result, skilled C programmers have a bright future: the 'sexy' PHP will not survive without C.
  • Noogie
    I "regressed" from c++ to c. But really its progress. I really just can't stand c++ anymore.

    And it's not just the language, but the people that use it. It's like talking to cult-members. I'm sure they'd all fellate BS if he walked in the room.

    I've been doing some googling about it just to know I'm not the only one, and found your diary..but also some nice quotes:

    http://harmful.cat-v.org/software/c++/
  • Rio
    Hi Dudes... you are completely beginner. NASA used C++ in one of their rover. Again it is C++ , not phyton nor c. Please open your eyes and mind. Good things are always hard to understand.
  • Anonymous
    C++ is a POS. Bjarne should do something constructive with his life.
  • i80and
    Thanks for the feedback, Wolfgang. I will agree that my knowledge of C++ is less than what would be optimal for critiquing it.

    C++ does indeed have more features than C or Python. I question whether these features actually help it or not, however.

    If you understand the error messages, good for you. Personally, I have better things to do than read a page or two of template errors for a trivial glitch when a single line would tell me just as much >90% of the time.

    Beauty is in the eye of the beholder. I'm not talking about beauty in the code, however (although I think that the abstractions that C++ allows can be more trouble than they're worth); I'm talking about the actual syntax of the language itself. I'm sure once you see it enough times, it looks fine. But I like the K.I.S.S. rule when applied to languages; the syntax of the language itself should be minimal and just enough to perform the required task. Python has a much simpler method of operator overloading, for example (although it isn't an optimal comparison as Python doesn't have static types).

    Again, thanks for the comment. You probably do have more experience with C++ than I do, and therefore you probably are more qualified to discuss the topic than I am. I'm just remarking on my thoughts on the matter, with some quotes thrown in for good measure. In the end, the language you like is more a matter of taste than anything else. If you like C++, then that's great. More power to you.
  • Bob
    The violin is still frustrating and difficult after only taking a single class with it as well. Mastery takes time.
  • Wolfgang
    C++ has its problems, but I don't think you've had enough experience with C++ to really make these sorts of judgment calls about a language you're still quite a novice in.

    Of course C++ is harder to learn than Python or C, it's got many more features.

    As a developer who writes plenty of C++, the error messages don't bother me at all. I know what they mean and why I get them. The bad bugs are the ones that happen when your code compiles.

    I would say that many people are better off programming in other languages, but the advantages that C++ offers are really nice in some scenarios. I *like* that C++ can still do low-level memory management if it's required, yet usually can get by with well-designed abstraction in classes. You think C++ is ugly because you haven't seen pretty C++ code. Some of the prettiest code I've ever seen was in C++, even using generics.
  • falafel
    C++ gives you the ability to make powerful abstractions in a simple way without significant performance tradeoffs as in other "high level" languages. Also, the zero-overhead principle is great: don't want to use virtual functions? Don't pay the runtime cost.

    You also seem to have missed generic programming, which is an extremely powerful abstraction. Remember that C++ is not an OO language, it's a general purpose language.
  • Jack
    Wow, sorry your first commenter was nasty. I've dabbled in many programming languages, but C++ was my first real programming language. While it seemed cool at the time, it turns out that it is arbitrary, obtuse, and overcomplicated. It inhabits a derelict space between lean, clean code machine and butch, fully-equipped armory, taking the advantages of neither. Newer, experimental languages seem to have a lot of promise. Thanks for breaking it down.
  • i80and
    Congratulations on completely missing my point. Your fantastic syntactical structure and phrasing makes a powerful argument.

    C++ was not hard for me to learn. It was, however, harder than C, and I'm arguing that the added complexity does more bad than good.

    Also, do you have any rationale for its being "a very good programing [sic] language"? Under most debate systems that I'm familiar with, one has to offer counter-evidence to their opposition. Unless you can quote a study disproving all that I have said, my points still stand.
  • Fight4Right
    Don't dare to say anything bad about C++.

    C++ is a very good programing language.
    So if it's to hard for you to learn it's not a problem about
    C++ it's about you.
blog comments powered by Disqus

 
Wordpress Themes by and Website Templates by Blogcut Blogged Blog Directory Blog Directory - Blogged