Live data from Hacker News

Does C++ still deserve a bad rap?

nibblestew.blogspot.com

41–50 of 310 posts

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

#41
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 language.

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

#42
post #10

C++ 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.

35 min of this statement and nobody to tell us of why, we, the C++ sinners, must convert to Rust or face the damnation in the hell of eternal unsafety and infinite bugs.

It must be some kind of HN record.

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

#43

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…

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

I don't think lisp is that beloved here. It's just that the few people who love it love to bring it up.

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

#44

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…

> I am sure any such developer will get equal treatment from another who is an expert, right?

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

#45

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. 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 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?

#46
C++ is, quite rightly, considered an overly-complex and bloated language. A lot of newer features are papering over poor design from the beginnings of the language.

But..

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?

#47

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…

A lot of this comes down to expectations. I would treat C++ like, say, kind of like a cabinet full of chemicals, rather than like (say) a typical home toolbox. You (hopefully) don't just grab containers and mix their chemicals and expect to learn by doing that 5 times a year; you really need to start slowly and take time to learn all the dangerous pitfalls properly, or otherwise expect to be told exactly what to do down to the most minute details. Adequate training for it is simply a prerequisite. C++ is kind of similar in that respect.

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

#48
post #2

I 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.

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

#49

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…

From memory, a thing i've implemented in C++ that its basically impossible in almost any other languages (with few exceptions).

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?

#50
post #2

I 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.

The trouble is often it doesn't matter and literally any of those would be useful, and yet none of them exists for you to use, so you have to waste time reinventing the wheel.
Post reply on HN