Game World!

Join A World Of Gamers

Enter your email address:

Delivered by FeedBurner

Followers

Popular Posts

Tuesday, 29 June 2021

Is C++ badly designed?

 I found a bunch of quotes about C++. It seems a lot of smart programmers don't like it. So, people who like C++, what is your defense?

all 47 comments

[–]locknsock 11 points  

"There are only two kinds of languages: the ones people complain about and the ones nobody uses."

-Bjarne Stroustrup, The C++ Programming Language

[–][deleted]  

[deleted]

    [–]krum 4 points  

    Haskell enjoys a decent userbase

    not really.

    [–][deleted] 1 point  

    "Nobody" is an exaggeration.

    [–]BroughtToYouByMtDew 2 points  

    Focusing on that is missing the point.

    [–][deleted] 1 point  

    What point is that?

    [–]BroughtToYouByMtDew 1 point  

    .. That people who complain about C++ are only doing so because it's so widely used. Geez c'mon.

    [–][deleted] 1 point  

    I don't think that's it. I wouldn't complain about Lisp if Lisp was widely used.

    [–][deleted] 8 points  

    a lot of substandard programmers use it

    Literally true of every reasonably popular imperative language.

    [–]jedwardsol 5 points  

    Making decisions about a language based on cherry picking quotes is pointless.

    [–][deleted] 2 points  

    I don't think anyone does. But these quotes are useful to beginners who might otherwise think that C++ is a good language. And by the way, I don't have to cherry-pick much. Trying to find even one favourable quote about C++ is kind of hard.

    [–]balefrost 3 points  

    But these quotes are useful to beginners who might otherwise think that C++ is a good language.

    But C++ is a good language. Maybe not for beginners, but that's not the question you asked.

    [–][deleted] -3 points  

    It is not.

    [–]balefrost 7 points  

    If your mind is already made up, then why did you phrase your post as a question?

    [–][deleted] -3 points  

    I thought the thread would get fewer downvotes that way. :)

    [–]Tux1 1 point  

    (downvoting based on opinion)

    [–]balefrost 5 points  

    To be fair, you didn't find a page of quotes about C++; you found a page of quotes specifically bashing C++. You can't then say "see, C++ is therefore bad" when that's based on biased data.

    I dunno, my attitude is that modern C++ has a number of advantages over C. All else being the same, I'm pretty sure I'd pick C++ over C. Obvious exceptions might be doing embedded development or working on a C codebase. C has a certain universality to it. But man, buffer overflows...

    [–][deleted] 2 points  

    To be fair, you didn't find a page of quotes about C++; you found a page of quotes specifically bashing C++. You can't then say "see, C++ is therefore bad" when that's based on biased data.

    I didn't say that. Allow me to repeat what I said: "It seems a lot of smart programmers don't like it."

    [–]balefrost 2 points  

    My point stands: you found biased data. Bjarne Stroustrup is a smart programmer, and he obviously likes C++. I guarantee that there are others. Heck, those quotes only from famous programmers. There are plenty of smart programmers who aren't famous.

    My point is that you can't draw a reasonable conclusion about a language from a biased data set like this.

    [–][deleted] 3 points  

    Of course I found biased data. Everybody can see that, and I don't deny it. But I don't draw conclusions from that, I draw my own conclusions based on my experience with C++. The reasons I showed the quotes was to get a discussion going, and I thought that without them people would have found me easier to dismiss.

    [–]balefrost 4 points  

    I draw my own conclusions based on my experience with C++

    Your original post doesn't mention that at all. The only opinions in your post are in fact other people's "expert" opinions. That by itself is fine, but by then asking people who like C++ to defend themselves, you instigate an argument and set yourself up to commit the fallacy of appeal to authority.

    Honestly, I think you would get better results if you simply laid out your problems with C++. Then, people might agree with you or might be able to show you how you could use C++ better, perhaps resolving your issues with the language.

    [–][deleted] 2 points  

    The problem is that the reasons that I don't like C++ are hard to explain succinctly. But they are partly explained here (the first link in the original post): http://yosefk.com/c++fqa/defective.html Also I have forgotten a lot of details since I last used it. And third, beginners, who are the ones I want to reach out to, wouldn't understand what I was talking about anyway.

    [–]maestro2005 1 point  

    When C++ was invented, it was the only general purpose language that was expressive and performed well. The cost is complexity, and lack of safety everywhere.

    Now, most programming tasks don't need the sheer performance of C++, and other languages are even more expressive with far more safety (and comparable performance, in many cases). So there's not really a good reason to use it for a new project any more.

    [–][deleted] 1 point  

    Is C++ good or bad?

    It depends, but this is not a discussion forum, lad.

    [–]nyslyetia 1 point  

    C++ is fast and has high performance.

    [–]lizaard64 1 point  

    All of those quotes, are from developers who really knows what they're talking about - And all of those quotes are more or less accurate. However, sometimes you have no choice ...

    [–]Frectus 1 point  

    there is no good or bad, language is just a tool

    [–][deleted] 4 points  

    And /u/locknsock ...

    So what if a saw is dull and crooked, is it still just a tool? Couldn't you say it's a bad tool? And what if a beginner spends years learning this tool, isn't he wasting his time? You're saying it as if it doesn't matter.

    [–]Frectus 1 point  

    If he doesnt have problems with the language and it works as he wants it to work how is it bad?

    [–][deleted] 2 points  

    "He"? You're talking about the beginner? Well how does the beginner know what he wants? He knows only one thing.

    [–]locknsock 1 point  

    Is it a waste of time to learn OOP concepts? Is it really hard to learn other syntax of other languages if you know what classes, functions, arrays etc.. are? If you are so concerned about a group of developers opinions then go move on to use Java and C. It's a waste of time to research for days what language to use because that time you could have spent learning.

    [–][deleted] 2 points  

    That would be true were it not for the fact that C++ takes a very long time to learn compared to other languages.

    [–]locknsock 1 point  

    Then if you think it's not worth the time then you can move on.

    [–]ziptofaf 1 point  

    And what if a beginner spends years learning this tool, isn't he wasting his time?

    See, here is an important distinction. C++ is huge (according to Tiobe index it's a 3rd biggest language... ofc this isn't entirely accurate but I would say it's still in the top 5 for sure). You want to work with GPU computing using Nvidia cards? You need C++ (CUDA). You work with microcontrollers like Arduino? You need to learn C++. You want to make video games? Unreal Engine uses C++ for in-game events... and heck, game engines themselves are built using C++. It's not "wasting" time if you are learning something used on daily basis all over the world.

    So whether or not it's a "bad" language in this context is irrelevant since it has no real alternatives. Personally I do think there's a lot of place for improvement in it (especially lack of built-in package/libraries management) and some languages like D or Rust have attempted it but it doesn't change a fact that their popularity is a drop in the sea compared to C++. You don't really have much choice but to use C++ if you encounter problem domains at which it excels.

    [–][deleted] 1 point  

    Surely there are other languages that work on microcontrollers, for example C? One can also make games with other languages. Sure, if you are dead set on using an engine that is specifically for C++, then I guess you have to use it. But even then, C++ is not great. Wouldn't it have been better if there was another language in C++'s place right now, that was better than C++? The more people keep using C++, the more we are gonna be stuck with it. By the way, Jonathan Blow (creator of Braid and The Witness) is making a new language for games, just because he is dissatisfied with C++, and that's great.

    [–]ziptofaf 1 point  

    Surely there are other languages that work on microcontrollers, for example C?

    There are, sure. C is in fact popular. But C++ gives you concept of classes on top of it and a bit of security if you use it correctly via RAII. Those are not useless!

    Wouldn't it have been better if there was another language in C++'s place right now, that was better than C++?

    Personally I would love to see Rust in it's spot since I consider it a spiritual successor to C++. Heck, it can even be used to make libraries that are C ABI compatible. But frankly Rust is not easy either as it relies on multiple concepts from functional programming (this actually raises an interesting point - everyone knows that learning a different paradighm for a first time is hard. But were you to start from functional programming then can you comprehend it as fast as you would with OOP or procedural style?) and it's borrowing feature with built-in RAII requires quite a lot of understanding of what's going on as well. It prevents a lot of mistakes from C++ but it's not "free".

    One can also make games with other languages

    Like which ones? I will limit your space to move around and say you are building a fairly big game from scratch meaning you need a custom (or at least customized) engine. Suddenly you are VERY limited as all languages with Garbage Collector are a no-go at this point and you need something compiled directly to a given platform with manual control over memory allocation. C is fairly bad at game dev since this field synergizes a lot with OOP style. Documentation for DirectX assumes you will be using C++, same with Vulkan.

    It's true that many games in fact use C++ to do heavy lifting and something else (like Lua, Python, Ruby etc) to introduce in-game scripting but this C++ is still a core component in a game development sauce. You can't just throw away 40 years worth of code and try reinventing a wheel just to prove that it's possible.

    That being said - personally I don't even think C++ is a horrible language. If you learn it's modern version (so 2011+ style) it offers a sane amount of protections against memory leaks, solid basics (C does not even give you built-in dynamic array or a hash map) and OOP capabilities. It does struggle if you try going one step beyond (no reflections or interfaces/traits, templating can generate 2 pages long errors that are nigh impossible to read) but there is some progress in this area as well. C++ imho suffers from it's age and the fact that one really should only learn a modern subset of it rather than trying to comprehend EVERYTHING but ultimately it's unavoidable when you have something that exists since 80s.

    [–][deleted] 1 point  

    Like which ones?

    First of all it depends on what kind of game you are making, but I get your point. Personally I would try these things before C++:

    • C
    • Jonathan Blow's new language
    • Research more alternatives
    • Implement a new simple language based on elegant ideas similar to Forth or Lisp
    • Give up

    [–]ziptofaf 2 points  

    Implement a new simple language based on elegant ideas similar to Forth or Lisp

    Building a low level language to create an engine in it? No one does it. Literally no one. Creating your OWN programming language might be a task you can do in a day if you want to make another Brainfuck but other than that it can be decades. Plus vast majority of programmers does not even have a sufficient understanding of computer science to get it done... let alone the drive to write what, half a million lines of C code? Ruby or Python are both nice and elegant languages, have you looked at their source code?

    https://github.com/ruby/ruby

    1070 releases, 50763 commits. 389385 lines of C code (I actually copied repo to check) and 36196 lines of Ruby code. Have fun writing it. That's what it takes to make a "simple" language with consistent rules and predictable behaviour. Spoiler alert - it still however has bugs from time to time.

    Also:

    Lisp

    See, reddit source code was once written in Lisp. They have shifted to Python. Main reason being insufficient library support, the fact that you also had to teach every new employee on how to use it definitely did not help either. This same problem would occur in game development - you want people that can use a given solution easily and you also want a community around it.

    Jonathan Blow's new language

    Which is in VERY experimental phase, it doesn't even exist for public yet if I read it correctly. It can also be abandoned at any stage since there are no companies behind it and your choice of libraries is inexistant. Rust is like 1000x more popular (and heck, it even has some game engines available for it like Piston) and it's still considered very niche.

    Give up

    And yet you find a lot of programmers working in game development and using C++. Heck, you find C++ even in desktop applications on a daily basis (Qt framework was for instance used to make Battle.net client, OBS, KeePass or even VirtualBox) - which frankly isn't even that surprising considering it lets you build native applications that require nothing to work on a target platform, something that neither Java nor C# can accomplish.

    Yes, C++ is a relatively hard language to learn. It has it's quirks too. But it has a plethora of use cases in which alternatives to it do not really exist. But ultimately it's not nearly as bad as you are trying to make it sound like.

    [–][deleted] 1 point  

    I understand that Ruby and Python took a long time to write. But Forth, for example, seems pretty easy to make. And I didn't mean that I would make my own engine anyway. I realize that even having said this, it would be a lot of work, but I'd rather try it than use C++. And I said I would try it before using C++, not that I would be able to do it. I haven't thought very hard about how I would do it.

    When I said "Give up" I didn't mean that I'm incapable of learning and using C++, I meant that if I have to use C++, I'd rather not make a game.

    [–]chaotic_thought 1 point  

    Surely there are other languages that work on microcontrollers, for example C?

    For 99% of the things, C is just a subset of C++. If you know C++, then you know C.

    [–]Tux1 1 point  

    What about COBOL?

    [–]locknsock 0 points  

    Yeah exactly. If you don't like it move on.

    [–]krum 1 point  

    The best thing about C++ is that you can use fairly high level abstractions and still get optimized machine level performance and certain levels of determinism. Is it a mess? Sure! It has its place though.

    [–][deleted] 1 point  

    The high-level abstractions are supposed to save time and make you more productive right? But the fact that it is a very complicated mess kind of cancels that out.

    [–]krum 1 point  

    Naw, it's like how right after the Big Bang, matter cancelled out the anti-matter by just a tiny fraction. And besides once you've been on C++ for 25 years it's not so bad as long as you only have to read your own code.

    [–]TheInfestation 1 point  

    Ive said this this before and I stand by it. C++ is a strictly worse version of rust, the only tangible benefits of C plus plus over rust is, familiarity, more libraries and supporting existing code.

    Furthermore, of the four main domains of modern programming (Web, Desktop, Mobile and embedded systems). It doesn't fit well anywhere.

    1. Web, absolutely not. (Aside from web assembly)
    2. Mobile, absolutely not.
    3. Desktop (C++ does best in single threaded low memory environments, that just isn't desktop anymore)
    4. Embedded, here, C++ is a reasonable choice. Most embedded systems have API support for C++. Although, even cheap embedded Hardware is starting to become multi-threaded so I don't see C plus plus doing well here for very long.

    Note: for multi threading, pointers and references in general don't work well. That is why I say c++ does poorly here, c++ is about avoiding copying.

    Note: Some people say Rust is harder to learn than C++, but I believe it to be easier, as rust requires you to write more correct code. And learning C++ vs learning how to do C++ correctly is a quite different.

    [–]Tux1 0 points  

    Remember, don't downvote based on opinion.

    [–]Meefims 2 points  

    But do feel free to downvote things which either don’t or which are detrimental to discussion. This post isn’t actually about whether or not the language is good or a discussion of its pros and cons: it’s just here to bash the language while attempting to hold a pretense of being objective.

    This post doesn’t belong in this sub, as a result.

    Floating Button

    Button