[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Rust

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 105
Thread images: 3

File: Rust.png (37KB, 400x400px) Image search: [Google]
Rust.png
37KB, 400x400px
It's not possible implement doubly linked lists and directed cycle graphs in Rust.

Why does it even exist?
>>
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?
>>
>>61549224
>You can with unsafe code.

But unsafe Rust has no advantage over C++11.
>>
>>61549258
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.
>>
>>61549084
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.
https://jaxenter.com/power-ten-nasas-coding-commandments-114124.html
>>
>>61549479
>Rust and safety is much like how the TSA works, at what cost?

Perfect description.
>>
http://cglab.ca/~abeinges/blah/too-many-lists/book/
>>
>>61549479
>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?
>>
>>61549084
Because C++ is an ugly mess. Yet Rust is already an uglier mess without having decades of backwards compatibility to worry about.
Impressive.
>>
File: 1498094877031.jpg (100KB, 500x430px) Image search: [Google]
1498094877031.jpg
100KB, 500x430px
>>61549479
>no recursion
How the fuck else am I supposed to draw terrain and check terrain collision for top down games?
>>
https://github.com/rust-lang/rust/blob/master/src/liballoc/linked_list.rs
>>
>>61551666
>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 :)
>>
>>61551324
>>C++ ugly

Not anymore. 11, 14 and 17 fixed that.
>>
>>61551733
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
>>
>>61551701
It's not refcounted, it's basically a raw pointer with additional compile-time information, like not being NULL and covariance: https://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.
>>
>>61551746
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.
>>
>>61551793
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.
>>
>>61551806
So? Legacy code will alway exist. Gradually move older code over and start new projects directly with 11 or better.
>>
>>61551666
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.
>>
>>61551860
>pulling shit out of my ass: the post
>>
>>61551860
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.
>>
>>61551873
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.
>>
>>61552026
> 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.
>>
>>61552288
Nice language based on OCAML becomes "safe" circlejerk, by people use JavaScript and never write low level code on real world.
>>
>>61549084
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
>>
>>61549084
linked list is a meme

use vectors
>>
can I ship rust as a single executable on windows (no gcc dlls or other bullshit) yet?
>>
>>61553205
Yes, it supports VS toolchain as well.
>>
>>61552460
>need to regularly insert an element at the front of a 100,000 elem vector

just fuck my shit up
>>
>>61554103
Insert at the back and then reverse, or just use deque, there's really no reason to use linked lists in 2017.
>>
>>61554127
O(1) to insert at back
O(n) to reverse

So literally no difference from what I said initially. Good job, pajeet.
>>
>>61554152
except now you get cache locality and O(1) lookups
>>
>>61549258
>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.
>>
>>61554127
How can you even live being this retarded
>>
>>61554380
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.
>>
>>61554497
That's still O(n) when you could have O(n) with linked lists
>>
>>61554545
except the vector has O(1) indexing and cache locality, and doesn't have two pointers overhead per element
>>
>>61554545
But a linked list would make n allocations, would take O(n) to index and would be extremely slow to iterate over.
>>
>>61554608
>in this case where linked lists are inappropriate, linked lists are inappropriate

genius
>>
>>61554693
linked lists are inappropriate in almost all cases
>>
>>61554727
>almost all cases
>no reason to use linked lists in 2017

Really makes u think.
>>
>>61554727
this, even most soc have a CPU cache
>>
>>61554755
prove me wrong
>>
>>61554103
>100,000 elem vector
Sign of a bad programmer
>>
>>61554902
He uses linked lists because his language doesn't have vectors kek
>>
>>61554997
A vector is a dynamically resizable array. Any non-meme language has it.
>>
>>61555504
Except for C
>>
>>61555568
C has realloc.
>>
>>61555586
So does other languages
>>
>>61555596
no shit?
>>
it's so women and black people can get into system programming
>>
>>61551389
Implement a stack yourself. Recursion is poor-man's iteration anyway.
>>
>>61549084
Just use the built in LinkedList from the standard library, which is doubly linked?

https://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.
>>
>>61552433
More likely, a 2nd year CS student taking data structures 101 and can't conceive of stdlib-provided generics.
>>
>>61556179
>The Rust standard library is actually good
Dogshit compared to Go's

>>61556253
t. buttblasted rust babby
>>
>>61556325
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.
>>
>>61556325
> 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.
>>
>>61556461
>>61556325
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.
>>
>>61556464
>tfw Rust needs a crate to do RNG
>>
>>61549084
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
>>
>>61556523
>Programming in rust is like putting your balls in a vice.

Time to learn Rust.
>>
>>61551746
>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.
>>
>>61556556
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++?
>>
>>61556556
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.
>>
>>61554103
>yfw it's going to be faster than linked list
>>
>>61556601
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
>>
>>61556792
First year in uni.
>>
>>61556792
They might be making a std::unordered_map
>>
>>61556792
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.
>>
>>61555755
Iteration is a poor man's recursion
>>
>>61556916
Enjoy your wrapper functions, and having trouble working with basic data structures like mutable priority queues.
>>
>>61556956
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.
>>
>>61551733
nothing can fix operator overloading hell
>>
>>61557009
the only inappropriate use of overloads in the standard library is streams
>>
>>61552460
vectors use contiguous memory region, linked list doesn't
THAT'S WHY IT EXISTS PAJEET
>>
>>61552460
>linked list is a meme
Said the incompetent programmer who reads blogs.
>>
>>61557022
most programs are not in standard library, unfortunately.
some programmers have really... novel definition of readable code
>>
>>61557103
Agreed. The worst part about C++ is other C++ developers.
>>
>>61556464
>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.
>>
>>61556601
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.
>>
>>61556601
>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.
>>
>>61556916
A poor iteration is a normal man's recursion
>>
>>61557182
a poor recursion is a normal man's iteration
>>
File: IBs6aYR.jpg (91KB, 625x612px) Image search: [Google]
IBs6aYR.jpg
91KB, 625x612px
>>61557139
>masterminds at google
>no generics
>>
>>61549331
>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.
>>
>>61557139
>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.
>>
>>61556179
>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.
>>
>>61557006
>>Ever wondered why Python doesn't have tail recursion? That's right. Refcounting.
No, it's because Guido wants good tracebacks.
>>
>>61551666
>there are people on the /g/ayjutsu 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
>>
>>61557173
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.
>>
>>61557245
>tfw at mozilla
>see this post
>walk into the kitchen and see a pink hair transgender
Hahahahah
>>
>>61554329
>don't use linked lists
What should I use instead?
>>
>>61558882
what's the use case?
>>
>>61558965
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"
>>
>>61559070
>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: https://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/ .
>>
Why not use linked arrays instead of arrays or linked lists?
>>
>>61559306
std::deque is exactly that, IIRC.
>>
>>61559367
It's a vector of vectors with some management.
>>
>>61549084
>It's not possible implement doubly linked lists and directed cycle graphs in Rust.
Why the fuck would you want those? Enjoy youre cache misses.
>>
>>61556523
>If you can't write secure code with RAII you shouldn't be near a computer
Every hacker writes insecure code at some point or another. They could be tired, have a bad day, or just forget something important, because they're fucking human beings. That's how vulns get into even the best open source projects like the Linux kernel. You can throw blame around all you want, but the solution is to use a safe language that prevents the vulns in the first place.
Thread posts: 105
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.