Live data from Hacker News

Does C++ still deserve a bad rap?

nibblestew.blogspot.com

131–140 of 310 posts

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

#131
post #113

Earlier quoted context omitted.

The overwhelming majority of C extensions release the Python GIL during calls to them. If you're in the situation described in the parent comment then you can parallelize just fine using threads.

> The overwhelming majority of C extensions release the Python GIL during calls to them. In that corner case you still have slow Python glue code calling fast C++ code. It makes no sense to claim that Python is performant based on the idea that it may be used to glue together calls to performant C++ code, while ignoring the fact that not only Python forces performance restrictions on it's code but also that C++ code…

The comment that started this discussion is about the specific case that most of your execution time is in libraries rather than your application code. In that Python is usually no slower to execute than C/C++. You disagreed with that by claiming that such programs cannot be multi threaded because of that GIL, and I just corrected that because it's untrue (edit: it's untrue in general, but especially untrue in this situation we're talking about).

To be honest I'm not sure what your new comment is about. If you're saying that Python is not necessarily faster than C then I'm sure no one going to dispute that; in the situation we're discussing, the performance of your code is totally dependant on the efficiency of the libraries that are doing all the work, not your glue code. If you're saying that Python is slower than C when it's doing a non-trivial amount of the execution, then sure, but no one was claiming that either. Or maybe you just want to simplistically categorise languages as "performat" and "non-performant" without thinking about the specific contexts they can be used in, but that wouldn't make any sense. Did I misunderstand?

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

#132
post #90

Earlier quoted context omitted.

> 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 implic…

The second case is easily solved by having an overload operator+(complex lhs, int rhs). No need to convert anything.

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

#133
I never even really got to the point where most of the stuff from the article would be relevant to me.

Whenever I'm forced to using C++ only a tiny amount of the time is spent actually implementing my ideas.

Most of the time is spent figuring out how to fix incredibly cryptic compiler error messages that usually have nothing to do with what I actually did wrong.

Then I have to figure out how to get all the dependencies in a way that will still work in a year or two, without directly committing them to my git repo, and setting up various complex build tools that were created decades before anyone even imagined package management.

Finally I hope that nobody will ever look at my code because I definitely didn't follow "best practices". The best thing I can do is sprinkle "const" wherever I can because of my religious belief that immutability should be the default. If I wanted to stay up to date with the latest developments in C++ and the accompanying proper ways of doing things I feel like I'd have to forget what little I know about the language every time I used it and learn it all over again, just to avoid doing stuff that some blog post now says is "considered harmful". I might as well try staying up to date with JavaCoffeeTypeScript using the latest AngularReactVue and whatnot.

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

#134
I've been programming C++ for years. Trying to keep up with modern C++ took a lot of time, which I feel is better spent on other stuff, like reading "Designing Data Intensive Applications" or something similar than yet another Scott Meyers book.

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

#135
post #101

C++ fills a niche and probably if you use it all on your own you don't even see the problems. But if you use it at scale with multiple developers you can see it's layers of leaky abstraction laid down since the 80s that can never really be cleaned because too much is built on this foundation. This slightly over 100 page book on move semantics https://leanpub.com/cppmove shows some of the iceberg like complexities dot…

> This slightly over 100 page book on move semantics https://leanpub.com/cppmove shows some of the iceberg like complexities dotted all over the place. Some developers probably never use and have never even heard of move semantics.

I think Scott Meyers' "Effective Modern C++" which is in large part a collection of caveats and description of things which don't fit always together also underlines that impression:

https://www.amazon.com/Effective-Modern-Specific-Ways-Improv...

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

#136

As someone who writes <5 commits of C++ per year, it is very frustrating. I can’t get through a code review without reviewers referencing at least 2 blog posts about proper style for modern C++. I’m sure if I were an expert who used it every day I could remember all the gotchas and best practices, but it sure is tedious to deal with occasionally. Too many foot guns and conventions, not enough constraints in the langu…

So C++ doesn't have linters? Why not configure the subset acceptable.

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

#137
post #101

C++ fills a niche and probably if you use it all on your own you don't even see the problems. But if you use it at scale with multiple developers you can see it's layers of leaky abstraction laid down since the 80s that can never really be cleaned because too much is built on this foundation. This slightly over 100 page book on move semantics https://leanpub.com/cppmove shows some of the iceberg like complexities dot…

FORTRAN is still quite popular in many fields of scientific computing and C++ hasn't become ubiquitously mainstream so there's probably quite a lot of potential here.

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

#138
If you dedicate a large amount of your career on C++, you can be quite productive writing very robust performant code, and these days its getting easier and easier.

I've been coding C++ since 1996, and to this day it is still a joy. I do a lot of back end node/typescript, and after dealing with the loosy goosy types and stuff in that language, coming back to a concrete hard core language that requires a much higher intellect to write in, is frankly refreshing.

I've always felt writing in C++ requires much more skill, and that alone is a very rewarding experience. I can tune things like arena allocators and make string operations insanely fast, things I agree most problems simply don't require, but still, its a craft that I feel very proud of conquering, and every day you learn something new.

So if you like a challenge, if you like learning, or maybe if you simply enjoy flexing your brain cells a bit more then most, C++ delivers that on all fronts.

As for whether it deserves a bad rap, that's a little too generalized of a statement, and it reeks of dogma. Ignore dogma, dive in, learn for yourself what you think sucks or doesn't.

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

#139
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…

To be fair, C++'s standard I/O library is really bad. There is probably an almost universal consensus in the C++ world that the locale library is the worst standard library, immediately followed by iostreams. For small programs that's annoying, although using libc IO is usually fine for them. However, C++ is probably one of the top 3 languages for developing large applications (Java would also be there, not sure which one is the third in that pack) and for these having to roll your own IO is usually no biggie, because it probably would have been done anyway (e.g. even if iostreams wouldn't be so bad, it would likely have no place in the IO system of a content creation app or being used in HDF5).

In that sense, C++ is not batteries included, which can be annoying for small and medium projects.

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

#140
post #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?

It's quite obvious that the poster was referring to codegen.
Post reply on HN