Better HN
topnewbestaskshowjobs
Log inSign up

naertcxx

10 karma · joined Jul 2, 2024 (2y ago) · 3 submissions

Submissions

comment 2y ago · link · parent

For algorithms like the ones in CLRS, which are explicitly written and proven with pointers in mind, definitely.

As I wrote, the stdlib++ agrees. Read that code and reevaluate your view on whether it is ridiculous.

For other graphs, it depends on the specific application. I am not saying that shared_ptr is always wrong, but often it is.

comment 2y ago · link · parent

I agree with this. Python is now more complex than C++. Python looks as if it is simple, because the syntax looks clean.

If you read the new "compilers" [1] in packages like PyTorch, which are unfortunately written in Python, you stare at a huge code base with walls of text, objects calling one another in a maze of ravioli code and generally no help at all to make sense of it all.

Compare that to the gcc code bases, where it is always possible to find some entry point to understand the whole thing.

[1] "compilers", because despite the huge code base (wasn't Python supposed to be terse?) they preprocess the function graph and then call g++ and Triton to do the actual work.

comment 2y ago · link · parent

I think the focus on smart pointers is a huge mistake. Code bases using shared_ptr inevitably will have cycles and memory leaks, and no one understands the graphs any more.

Tree algorithms that are simple in literature get bloated and slow with shared_ptr.

The only issue with pointers in C++, which C does not have, is that so many things are copied around by default if one is using classes. So the way to deal with tree algorithms is to have a hidden tree with pointers and a class that wraps the tree and deletes all dangerous copy methods, implicit and explicit.

stdlib++ seems to use that approach as well.