News for hackers. Stuff that matters.
Re:Small exercises to get you used to reading and writing Ru... by carols10cents on Tuesday February 02, 2016 @08:52AM (#11019382)
Hi! I'm the maintainer, and I'm glad yinz are enjoying rustlings :) I don't have any plans to do this for other languages, but please feel free to start your own!

If you have any particular Rust concepts that you'd like exercises for, please let me know here, file an issue, or even contribute an exercise! Errors that you've hit that took you out of your flow of working on something else are great candidates. I haven't been adding new exercises recently, but I would like to continue expanding.

Thanks! <3

Re:Small exercises to get you used to reading and writing Ru... by pc86 on Tuesday February 02, 2016 @10:40AM (#11020073)
This looks pretty neat! Would you recommend this for someone wanting to learn rust from scratch who is proficient in other languages?
Re:Small exercises to get you used to reading and writing Ru... by carols10cents on Tuesday February 02, 2016 @11:02AM (#11020234)
That's basically my target audience :) It's not comprehensive yet, but the idea is to give you practice with Rust syntax and compiler errors.
Re:Small exercises to get you used to reading and writing Ru... by MuEta on Tuesday February 02, 2016 @09:26AM (#11019558)
> yinz

So a Pittsburgher with a passion for rust? Color me surprised.

Re:Small exercises to get you used to reading and writing Ru... by dikaiosune on Tuesday February 02, 2016 @09:31AM (#11019584)
Isn't it in the rust belt?
Re:Small exercises to get you used to reading and writing Ru... by carols10cents on Tuesday February 02, 2016 @09:44AM (#11019641)
Indeed it is!
Re:Small exercises to get you used to reading and writing Ru... by solipsism on Tuesday February 02, 2016 @12:23PM (#11020818)
That's... the joke...
Re:Small exercises to get you used to reading and writing Ru... by carols10cents on Tuesday February 02, 2016 @09:44AM (#11019638)
> So a Pittsburgher with a passion for rust? Color me surprised.

Guilty as charged :)

Re:Small exercises to get you used to reading and writing Ru... by untothebreach on Tuesday February 02, 2016 @11:33AM (#11020447)
holy cow...just went looking for the origins of "yinz" and found out about "western pennsylvania english." My wife does the "needs/likes/wants + past participle" thing listed in the wikipedia article[1], and I never knew it was commonplace in some parts of the U.S.

1: https://en.wikipedia.org/wiki/Western_Pennsylvania_English

Re:Small exercises to get you used to reading and writing Ru... by bwanab on Tuesday February 02, 2016 @01:03PM (#11021118)
Hmmm... It is a common usage in Appalachian East Tennessee also. I suspect it's more generically Appalachian than just Pennsylvania.
Re:Small exercises to get you used to reading and writing Ru... by steveklabnik on Tuesday February 02, 2016 @12:40PM (#11020939)
Wikipedia says only outsiders say "Pittsburghese", but I've only ever heard it, and never "Western Pennsylvania English."

See also http://www.pittsburghese.com/

Re:Small exercises to get you used to reading and writing Ru... by cgh on Tuesday February 02, 2016 @12:43PM (#11020965)
Thank you for doing this. Is there any chance we could see exercises involving lifetimes? I've found this is one of the trickiest Rust-only concepts to really understand.
Re:Small exercises to get you used to reading and writing Ru... by carols10cents on Tuesday February 02, 2016 @01:22PM (#11021263)
I will try!!
Re:Small exercises to get you used to reading and writing Ru... by CoffeeDregs on Tuesday February 02, 2016 @02:50PM (#11021975)
Thanks for putting in the effort to produce this. I'm excited to learn Rust and to port a few projects over to it, but I haven't gotten traction to get past the first few steps. Your packaging-up of the examples is a great way to start.
Re:Small exercises to get you used to reading and writing Ru... by Eridrus on Tuesday February 02, 2016 @03:08PM (#11022109)
For everyone looking for exercises in other languages, there is actually a project to curate exercises for programming languages called exercism.io

Maybe the OP could contribute their exercises there, since their Rust exercises were not very good when I tried them.

Re:Small exercises to get you used to reading and writing Ru... by chc4 on Tuesday February 02, 2016 @03:38PM (#11022327)
There's also Rosetta Code, which has tons of problems and language implementations. It's tons of fun to read through.
Re:Small exercises to get you used to reading and writing Ru... by carols10cents on Tuesday February 02, 2016 @03:39PM (#11022337)
Yeah, I love exercism! There's definitely conceptual overlap, but IIRC the exercises in exercism were more of the variety where you're given a problem and you start from scratch, then others give feedback on your solution. I'm not sure if the intentionally-broken starting places of rustlings would fit in?
Re:Small exercises to get you used to reading and writing Ru... by maxbrunsfeld on Tuesday February 02, 2016 @03:12PM (#11022135)
This looks great. Bookmarked for when I get around to learning Rust.
Re:Small exercises to get you used to reading and writing Ru... by adrianN on Tuesday February 02, 2016 @06:27AM (#11018823)
This is great. It took me from occasionally scrolling through the Rust book ("Rust looks cool, I'll use it eventually") and never writing a line of code to actually trying the language.
Re:Small exercises to get you used to reading and writing Ru... by danbolt on Tuesday February 02, 2016 @09:54AM (#11019712)
I feel the same way! Especially since this makes me a little more comfortable with the language, I might be more inclined to use it later too!
Re:Small exercises to get you used to reading and writing Ru... by elcapitan on Tuesday February 02, 2016 @03:28PM (#11022251)
This is absolutely fantastic, well done.

One point that makes this particularly nice is the fact that for many languages of the compiled c++/Rust/etc kind there is a certain level of barrier for people coming from dynamic languages, and that is the non-existence of a repl where you can just try out basic idioms and constructs without having to manually set up a context. This kind of interactive environment kind of replaces that and therefore opens the language for much more people.

Re:Small exercises to get you used to reading and writing Ru... by andrey-g on Tuesday February 02, 2016 @04:01PM (#11022555)
When you're a little bit more comfortable with Rust, Exercism (http://exercism.io/languages/rust) has a lot of cool toy problems to solve.
Re:Small exercises to get you used to reading and writing Ru... by kbenson on Tuesday February 02, 2016 @06:58PM (#11023715)
That's really cool. I like the whole idea behind this site, and apparently I missed it the times it's been on HN in the past. I'm totally going to use this for a few languages I've been meaning to pick up (including rust).
Re:Small exercises to get you used to reading and writing Ru... by speg on Tuesday February 02, 2016 @08:20AM (#11019240)
What about all the `unwraps`? I have nightmares from last time I tried to get into Rust and it was unwrapping everything all the way down.
Re:Small exercises to get you used to reading and writing Ru... by burntsushi on Tuesday February 02, 2016 @08:53AM (#11019386)
The book has a section on error handling, starting with the basics: https://doc.rust-lang.org/book/error-handling.html
Re:Small exercises to get you used to reading and writing Ru... by danieldk on Tuesday February 02, 2016 @08:37AM (#11019324)
Handle errors, or use try! when you want to propagate errors to the caller:

https://doc.rust-lang.org/std/macro.try!.html

Re:Small exercises to get you used to reading and writing Ru... by sanderjd on Tuesday February 02, 2016 @12:38PM (#11020924)
The only violator I found in these exercises is the one that uses mutexes. The suggested answer involves `val.lock().unwrap()`, which is (anecdotally) common in real Rust code. An error result of a mutex unlock implies that another thread panicked while holding the lock[0], so propagating that panic is likely the right answer in this case.

[0]: https://doc.rust-lang.org/std/sync/struct.Mutex.html#poisoni...

Re:Small exercises to get you used to reading and writing Ru... by lhnz on Tuesday February 02, 2016 @12:56PM (#11021076)
Often the quickest replacement for an `unwrap` is an `unwrap_or` with a sensible default.

Other times where error-handling is important use a `match` there and then. And don't nest the arms of the match instead use the return of the match expression.

On the other hand, I found `try!` pretty awkward. Especially since quite often you need to create custom errors alongside it and can go down a rabbit hole in which you have to read confusing compiler messages from within macros about traits not being implemented correctly, and lifetimes missing, etc.

Re:Small exercises to get you used to reading and writing Ru... by vbezhenar on Tuesday February 02, 2016 @08:32AM (#11019306)
You should handle errors, not unwrap them.
Re:Small exercises to get you used to reading and writing Ru... by softinio on Tuesday February 02, 2016 @08:01AM (#11019144)
This is an excellent idea. Every language should have something like this.
Re:Small exercises to get you used to reading and writing Ru... by on_and_off on Tuesday February 02, 2016 @07:37AM (#11019065)
Awesome !

I learned Kotlin by glancing at the doc and then completing the kotlin koans.

I look forward to doing the same with Rust.

Re:Small exercises to get you used to reading and writing Ru... by shmerl on Tuesday February 02, 2016 @02:23PM (#11021759)
These are very useful! Do you plan to add anything about object oriented approach of Rust (structs, traits, trait objects)? This topic (OOP approach) isn't documented in a focused fashion, especially since Rust lacks common inheritance (favoring composition).

I.e. some examples of how to do OOP "the Rust way".

Re:Small exercises to get you used to reading and writing Ru... by carols10cents on Tuesday February 02, 2016 @02:46PM (#11021946)
Those would be great additions, I'll try to get to them soon!
Re:Small exercises to get you used to reading and writing Ru... by pj_mukh on Tuesday February 02, 2016 @08:29AM (#11019283)
Is there something like this for objective-C or swift? Still getting used to the syntax
Re:Small exercises to get you used to reading and writing Ru... by josep2 on Tuesday February 02, 2016 @01:12PM (#11021178)
Exactly what I needed.
Re:Small exercises to get you used to reading and writing Ru... by reacweb on Tuesday February 02, 2016 @07:52AM (#11019122)
excellent. Do you have the same for javascript ?