Live data from Hacker News

Does C++ still deserve a bad rap?

nibblestew.blogspot.com

81–90 of 310 posts

Re: Does C++ still deserve a bad rap?

#81

> This code compiles, runs and works [1] on all major platforms using only the default toolchain provided by the OS vendor without any external dependencies or downloads. This is something that no other programming language can provide as of date. Isn't that provided by at least Golang and Zig currently?

> This code compiles, runs and works [1] on all major platforms using only the default toolchain provided by the OS vendor without any external dependencies or downloads.

I don't know, my OS vendor provides Bash, Python, Perl, and a great whack of CLI programs and libraries. I know Python programs are pretty useless on systems without Python interpreters, but so's an ARM64 binary on an x86-64 system. I get what the quote is trying to claim, but it doesn't stand up to much scrutiny.

Re: Does C++ still deserve a bad rap?

#82
for me the problem with C++ is not about the verbosity itself... it's more about how generally incomprehensible maybe even hostile it is towards you if you lack experience compared to other languages I've worked with (JS, Python, Java, Go, ..):

- navigating through template compilation error messages is a pain. - standard library is getting better, but still feels lacking. - different commonly used libraries have different code styles and reimplement the same things in different ways. - combine the previous two and you get small-ish projects where you have 4 or more different types of strings (char, const char, std::string, QString, ...) - no standard build/publish/compile/library distribution system makes using less-known external libraries a giant pain in the ass.

Re: Does C++ still deserve a bad rap?

#83

So first, C++ in a small codebase with a small team, is a very powerful language that really does produce the best code. That's what you want in a professional, top tier code base and that's what you get. Unfortunately, once a project grows to many developers, many of whom have varying levels of experience, it's just too easy to write bad C++ that becomes impossible to debug. I've been using it for a decade and I swe…

> So first, C++ in a small codebase with a small team, is a very powerful language that really does produce the best code.

"Best" is such an undefined term it's word-noise here. "Best" in terms of end-user extensibility? "Best" in terms of debuggability? "Best" in terms of having a single binary which can be copied and run without regard for machine architecture and OS?

Re: Does C++ still deserve a bad rap?

#84
post #76

Like every programming language out there, C++ is a tool. And like every tool out there it has its uses. There isn't any point of using C++ to count words in a text file. Any high-level language like Python will beat you to it. However, there's one thing you can do in C++ and not in Python or JavaScript or PHP: fully control the memory layout of your data. While you don't need it in most of the cases, it becomes a ki…

> There isn't any point of using C++ to count words in a text file. Any high-level language like Python will beat you to it. People using c++ usually care about programs finishing before the heat death of the universe. I had a few Python scripts that spend several seconds parsing larger files, after a rewrite to c++ that changed to almost instant.

it depends on what you're doing of course. It can even go the other way[1]

Generally languages like C++ are obviously much faster, but a lot of primitive stuff in languages like python is also just C calls and may be optimised to the point of being faster, because doing things in low level compiled languages often comes with its own tricks and problems.

[1]https://stackoverflow.com/questions/9371238/why-is-reading-l...

Re: Does C++ still deserve a bad rap?

#85

C++ is a very poorly designed language. A lot of the work being done by the committees is fixing Stroustrup's mistakes. Consider horrors such as this. In the following statement what are foo and bar? int x = foo(2) + bar(3); Most people will say foo and bar are functions and that's a reasonable guess. Unless you are talking about C++. In C++ foo and bar could be functions but could also lots of other things. For exam…

> Consider horrors such as this. In the following statement what are foo and bar?

I don't understand your point. What's exactly the problem of knowing what are foo and bar? Even if you struggle with C++, any half decent IDE allows you to check the symbol and see what's being called with a single mouse click.

So what's exactly the problem?

> As another example consider implicit type conversions:

Again, what's exactly the problem? If you write down "c+3" it's your responsibility to know what you are doing and that "c+3" does make sense. And your example can only start to become a possibility if you explicitly and quite intentionally define your constructors to allow implicit type conversions, which is a direct violation of basic C++ best practices.

Adding to that, your convoluted example is no where near the mess that's javascript or Python and somehow people manage to not screw that up even without any type checking.

So why single out C++ although it does provide all sorts of guardrails and sanity checks?

> Many of these craziness

You failed to show any semblance of "craziness" in any of the convoluted examples you presented. In fact, you only showed you struggle with a language you barely have any experience with, let alone a grasp on rudimentary best practices such as requiring explicit constructors. Thus, why pin the blame on the language instead of where it really belongs: your lack of knowledge and experience using the language?

Re: Does C++ still deserve a bad rap?

#86

I've never actually had a problem with c++ grammar or syntax or logic What I do have a problem with is trying to interface with more complex apis and functions. For example a while back I had to implement a https get and post request and it was a total nightmare. Something that takes only a few lines in python took a few days to figure out. Maybe it's lack fo experience but I tried wrestling with libraries like pocco…

Modern C++ with libcurl API’s still isn’t great. I’ve found the Python and Go http API’s much more intuitive.

Re: Does C++ still deserve a bad rap?

#87

So first, C++ in a small codebase with a small team, is a very powerful language that really does produce the best code. That's what you want in a professional, top tier code base and that's what you get. Unfortunately, once a project grows to many developers, many of whom have varying levels of experience, it's just too easy to write bad C++ that becomes impossible to debug. I've been using it for a decade and I swe…

C++ error messages have been gradually improving over time. Clang really raised the bar when it came along, and the other two compilers have been catching up. Concepts in C++20 will really help to further improve things for template errors.

Re: Does C++ still deserve a bad rap?

#88
post #76

Earlier quoted context omitted.

> There isn't any point of using C++ to count words in a text file. Any high-level language like Python will beat you to it. People using c++ usually care about programs finishing before the heat death of the universe. I had a few Python scripts that spend several seconds parsing larger files, after a rewrite to c++ that changed to almost instant.

it depends on what you're doing of course. It can even go the other way[1] Generally languages like C++ are obviously much faster, but a lot of primitive stuff in languages like python is also just C calls and may be optimised to the point of being faster, because doing things in low level compiled languages often comes with its own tricks and problems. [1] https://stackoverflow.com/questions/9371238/why-is-reading-l…

> but a lot of primitive stuff in languages like python is also just C calls and may be optimised to the point of being faster

That assertion makes zero sense if we take into account that parallelization is one of the most basic performance techniques there is, and Python's GIL simply eliminates that option except for multi-process applications which then require serializing stuff back and forth.

Python is pretty much unparalleled as a glue language, and excels at putting together small exploratory scripts for data analysis and number crunching applications, but it makes no sense to present Python as a performant alternative to C++.

Re: Does C++ still deserve a bad rap?

#89
post #45

Earlier quoted context omitted.

> There isn't any point of using C++ to count words in a text file. Any high-level language like Python will beat you to it. However, there's one thing you can do in C++ and not in Python or JavaScript or PHP: fully control the memory layout of your data. Any books or resources for digging deeper in these kinds of topics? I’m a Python developer and would like to learn C++ but the just the reasons you mentioned make i…

you can malloc() to get a memory range, or mmap() to get a disk-backed memory range with kernel-managed paging, and then you can do whatever you want with it. You get a pointer to the start of the range, and you know how large it is, so from there it's just pointer arithmetic and assignment. Easy peasy. Now you just have to make sure that you zero data when you're done with it, track how much of that memory is availa…

> you can malloc() to get a memory range, or mmap() to get a disk-backed memory range with kernel-managed paging, and then you can do whatever you want with it.

No need for that, as C++ provides placement new().

https://en.cppreference.com/w/cpp/language/new

Re: Does C++ still deserve a bad rap?

#90

Earlier quoted context omitted.

This story about the committees fixing Stroustrup's "mistakes" is completely made up from you and is not even remotely true. Also Stroustrup does _not_ take pride in how big the language is, the exact opposite is true. E.g. you will never ever hear Stroustrup speaking about template meta programming or similar weird stuff. He always tries to teach the practical side of C++. His C++ book is not big because the languag…

> Implicit type conversions are inherited from C, the language you called "awesome". It is true that C language has some very limited implicit type conversions. For example you can say: long n = 3; And the integer 3 is converted to long. This is extremely limited, and does not make the program hard to understand, which is completely different from the craziness you see in C++.

> C language has some very limited implicit type conversions

What? C will happily compile this:

    void g() {
        float f = 3.14;
        int* ip = &f;
    }
C++ has no such _craziness_. Your strawman actually has pretty good uses:

    complex c = 3i;
    ... = c + 4;
Would you rather have the last line not compile because 4 is not a complex number? Because one _could_ argue that 4 is a complex number, and C++ can represent this with an implicit constructor.

The issue with C++ is that implicit is the default, not that it exists.

Post reply on HN