Does C++ still deserve a bad rap?
41–50 of 310 posts
Re: Does C++ still deserve a bad rap?
#42C++ will be around for at least the next 100 years. It's an ISO standard used by business and government all over the world. Modern C++ is very safe and fast too.
It must be some kind of HN record.
Re: Does C++ still deserve a bad rap?
#43C++ 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…
"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." Same as in Lisp, one of the most beloved of languages on HN. Were Lisp's macros a mistake? Some will say yes, but overall the language is more praised for them than damned. So highly regarded are Lisp macros that many languages wil…
Re: Does C++ still deserve a bad rap?
#44As 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…
Re: Does C++ still deserve a bad rap?
#45Like 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. 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 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 available or used (and which sections), and (optionally) implement your own defragmentation and garbage collection.
Unless you desperately need to specifically manage the memory layout of your data (e.g. for alignment purposes for massive data processing), none of this is worth the time or trouble to do for most projects, not only because it's a huge amount of work for little gain, but because you'll almost definitely screw it up and potentially corrupt your entire data set.
Note that, at least for the on-disk hashmap set, you absolutely can do this in python, so if you're interested in experimenting with this sort of data management, practice it there first.
A good place to start: https://github.com/luispedro/diskhash
Re: Does C++ still deserve a bad rap?
#46But..
There is something about the use of destructors, RAII, and even smart-pointers that just feels so...elegant? I'm not sure what the word is I'm looking for. I feel like there's a kernel of a beautiful language hiding in c++ and those features are the integral parts of that.
Re: Does C++ still deserve a bad rap?
#47As 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…
Re: Does C++ still deserve a bad rap?
#48I say this with a lot of love for C++, and I think it has gotten much better, but just try splitting a string via another string as the delimiter...
Do you want to truncate the string? return new strings? return string views? It all depends what you need.
In some languages all strings are immutable and all operations result in new strings and you have no control over that.
Re: Does C++ still deserve a bad rap?
#49Like 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…
Represent a data table in memory where the columns are from different types, where the data is backed by a arena allocator and represented contiguously in memory.
Of course you can do a data table representation in almost any language, but once you benchmark the implementations, the languages that gives you full control of memory and are good at moving bytes are the ones that lead in performance.
Lars Bak once said that C++ is a great "byte chunker" (if i recall the term correctly), explaining why its a good language to create a compiler or a VM in it.
Re: Does C++ still deserve a bad rap?
#50I say this with a lot of love for C++, and I think it has gotten much better, but just try splitting a string via another string as the delimiter...
In C++ you can implement it in a way that gives you much more control. Do you want to truncate the string? return new strings? return string views? It all depends what you need. In some languages all strings are immutable and all operations result in new strings and you have no control over that.