News for hackers. Stuff that matters.
Re:I am sick and tired of hearing tech companies complain ab... by dheera on Wednesday May 19, 2021 @12:12AM (#27204485)
Depends a lot on how you use it.

You can pass everything by value, write very child-friendly C++ code, using std::map like Python dict and std::vector like Python list, and still VASTLY beat the speed of an interpreted, weakly-typed language like Python.

But nobody does that. Chances are someone on the team takes a shit about unnecessary memory copies, the code will be littered with a smattering of pass-by-reference and pass-by-pointer, there will be std::shared_ptr, std::weak_ptr, std::unique ptr everywhere, and if you're lucky some intern will have committed some C-ish C++ code that will leave you gift of memory leaks, and now all of a sudden you need everyone to understand all the nuisances of the language and how memory works.

Re:I am sick and tired of hearing tech companies complain ab... by amluto on Wednesday May 19, 2021 @12:30AM (#27204599)
> But nobody does that. Chances are someone on the team takes a shit about unnecessary memory copies

It’s not just performance. In any moderately complicated C++ program, you will want a function to mutate its argument, and this falls apart.

Sure, you can write in a pure functional style with immutable data structures, but I wish you luck implementing an immutable data structure with asymptotically reasonable performance without using pointers of some sort.

Re:I am sick and tired of hearing tech companies complain ab... by pkolaczk on Wednesday May 19, 2021 @01:20AM (#27204843)
Unfortunately many programmers underestimate the speed at which computers can copy flat regions of memory these days and overestimate speed of code littered with pointers and indirection. Often using pointers to avoid copying a few bytes leads to worse performance.

In my experience a combination of pass-by-value with move semantics provides good code readability and almost optimal performance in most cases, so that's my default. Unless a profiler disagrees in specific cases, of course.

Re:I am sick and tired of hearing tech companies complain ab... by amluto on Friday May 21, 2021 @10:43AM (#27234622)
> copy flat regions

A map or pretty much any nontrivial data structure is not a flat region.

In any event, waiting to optimize until a profiler tells you to is a reasonable practice as long as you pay attention to scaling. It’s very easy to write, for example, a JSON parser that performs fine in small tests and has a nice small n^2 coefficient. And then someone throws in a bigger input than you tested and your game takes ten minutes to load.

Re:I am sick and tired of hearing tech companies complain ab... by pkolaczk on Friday May 21, 2021 @11:18AM (#27235164)
> A map or pretty much any nontrivial data structure is not a flat region.

Not necessarily. A hashmap can be implemented in a way it stores both the keys and values in a flat memory region, as long as keys and values are fixed size, and such a structure is way more efficient that traditional array-of-pointers implementation, where fetching each key requires following a pointer and getting the value requires following another pointer.

Re:I am sick and tired of hearing tech companies complain ab... by amluto on Friday May 21, 2021 @03:38PM (#27238906)
The resulting code will still be asymptotically slow.