What are some things that are easy to do in C++ but hard to do in Rust/C?
C++
Other urls found in this thread:
cglab.ca
twitter.com
Write good programs.
>hard to do in C
Make safe abstractions and clear interfaces against them.
Implementing Object-Oriented Design Patterns.
Java-style OOP in C++ is a mistake, too many pitfalls.
Deep inheritance was a mistake but composition is still good.
Agreed
Inheritance of anything other than abstract virtual base classes is a mistake.
is-a
has-a
Etc.
Nothing wrong with inheritance when done right.
might as well just have type traits desu
Write generic high performance data structures
You can do that in Rust easier than in C++
use c++ libraries
how does a linked list look in Rust?
I would if C++ made them convenient and non-ugly to use.
Maybe when concepts arrive.
C++ will probably never beat Rust traits though, which can be used for both monomorphized generics and dynamic polymorphism whenever you please without changing anything.
About the same as it would look in C++, but with Rust syntax.
>high performance data structures
I know, just indulge me.
struct LinkedList {
item: T,
next: Option,
}
Sent from my phone.
next: Option
correction
looks pretty awkward to me desu
Linked lists are awkward to begin with.
It's one of the simplest and most obvious data structures I can think of. It's the bubble sort of data structures.
FPBP
Disgusting
Now do a doubly-linked list in Rust.
Protip: You can't.
And why doubly-linked lists? Because forget about advanced graph data structures if your language can't elegantly implement doubly-linked lists.
You can, using unsafe blocks.
Or the linked list implementation that's in the standard library.
What's unsafe about doubly linked lists? I mean, how are singly linked lists safer than doubly linked lists?
You have to use pointers and pointers are scary :c
But you have to use a pointer with singly linked lists too. Is one pointer okay but two are too much to trust the programmer?
I'm guessing Box is analogous to unique_ptr. Only makes sense to have a singly linked list in that case.
People went overboard with it. Making light use of it without creating shit like SomethingFactoryInterfaceProvider is still the most powerful way to model software.
People go overboard with all C++ features e.g. templates.
That fucking syntax, it's like C++ template hell.
What do you consider going overboard with templates?
Because typetraits are nice to have.
If you're referring to template metaprogramming, constexpr exists now.
Thank god it does, TMP was a hack.
anything that involves a complex data structure/design/algorithm can be written and tested LITERALLY a hundred times faster in C++ and Rust
but it will run slightly slower
if you know Rust then it's even better in my opinion because its standard library appears to be much more logical and modern
get a job
thanks party pooper
Shoot in your leg
I made you a version without the watermark.
Preventing memory leaks
write fucking unreadable code
No.
Nothing