Live data from Hacker News

100 days with Rust: a series of brick walls

brandur.org

111–120 of 323 posts

Re: 100 days with Rust: a series of brick walls

#111

There are a few things in life you just should not do. One of them is jump from your only language experience being Python into an advanced language like Rust when you’re struggling to grok SQL.

Brandur is not struggling with SQL[0][1]. That was an illustrative example of the kinds of walls you encounter in life as a programmer.

[0]: https://brandur.org/postgres-reads

[1]: https://brandur.org/postgres-atomicity

Re: 100 days with Rust: a series of brick walls

#112
post #77

Earlier quoted context omitted.

Minor point: you can have Vectors in structs. Vector is a fixed-size type on the stack so it works fine. And other types in structs too. EDIT: sorry, I see you got to that before I'd finished this post :) Rust is a language where you have to kind of take a step back before working with it to read about the design tradeoffs and why they were made. Certain things you're used to doing with other languages just won't wor…

> lifetime system logical on its own terms but very, very unnatural to learn That is a succinct explanation of it, yes! Like I can read the documentation and nod along, and the rules seem simple. Actually then remapping your brain and how you want to achieve things seems incredibly challenging

Well, that's down to practice. And on that subject...

One thing I like to do with a new language is to re-implement a self-contained but non-trivial program that I've built before. I have a few but my favorite is a genetic algorithm which breeds rule sets for a cellular automaton to get the CA to solve some simple computation problems. It's not at all complex, a few hundred lines when done in Python, but it's more than a tiny example. I like it for learning new languages as it touches on various data structures, it's inherently parallelizable, it's not especially bound to any particular programming paradigm, it lends itself to exploring various useful concepts and constructs (function pointers, closures, recursion, etc.), and it is fun and interesting to work on.

So maybe you have something similar, something where you really understand the problem and the solution, freeing your brain to focus entirely on seeing how it would map to Rust.

Re: 100 days with Rust: a series of brick walls

#113
post #93
post #61

Earlier quoted context omitted.

You're absolutely right. What I really meant was that you can't have Vec where T is a trait without also wrapping that in a box, which for me in turn doesn't work for a bunch of other reasons. In any case, my point remains the same: it is very challenging-- at least for someone used to just creating data structures and letting GC handle it-- to build code that does what you want, and you spend large amounts of time "…

It fundamentally doesn't make sense to have a Vec , because Vec expects each of its elements to be the same size (otherwise you couldn't index into it in O(1)), but different types that implement Trait can have different sizes. Other languages allow this because they automatically box everything, but Vec > should accomplish the same in Rust; I'm curious what the "other reasons" you referred to are, that make that uns…

I didn't really want to get into the nitty gritty because it detracts from the point (I considered not having the rant paragraph at all for fear that it would just be deconstructed and the exact examples becoming the focus of what I said and not what I was actually trying to say).

But anyway!: https://doc.rust-lang.org/error-index.html#E0038 . The one that screws me is the first one, requiring Sized.

Re: 100 days with Rust: a series of brick walls

#114
post #75

The problem with Rust is that it is very hard to program interconnected graphs. Basic Rust does not allow cyclic references, which means that almost every graph needs to use special tricks to make it work. These tricks are variants of reference counting. A trick that was copied directly from C++. It feels like having to build a car with only a screwdriver and hammer. Each section of your graph needs to be managed sep…

The easiest way to build graphs in Rust is to store all your graph nodes in a Vec, and use indices instead of references to refer to other nodes. Also a cache locality win.

Re: 100 days with Rust: a series of brick walls

#115
PG had this comment about programming languages: The correct solution of a problem is the most simple solution. Just like in math, you can solve one problem in multiple ways, but the correct one is the shortest, beautiful looking one.

When I look at Rust, it gives the feeling "could be simplified". Obviously it's a new language and it comes with lots of cool stuff, but it looks ugly, doesn't excite those who seek simplicity.

If I had the time to invest in learning Rust, I'd use that time for building something new with any language that makes me productive.

Re: 100 days with Rust: a series of brick walls

#116
post #84

Earlier quoted context omitted.

(Responding to myself to reply to the parent's edit) > You're absolutely right. What I really meant was that you can't have Vec where T is a trait without also wrapping that in a box, which for me in turn doesn't work for a bunch of other reasons. Ah, it sounds like you're using traits as types directly, which is very much discouraged by Rust ( especially in conjunction with taking references to those traits). What t…

> What the language really prefers for you to do is to use traits as bounds on generic types to get rid of the dynamic dispatch and the consequent complications with lifetimes Isn't this basically equivalent to only using templates in C++ code ? and doesn't it kill build times & prevent reusability across different shared objects ?

Dynamic dispatch will surely always be faster to compile than static dispatch, but static dispatch has crucial runtime performance advantages (e.g. it enables inlining, which is the ultimate meta-optimization). And extreme runtime performance is one of Rust's raisons d'etre. Having fast compilation is surely a worthwhile goal, but, for Rust, not if it comes at the expense of runtime performance.

What do you mean by "prevent reusability"? There's nothing about static vs. dynamic dispatch that prevents code or types from being used across different compilation units.

Re: 100 days with Rust: a series of brick walls

#117
post #48

Exactly my feelings. Interesting how some people claim a rather different experience. Rust was voted the most loved technology on StackOverflow, which is unbelievable to me.

> Rust was voted the most loved technology on StackOverflow, which is unbelievable to me.

I absolutely adore Rust because my code has an order of magnitude fewer bugs when it is time to actually run the end result.

A lot of programmers have an ugly tendency to blame the language/library/framework/weather for their problems before questioning their skills or knowledge. They are absolutely not suitable to be Rust developers.

Re: 100 days with Rust: a series of brick walls

#118
post #113
post #93

Earlier quoted context omitted.

It fundamentally doesn't make sense to have a Vec , because Vec expects each of its elements to be the same size (otherwise you couldn't index into it in O(1)), but different types that implement Trait can have different sizes. Other languages allow this because they automatically box everything, but Vec > should accomplish the same in Rust; I'm curious what the "other reasons" you referred to are, that make that uns…

I didn't really want to get into the nitty gritty because it detracts from the point (I considered not having the rant paragraph at all for fear that it would just be deconstructed and the exact examples becoming the focus of what I said and not what I was actually trying to say). But anyway!: https://doc.rust-lang.org/error-index.html#E0038 . The one that screws me is the first one, requiring Sized.

I can agree with the initial frustration coming from a GC-ed language until one figures out the right way to design code and structure data in a language with manual memory management. But I got over it eventually.

I'm also curious about this nitty gritty bit. I see this:

Generally, Self : Sized is used to indicate that the trait should not be used as a trait object. If the trait comes from your own crate, consider removing this restriction.

I guess you needed that sized restriction for some reason, assuming this was a trait of your own?

Re: 100 days with Rust: a series of brick walls

#119

There are a few things in life you just should not do. One of them is jump from your only language experience being Python into an advanced language like Rust when you’re struggling to grok SQL.

So what do you propose? He learn C first? Or he's just not allowed to learn Rust?

Re: 100 days with Rust: a series of brick walls

#120
Disclaimer: Am a C++ programmer

Watching from a distance I have to concede that from a safety, dynamism of the community and package management using cargo Rust has improved upon C++ in meaningful and measurable way.

However on the complexity of the language front, I wonder if Rust will also join C++ in the realms of "too complex" 10 years from now. Would love to get some Rust experts to weigh in here on their thoughts about managing complexity of the language long term and whether being a simple systems programming language is an end goal.

Post reply on HN