Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I 100% agree with the title, but some of the complaints in this article have been addressed since the article was published by C++11, C++14, or C++17. Others are just weird.

> If you've heard anything about C++, you've probably heard that there's no standard string class and everybody rolls their own.

Is this still true? std::string seems perfectly reasonable now, especially now that they've given up on supporting ropes and integrated the small string optimization. Yes it doesn't specify an encoding.

> No garbage collection? Check. No refcounting? Check. Need to allocate/free heap space just to pass a string constant to a function?

Nothing else in the standard library is garbage collected or refcounted by default. Why would std::string be the lone exception? You can opt into refcounting for any type using std::shared_ptr.

The objection about allocating/freeing heap space is about APIs that take const std::string& being passed C-string literals. Legitimate complaint, but it's addressed by std::string_view now.

> ...rant about lack of []= operator...

[] mutating the map does surprise people, so that's definitely a legitimate complaint. And it is annoying to have to use find() in a const context...

but simple operations like counting are simpler and more efficient in C++ than in Python because the +=, -=, etc operators work:

  for value in list:
    counts[value] = counts.get(value, 0) + 1
vs

  for (auto& value : list)
    counts[value]++;
> So actually C++ maps are as fast as python maps, assuming your compiler writers are amazingly great, and a) implement the (optional) return-value optimization; b) inline the right stuff; and c) don't screw up their overcomplicated optimizer so that it makes your code randomly not work in other places.

This is just comical. Python is not playing in the same performance league as C++, regardless of whether inlining or RVO happens. RVO of course is a general optimization for returning objects by value from functions, not a special case to optimize setting map items. It's still relevant, but less important since C++11's move semantics.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: