Rust

It's not possible implement doubly linked lists and directed cycle graphs in Rust.

Why does it even exist?

Other urls found in this thread:

jaxenter.com/power-ten-nasas-coding-commandments-114124.html
cglab.ca/~abeinges/blah/too-many-lists/book/
github.com/rust-lang/rust/blob/master/src/liballoc/linked_list.rs
github.com/rust-lang/rust/blob/master/src/libcore/ptr.rs#L1161
doc.rust-lang.org/std/collections/struct.LinkedList.html
kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/
twitter.com/NSFWRedditImage

It's for people who are too stupid to learn C to feel like they're programming.

You can with unsafe code. I still have to try, but I guess it's alright.

>tfw no recursive closures
Can someone explain me why?

>You can with unsafe code.

But unsafe Rust has no advantage over C++11.

The main point is to limit unsafe areas as much as you can. Also, you have a modern language instead of a bloat full of shit because of
>muh retrocompatibility

It's still work in progress, but it looks like a solid language overall. Dunno if it will ever replace C++ tho.

Rust and safety is much like how the TSA works, at what cost?

Anyway good programmers are good programmers that don't rely on the language to restrict them.
jaxenter.com/power-ten-nasas-coding-commandments-114124.html

>Rust and safety is much like how the TSA works, at what cost?

Perfect description.

cglab.ca/~abeinges/blah/too-many-lists/book/

>All loops must have a fixed upper-bound. It must be trivially possible for a checking tool to prove statically that a preset upper-bound on the number of iterations of a loop cannot be exceeded. If the loop-bound cannot be proven statically, the rule is considered violated.

Your response to a restrictive language is to use a non-turing complete subset of some other language?

Because C++ is an ugly mess. Yet Rust is already an uglier mess without having decades of backwards compatibility to worry about.
Impressive.

>no recursion
How the fuck else am I supposed to draw terrain and check terrain collision for top down games?

github.com/rust-lang/rust/blob/master/src/liballoc/linked_list.rs

>Struct core::ptr::Shared
> This is a nightly-only experimental API.
good job adding completely needless refcounts to a linked list, I'm sure this is gonna perform well :)

>>C++ ugly

Not anymore. 11, 14 and 17 fixed that.

Adding more shit onto a language just makes it harder and harder to read. smart pointers and move semantics are wonderful constructs and I agree that C++11 was a major turning point in the usability of the language but it remains overloaded with heaps and heaps of legacy shit

It's not refcounted, it's basically a raw pointer with additional compile-time information, like not being NULL and covariance: github.com/rust-lang/rust/blob/master/src/libcore/ptr.rs#L1161 , it has no runtime costs. You should really spend some time actually reading about stuff before posting.

You don't have to use all of the language. You can write fast, secure code with modern lazyness without ever touching memory. Don't shit on the language for having features.

So much legacy code does use those parts of the language. C++ only became truly usable with 11 and it wasn't taken up immediately. There is an absolute shitton of hellish C++98 code out there.

So? Legacy code will alway exist. Gradually move older code over and start new projects directly with 11 or better.

The funny thing is: some Rust enthusiast is proud of spending 10x as much work on this. Reality will hit Rust fanboys once regular programmers are forced to use the language at their jobs. They'll just take the path of least resistance, which is *mut T and a large unsafe block.

>pulling shit out of my ass: the post

It's a trade off when using Rust. Either you can put more time into your shit up front and spending less time fixing bugs afterwards.
Usually it's much more expensive to fix shit after something has hit the market.

Nice arguments. Might want to go back to your /r/rust echo chamber.

The funny thing is, everytime you cult followers celebrate a hole in a C/C++ software, the software in question is usally:
- 10 years or older
- riddled with legacy code
- underfunded
- ignoring all programming best practice
- maintained by some old guy who lost motivation years ago

Only fair to assume none of this will ever happen in magic Rust land, the place where people just follow the rules and Pjaet will tell his supervisor "Just another 10 weeks until my linked list is ready, sir!" because he's so eager to write that shit in 100% safe code.

> Nice arguments.
I don't need arguments to refute unsubstantiated claims like "They'll just take the path of least resistance, which is *mut T and a large unsafe block". All you have to do is to check popular Rust repositories to see that unsafe is used only when necessary with as small blocks as possible, even in such low-level projects like Redox. I have no idea what you based your statement on.

> everytime you cult followers celebrate a hole in a C/C++ software, the software in question is usally [...]
Again, you pull that out of your ass, projects like kernel, bash and openssl are well-funded, have large teams and supposed to have a high-quality code, same goes for proprietary code like SMB in Windows.

I think someone here once told me this programming language is related to jews, blacks and women with bad personalities. Or transsexuals?

I dont remember how all of that made sense, but it seemed to at the time. I might have been high though.

Nice language based on OCAML becomes "safe" circlejerk, by people use JavaScript and never write low level code on real world.

I'm learning it right now, it's not too bad.
I never had felt the necessity to do doubly linked lists, directed cycle graphs and riding unicorns. You are probably a shitty C++ programmer

linked list is a meme

use vectors

can I ship rust as a single executable on windows (no gcc dlls or other bullshit) yet?

Yes, it supports VS toolchain as well.

>need to regularly insert an element at the front of a 100,000 elem vector

just fuck my shit up

Insert at the back and then reverse, or just use deque, there's really no reason to use linked lists in 2017.

O(1) to insert at back
O(n) to reverse

So literally no difference from what I said initially. Good job, pajeet.

except now you get cache locality and O(1) lookups

>But unsafe Rust has no advantage over C++11.
You mean, besides better package management, default build system and standard library.
And it's not like unsafe makes your whole code unsafe.
And it's not like you should use linked lists, ever, those are a relict from the home computer aera when CPU caches weren't a thing.

How can you even live being this retarded

What's wrong with it? If you need to insert 10000 values at the front of a vector it's faster to push_back them and then reverse the vector.

That's still O(n) when you could have O(n) with linked lists

except the vector has O(1) indexing and cache locality, and doesn't have two pointers overhead per element

But a linked list would make n allocations, would take O(n) to index and would be extremely slow to iterate over.

>in this case where linked lists are inappropriate, linked lists are inappropriate

genius

linked lists are inappropriate in almost all cases

>almost all cases
>no reason to use linked lists in 2017

Really makes u think.

this, even most soc have a CPU cache

prove me wrong

>100,000 elem vector
Sign of a bad programmer

He uses linked lists because his language doesn't have vectors kek

A vector is a dynamically resizable array. Any non-meme language has it.

Except for C

C has realloc.

So does other languages

no shit?

it's so women and black people can get into system programming

Implement a stack yourself. Recursion is poor-man's iteration anyway.

Just use the built in LinkedList from the standard library, which is doubly linked?

doc.rust-lang.org/std/collections/struct.LinkedList.html

The Rust standard library is actually good, unlike the C++ STL which is ignored by every major library where all basic functionality is reimplemented with an extra Q in front of the name.

More likely, a 2nd year CS student taking data structures 101 and can't conceive of stdlib-provided generics.

>The Rust standard library is actually good
Dogshit compared to Go's

t. buttblasted rust babby

Go can't even enforce type safety on its linked lists.

The standard library only has a linked list of interface{} objects, so any linked list that you deal with could contain anything. I hope you like finding a lone float in your array of ints.

> Dogshit compared to Go's
Go's standard library is batteries-included style, while Rust relies on crates.io to provide non-essential functionality like compression algorithms and image manipulation. Which is reasonable for a system language. Besides that, Rust standard library is better because Rust has generics and as a result, many things can be expressed efficiently in it without resorting to polluting the language itself, like Go does for maps and channels.

Also, the fact that linked lists have interface{} as elements means that nodes can't contain the elements inline. You need both extra space for the pointer to the element, and you need an extra pointer deref to reach any element.

>tfw Rust needs a crate to do RNG

Programming in rust is like putting your balls in a vice.

If you can't write secure code with RAII you shouldn't be near a computer

>Programming in rust is like putting your balls in a vice.

Time to learn Rust.

>adding more shit
You have no clue what you're talking about.

C++1xyz all SIMPLIFIED the language and made the syntax shorter, more convinient and expressive.

The theme for C++ is powerful abstraction at zero overhead cost. (ZCAs) but also expressibility and readability.

Well written C++ code is the most readable thing you can find.

Newly written and idiomatic C++11 is great but there is a shitton of legacy C++ out there, we went over this.
Good C++ > Good C > Bad C > Bad C++

Reposting from /dpt/:
is there a good resource on learning modern and idiomatic C++?

So try writing a zero-overhead doubly linked list with C++11 smart pointers. You can't. You still have to drop down to raw pointers and new/delete.

C++11 "simplified" the language by adding constructs with a runtime penalty, forcing you to use older constructs when performance are an issue. Rust uses compile-time safety checking to give you zero-cost high level abstractions so that you don't have to drop down to raw pointers as often.

>yfw it's going to be faster than linked list

Also, trying to use shared_ptr/weak_ptr for a doubly linked list with a performance penalty is going to be error-prone, because you have to write your custom destructor to override the default behaviour of the shared_ptr objects. Dropping the head isn't enough.

If you just drop the head, the chain of refcount decrements and deallocations will cause a stack overflow in the destructor for any sufficiently large list. So you'd have to actively fight the behaviour of your C++1x smart pointers to make a reliable data structure.

Why would anyone ever use a linked list

First year in uni.

They might be making a std::unordered_map

It's quite common to want a tree where the nodes have a pointer to the parent. Linked lists are a nice special case of that which can be instructive to implement.

They also are a great example of why refcounting is a terrible garbage collection strategy, and of how RAII can hide really horrible bugs in a closing brace.

Iteration is a poor man's recursion

Enjoy your wrapper functions, and having trouble working with basic data structures like mutable priority queues.

Also, incompatibility with deterministic RAII or refcounting, since the destructor calls or refcount decrements need to happen when the function scope exits, but that is delayed by the recursive function call, and the compiler usually can't tell whether the two operations can be reordered.

Ever wondered why Python doesn't have tail recursion? That's right. Refcounting.

nothing can fix operator overloading hell

the only inappropriate use of overloads in the standard library is streams

vectors use contiguous memory region, linked list doesn't
THAT'S WHY IT EXISTS PAJEET

>linked list is a meme
Said the incompetent programmer who reads blogs.

most programs are not in standard library, unfortunately.
some programmers have really... novel definition of readable code

Agreed. The worst part about C++ is other C++ developers.

>muh cargo cult
Rust is inexcusable trash. C++ has the standards committee at the ISO, Go has the masterminds at Google, Rust had pink haired trannies working for Mozilla.

No shit you have to use raw pointers for basic containers. You can just use std::list anyway.

People who studied CS 101 can write a linked list without bugs.

>C++11 "simplified" the language by adding constructs with a runtime penalty
>pulling shit out of your ass to justify use of Rust
This is a tonne of shit son. shared_ptr is reference counted, unique_ptr and weak_ptr are not. Get over yourself.

A poor iteration is a normal man's recursion

a poor recursion is a normal man's iteration

>masterminds at google
>no generics

>Dunno if it will ever replace C++ tho.

C++ is so heavily established that it's going to be another 10-15 years before Rust even begins to replace it in any meaningful way.

>pink haired trannies working for Mozilla

I assure you that not one of them is contributing anything technically significant. The ones making meaningful contributions are keeping their heads down.

>where all basic functionality is reimplemented with an extra Q in front of the name
Ah, I see you're a man of Qt as well.

>>Ever wondered why Python doesn't have tail recursion? That's right. Refcounting.
No, it's because Guido wants good tracebacks.

>there are people on the Sup Forumsayjutsu board who unironically believe programming in this illegible obfuscated poser "language" will bring a bug-free software ecosystem

Rustbabbies be like:
>there's no reason to use linked listeds, their performance is bad
and then they go and use BTrees to sort 3 elements

Weak ptr is refcounted to keep the shared struct alive after its content has been deallocated, so that weak pointers can know whether or not they are dangling.

Unique_ptr have a runtime penalty due to being nullable and having move semantics, so you always need to check them for null to make sure that they haven't been stolen.

>tfw at mozilla
>see this post
>walk into the kitchen and see a pink hair transgender
Hahahahah

>don't use linked lists
What should I use instead?

what's the use case?

Nothing in particular right now but when I need a data structure to hold some ordered data I can easily add to and remove I just use a linked list without much thinking about it.
I consider a linked list an essential data structure along with stack so I find strange the suggestion "don't use them"

>I just use a linked list without much thinking about it.
You should really educate yourself on the impact cache architecture has on the performance on modern systems: kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/ .