Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I keep trying to learn rust but fail miserably.

They do say on their website that there's a hump that you have to climb over before everything fits into place, which is probably applicable to everything you'll learn, but sometimes I think that hump is too much of a hurdle



How are you trying? What are you getting stuck on? I'd love to improve things.


I'd get excited and go through some tutorial on their website, probably the main? tutorial, bu then when you get to the lifetimes section is seemed to get really complicated instantly. I tried twice and think I hit the same problem. Maybe some more good examples would help?


Makes sense! I'm working on a second draft of the book right now, and it's making that stuff more clear. http://rust-lang.github.io/book/ is the draft; the lifetimes bit hasn't landed yet though.


Did you go through these screencasts?

http://intorust.com


Not specifically about your book, but I would love if there was a quicker way to find methods in the docs.

Right now, if I want to find the methods used by BTreeMap you have to wade through a good amount of information until you can find how to just get the keys. I'm currently on mobile where the issue is more prominent.


Are you missing the search bar at the top? Typing "keys" in shows BTreeMap's keys right away, even https://doc.rust-lang.org/stable/std/?search=keys

That said, yeah, I hear you. It can still be tough sometimes. At some point, I'd love to work with some sort of information design / UX person to totally re-do rustdoc's output. There's a surprising number of thorny problems there. But there's always so much to do...


If you click the "[-]" symbol at the top right of a docs page it collapses all the text and just shows the method signatures. Then you can click the "[+]" symbol next to any single method to get full details.


If I don't find what I'm looking for from the docs, I often use ripgrep on a copy of the rust repo locally to find answers.


> I often use ripgrep on a copy of the rust repo locally to find answers

I mean, that works, but it's a workaround and not a solution.


What are you getting stuck on? I'd love to improve things.

I feel I am getting over the hump of learning rust now and coding in rust is becoming less frustrating for me.

However, one thing that slows me down is the lack of indices in the documentation. For instance, if I want to know the return type of a vector len() I go here:

https://doc.rust-lang.org/std/vec/struct.Vec.html

.. and then I have to search the web page for all instances of "len". It would be good if there was an index similar to Javadoc, Godoc or Doxygen.

There might be a good reason for not having the index, but as a beginner it is lost on me.


Two things:

If you click the little [-] button, you'll get an index for that page.

If you use the search bar at the top, https://doc.rust-lang.org/std/vec/struct.Vec.html?search=vec... will let you go right to the method. (In this case, you have to know that it's slice::len though)

Does that help?

EDIT: UX is hard! Glad people are discovering this. It's the same symbol HN uses, incidentally...


Whoa, I have been working with Rust for a little over a year, and had no idea about the [-] button.

I would echo the suggestions to make that button much more visible. Or perhaps even have the top-level description expanded by default but method/trait descriptions hidden. I can't think of a case where you'd simultaneously want to see every method description.


Been using rust for months now and I never knew the [-] did that. I never even thought to click it.

Seems like there's some UX improvements that could happen there.


Thanks, thats very helpful. I did not know about the minus sign.

A polite suggestion - maybe the link marked [-], that takes you to the index, could be labelled "index".


Well, it's not so much that it's an index, it's that when you have a page with only signatures, it feels like an index. There's no redirect, just some JavaScript :)


Maybe 'collapse' and 'expand' would be good substitutes for the '-' and '+' at the top?


Not OP, but as someone who theoretically would like Rust - I'll bite. Maybe my usecase is a common one.

I understand memory management in C. I understand it modern C++ (destruction when going out of scope, smart pointers etc).

Basically, a description and discussion of borrow-checking for people who have already used system programming languages would be really helpful. I feel like the book is targeting people who have only used garbage collected languages.

Or is the memory management of rust so novel it can't be described in those terms? I find the concepts aren't very concrete to me.


It's trying to be accessible to those people, but not strictly for them. I don't think the issue here is that it's for GC'd users, but that it's trying to explain things from whole-cloth, where you're looking for a direct comparison, "c does this, rust does that."

I try generally to keep other languages out of Rust's docs for various reasons, but agree that these kinds of resources are useful; I wrote "Rust for Rubyists" after all!

I'm hoping that others will step in and fill this gap; the repo in my sibling is a great start.


Have you tried looking at https://github.com/nrc/r4cppp ?


That looks like exactly what I'm after actually. I'll read this next time I try rust.


I'm also in a similar boat but my primary thing being that I learn by doing and since it's branded as "system programming" I immediately think of big projects like kernels and drivers. I wish there were some small projects that I could do apart from just doing "project euler" that would be helpful to me. I even bought raspberry pi to learn rust but don't quite know what to do with it and rust.


There are a large number of projects on Cargo that maybe-perhaps do something useful, but don't get much love in the testing/documentation/polish department since the authors tend to move onto other projects. My personal wish list:

Varints: https://crates.io/crates/varint

Bloom filters: https://crates.io/crates/bloom

Iron: https://github.com/iron/iron

All the accessories for Iron: authentication middleware, integration with OAuth2, cookie-signing, integration with templating systems, etc. Also, an omakase framework (like Django or Rails) that pulls together a bunch of useful libraries into one crate that you can just use (with good docs) and not have to wire everything up.

Websockets: https://github.com/cyderize/rust-websocket or https://github.com/housleyjk/ws-rs

Server-sent events. I don't see a good alternative for these yet.

ElasticSearch: https://github.com/benashford/rs-es or https://github.com/erickt/rust-elasticsearch or https://github.com/KodrAus/elasticsearch-rs

An easy documentation/website generator for small libraries, that pulls examples, tests, and README files out of GitHub, runs RustDoc, and generates a professional-looking website that provides all the info that you need to get started with a library, with a minimum of extra effort for the library author. Basically, automate the job of going through libraries built to scratch someone's personal itch and "productizing" them.

Any of these could be a good project for a beginner, since there's already a lot of existing code to learn from, a small well-defined task, and an existing maintainer who has an incentive to help. Basically, just take a library, try to use it in a small test program (Linus's Law: "Never try to make a big important program. Always start with a small trivial program, and work on improving it"), and if anything is difficult or doesn't work right, figure out how to make it less difficult for the next person who runs across it and submit a pull request with that. As an added bonus, you can learn a lot of domain knowledge or basic CS data structures through digging through this, and that transfers to programming outside of Rust.


This might be too much like Project Euler but I started by solving some common interview problems using Rust.

Try solving the problems without looking at the solutions first: https://github.com/brianquinlan/learn-rust

Here is a rough rank of difficultly: https://github.com/brianquinlan/learn-rust#understandability


Makes sense! Have you seen http://www.chriskrycho.com/2016/using-rust-for-scripting.htm... ? Maybe something like that can be of inspiration.


same feeling here. There are docs here and there, but not good.

I am waiting a good book on rust. similar to Haskell, I really did not get much until the book http://learnyouahaskell.com/

currently, "The book" is too dry.


Programming Rust by O'Reilly is in early release and I recommend it.


I am having the same inertia.

I have resorted to using Nim for now, and it is going real well. I would like to rewrite the Nim stuff in Rust to compare for my own sake when I have done something substantial in it.



Feel free to stop by the IRC and ask questions/ seek help - lots of people there who are willing to answer your questions.

Or the rust forums: users.rust-lang.org

Or the rust subreddit: reddit.com/r/rust


For me the hump was from the get-go.

Following the book, I installed Rust directly, but then i realized that I should've installed it via Rustup. Next, I want a good editing environment, so I install VS Code and Racer, but then I find out that I can't use Clippy unless I use Nightly... and I'm not interested in using Nightly, so I'll wait.


Rustup has been in beta for a while, which is why we don't recommend it in the book. Soon though!


I just installed the nightly tarball and used my usual editor (emacs). I'm not sure what the editing environment has to do with a learning hump.

Now, coming from loose dynamic typed languages or really terrible C or C++ code bases is another matter.


A good language should be like a good game: easy to learn, hard to master.

We don't care about expert cases, we only care about getting productive ASAP, which means having students hoping into a language and learning it quickly. Solving the details is easy: just teach coding discipline and enforce good practice and do code reviews, and discourage "throwable" code. Security is not only the job of a programmer, it has many many facets.

In short: english is better than latin or esperanto. The more time and space you need to describe your language, parse it or the more character or syntax it requires and the longer it requires for an individual to read a program and guess what it does, the worse it is.

I'm getting a little tired of the "novelty" languages these last few years. Maybe I'm more conservative and don't like the hype. To me only D is relevant and it has been there for a long time now.


Do you have a proposal to achieve Rust's goals in a way that's easier to learn?


Hi pcwalton, I've seen a couple of your videos and want to know if you've posted any tutorials on integrating Rust with Xcode and using the native tools, or if others have? Some of us are coming from IDE Javaland, and while Rust is quite usable from a text editor, print debugging only goes so far, and gdb is incomprehensible gobbledygook for us.


syntax


Be specific.


As someone getting into and loving Rust, I have a few:

1) Drop the semicolons and implicit returns in multiline functions (I.e. like Swift). Eliminates hard to understand errors around missing or present semicolons.

2) Allow silent lossless integer upcasts. Sprinkling as usize and friends everywhere is unergonomic.

3) ? For return is fine but the line should still have one "try" at the beginning for legibility.

4) Allow full inference of generic type parameters. Would make it much easier to split code into helper functions.

5) Macros are nicer than in C but still hostile to comprehension.

There are others, but these are ones I've personally run into. Love the language and especially love Cargo but it has some newbie-hostile rough edges like this and others.


Many of these are not possible due to backwards compatibility. Even if we could:

1. Most Rust users, including me, like the implicit returns. We would face a ton of pushback if we tried to drop them. Rust doesn't actually need that many semicolons: you can frequently leave them off.

2. This is tricky, because it can have surprising semantics if not done right (e.g. right shifts). There are proposals to do something like this, though.

3. I disagree. That would eliminate much of the benefit of ? to begin with.

4. Not possible. This would complicate the already very complex typechecker too much.

5. Macros 2.0 is coming. We can't just remove macros: they're fundamental to basic things like #[derive] and string formatting.


Hi pcwalton,

1) If you dropped semicolons like Swift, you could keep implicit returns.

I just don't see the advantage of having them in multiline functions at the cost of having to retain semicolons. IMO, a trailing value after a multiline function also just looks plain bizarre for newbies.

I agree it's probably too late for this, but you asked how Rust could be easier to learn and this is one of the ways.

2) It would certainly be much nicer to have this.

3) See Swift for an example of where this was done more nicely IMO than in Rust.

4) Unfortunate. Splitting out a helper function means we lose Rust's inference which already exists when used in a let statement, and requires adding dependent crates from libraries to the binary's Cargo.toml and importing them into the module and hard coding the types. The client shouldn't have to care about this.

5) Great!

I still enjoy the language just the same, but you asked how it can be easier to learn and this is how I see it.


LuaJIT + C have suited me just fine for systems programming. I don't care about security, so I find it hard to care about Rust. All I care about is lessening the burden on me as a programmer.

I think Rust may be useful in cases like ripgrep, where you basically rewrite an existing, established tool or service used by many to be as performant and secure as possible. But other than that niche use-case, I don't think Rust will catch on in the long-term.


As the author of ripgrep, I can assure you, the burden on me as the programmer was lifted quite a bit! I probably wouldn't have been able to build it otherwise. (Not because it's physically impossible, but because it would have taken too much time.)

It's not like I just rewrote grep. ripgrep is built on a large number of libraries that are reusable in other applications. You can see my progress on that goal here: https://github.com/BurntSushi/ripgrep/issues/162 (And those are only the ones I wrote, nevermind all of the crates I use that have been written by others!)


Oh wow, The creator in the "flesh"! Thanks for replying to me.

Hypothetical scenario: Let's say you're writing an experimental tool that doesn't exist anywhere else. You don't care about security, you don't care about speed. You just want it to exist so you can see what it does and possibly iterate on the idea if it ends up working out. Would Rust still be feasible?

From my impression of it, you would need to take care of a lot of corner cases and such (which don't exist in other languages) that may slow you down in the short run. I'd imagine those corner cases would be extremely helpful in the long run if you want to squeeze some extra performance out of it (or avoid technical debt). But from the perspective of "figuring out what's possible" I feel like Rust would get in the way a lot.


Good question! The inherent problem with asking me that is that I've been writing Rust continuously for over 2.5 years by now. I live and breathe it. It comes as naturally to me as Go or Python does at this point (which I've been writing continuously for even longer).

I will say that a comparison between Rust and C is much easier, because in the past, I've spent so much time debugging runtime errors in C with valgrind. Rust is an easy win there for me personally. I've never done much C++ so I can't provide a comparison point there.

After a bit of Rust coding you get quite familiar with the workings of the borrow checker, and it becomes pretty natural to work with it. There are plenty of things you can do in C that Rust's borrow checker will forbid because it isn't smart enough to prove it safe, but there are usually straight-forward work-arounds. Sometimes the borrow checker might even help make the code a bit clearer. :-) Some of this is institutional knowledge though, so there's still a lot more documentation work left to be done!

To bring this back to earth: Rust won't replace those ~100 line Python scripts that I sometimes write for quick data munging.

The other important bit of context is that before I started with Rust, I had already had quite a bit of experience with C, Standard ML and Haskell. This meant that the only truly new thing I had to cope with in Rust was the borrow checker, so it might have been easier for me to digest everything than it might have been for most.


Thanks for the insight! I may give Rust another shot at some point. Interoperating it with Lua may be fun.


I learned Rust in a couple of weeks, and I'm writing a game in it right now. It's a pleasurable experience, and far outside that niche. "I can't learn it so nobody will use it" is such a silly thing to think.


It's worth it, imo. I was in your boat a few months back and hated every minute of it. With that said, i'm still not 100%. I semi-regularly see syntax that makes me go "Wat is what!?", but then i sit for a moment and understand it. Rust introduces a lot of visual baggage and that seems to cause me syntax blindness.. not enjoyable.

Unfortunately though, i'm back on Go. I want to be on Rust, but i had to pick a language for work and i can't ask my Team to go through what i did. Rust, despite the safety, is too unnatural for our larger codebase.

Luckily i think Rust has seated itself as the language we will use if the need is truly there. Unfortunately though, not everything.. just the specific things that need it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: