News for hackers. Stuff that matters.
Re:Rust in 2018: easier to use by nafizh on Sunday January 14, 2018 @02:21AM (#16143214)
Anyone has suggestions on learning rust for a python programmer who is also not strong on systems concepts?
Re:Rust in 2018: easier to use by red75prime on Sunday January 14, 2018 @02:46AM (#16143251)
Read the books, write code. When you'll encounter lifetimes, it's good to remember that lifetime annotations are descriptive and not prescriptive. You can't change lifetime of a variable by adding lifetime annotations.

For example, local variables of a function get destroyed on function exit no matter what and you can't prevent it by adding lifetime annotation to a local variable reference you are trying to return.

That was a stumbling block for me.

Re:Rust in 2018: easier to use by littlestymaar on Sunday January 14, 2018 @07:41AM (#16144025)
You summarized it so well ! It was also a huge source of confusion for me in the beginning.

Would you mind if I made a pull request to the Rust book adding your explaination to the lifetime chapter ?

Re:Rust in 2018: easier to use by steveklabnik on Sunday January 14, 2018 @02:54PM (#16145980)
While it doesn't have this literal text, it already does have the equivalent: https://doc.rust-lang.org/book/second-edition/ch10-03-lifeti...

> Lifetime annotations don’t change how long any of the references involved live. In the same way that functions can accept any type when the signature specifies a generic type parameter, functions can accept references with any lifetime when the signature specifies a generic lifetime parameter. What lifetime annotations do is relate the lifetimes of multiple references to each other.

Re:Rust in 2018: easier to use by littlestymaar on Monday January 15, 2018 @03:48AM (#16149361)
Cool. I haven't read the second version of the book, and I read the first version about two years ago I think. Glad to see this difficulty is now covered. Carry on with the great job Steve :)
Re:Rust in 2018: easier to use by steveklabnik on Monday January 15, 2018 @08:26AM (#16150309)
Ah ha! Yeah, it's quite different.

Thanks :)

Re:Rust in 2018: easier to use by red75prime on Sunday January 14, 2018 @08:05AM (#16144094)
I wouldn't. Feel free to use it. But I have the impression that the Rust book contains something to that effect.

"Descriptive and not prescriptive" part probably comes from stackoverflow. I don't remember exactly.

Re:Rust in 2018: easier to use by steveklabnik on Sunday January 14, 2018 @02:53PM (#16145977)
I'm not sure where I heard it, but I certainly repeat it. It's not literally in the book though, I'll also reply to your parent about this.
Re:Rust in 2018: easier to use by aaron-lebo on Sunday January 14, 2018 @02:32AM (#16143236)
Read the rust book and actually build something with it. There's a lot of stuff in Rust that you just never have to consider in Python so there's no easy way other than diving in. Actually, Programming Rust might be better, but it's not free.

https://doc.rust-lang.org/book/second-edition/

http://shop.oreilly.com/product/0636920040385.do

Re:Rust in 2018: easier to use by z0ltan on Sunday January 14, 2018 @04:11AM (#16143430)
Upvoted for Jim Blandy's book. That man can teach!
Re:Rust in 2018: easier to use by terminalcommand on Sunday January 14, 2018 @02:51AM (#16143264)
For a python programmer some parts of Rust might feel too low-level and out of reach. However that is not a big issue. I would suggest you get comfortable tooling first, intellij rust plugin was awesome when I last checked it out. It comes with autocomplete, on-the-fly syntax checking etc. out of the box. The Rust compiler has very sane and understandable error messages (at least for basic tasks) so that will guide you a lot. I would also advise you to get on #rust-beginners on irc.mozilla.org, if you have any questions you will get instant help, which is a huge benefit :).

Lastly, I would first advise you to work through https://learnxinyminutes.com/docs/rust/ to get a feel of the language (like dipping your toes into the water). If you like what you see, then continue from the Rust book: https://doc.rust-lang.org/book/second-edition/ .

And most importantly remember to have fun!

Re:Rust in 2018: easier to use by currymj on Sunday January 14, 2018 @06:30AM (#16143812)
a big part of the early Rust community comes from Ruby, so Rust as an entry to systems programming is really common.

Mozilla's IRC server has a #rust-beginners channel that is like, overwhelmingly helpful. Go and ask stupid questions.

"The Rust Programming Language" is good:

https://doc.rust-lang.org/book/second-edition/

Knowing the difference between the stack and the heap, and having a picture of it in your head and understanding which variables go where, and what happens to the stack when calling and returning from functions, is pretty important. (Python wouldn't give you this intuition, although programming in something like Java might.)

I half-assed learned to code in C++ for scientific purposes. Later I got deeper into Rust, and it's made me a better, safer C++ programmer when I run into C++ code.

Re:Rust in 2018: easier to use by timClicks on Sunday January 14, 2018 @04:34AM (#16143482)
Hopefully I am not overstepping bounds by mentioning my book, but I encourage you to take a look at Rust in Action by Manning. It's written for current programmers who want to learn Rust as well as enough of the systems programming concepts that seem to sneak into Rust docs and discussion.
Re:Rust in 2018: easier to use by Dowwie on Sunday January 14, 2018 @05:37PM (#16146925)
I appreciate your hard work and sacrifice.

Really looking forward to learning from your material, when it's ready.

Re:Rust in 2018: easier to use by chucksmash on Sunday January 14, 2018 @05:02AM (#16143561)
The best thing you can do is to start! Your background sounds similar to mine. V2 of the docs are really good. I've called them my favorite piece of technical documentation somewhere on HN before.

Anyway, the other comments about reading the docs and building things are correct. I'd just point out two things in addition.

1) Don't feel like you have to go write some impressive low level application just because the language is lower level - fizzbuzz works fine too.

2) Don't worry too much about whether you're strong enough on systems concepts. It's not a class you fail if you show up unprepared for; it's (presumably) play time you're engaging in to scratch your own itch. You'll make mistakes but that's not something to be avoided, it's the only way to learn.

Re:Rust in 2018: easier to use by narimiran on Sunday January 14, 2018 @05:10AM (#16143577)
> learning rust for a python programmer

You might give Nim[1] a try.

Coming from Python, you might find Nim's syntax (and significant whitespace) familiar. It took me (also a Python programmer) a week or so before I was able to write small programs in Nim.

(Don't let "not yet v1.0" to turn you off)

[1] https://nim-lang.org/

Re:Rust in 2018: easier to use by StreamBright on Sunday January 14, 2018 @03:17AM (#16143308)
Depends what is your goal. Learning a language with decent type system? Learning a language with lower level access to operating system features? I would suggest to learn OCaml because it got really popular in 2017 thanks to Facebook & Bloomberg, it has an amazing type system and you can use it to build CLI tools and web pages (Reason/Bucklescript) with an insanely good tooling (utop, jbuilder, merlin) and the community is probably the best community of software engineers I have encountered recently. If you are interested in lower level coding there is Mirage as well.

https://discuss.ocaml.org/

Re:Rust in 2018: easier to use by papaf on Sunday January 14, 2018 @03:51AM (#16143376)
I used OCaml a few years ago and I thought it was an excellent language. Despite being powerful it was really easy to learn.

One thing that put me off in the end was that it didn't support native OS threads (I have the same problem with Racket). Has threading support improved over the years?

Re:Rust in 2018: easier to use by grayrest on Sunday January 14, 2018 @05:33AM (#16143647)
> Has threading support improved over the years?

The main push in this area is Multicore OCaml[1]. I don't track OCaml closely enough to know how getting this into the main compiler is going.

[1] https://github.com/ocamllabs/ocaml-multicore/wiki

Re:Rust in 2018: easier to use by StreamBright on Sunday January 14, 2018 @07:48AM (#16144047)
I am not sure what exactly you are missing, isn't this a native OS thread either POSIX or Win32?

http://caml.inria.fr/pub/docs/manual-ocaml/libref/Thread.htm...

Re:Rust in 2018: easier to use by papaf on Sunday January 14, 2018 @03:58PM (#16146387)
The documentation that you linked to is not describing native OS threads. I am sure that the OCaml implementation is good for a lot of applications.

However, because I am used to writing multithreaded code using pthread or std::thread, I find the standard OCaml model uncomfortable and limiting. Its mostly a matter of personal taste but this is the reason I stopped using OCaml.

Re:Rust in 2018: easier to use by seertaak on Sunday January 14, 2018 @01:53PM (#16145600)
I tried it too; after I realized I that every struct had to have unique field names, I gave up. This was too much craziness for me, although I did think the module/functor concepts were very cool.
Re:Rust in 2018: easier to use by ernst_klim on Tuesday January 16, 2018 @03:42AM (#16156681)
>I that every struct had to have unique field names

Nope, different structs could have fields named the same.

Re:Rust in 2018: easier to use by masoodusmani on Sunday January 14, 2018 @10:33AM (#16144640)
Are you sure Racket doesn't support native threads? I thought it had something called "places" for that.
Re:Rust in 2018: easier to use by papaf on Sunday January 14, 2018 @03:46PM (#16146307)
I did not know about places, but after reading about them [1], I can see that although they are implemented on top of OS threads, it is not a conventional threading model.

For instance there is an instance of the Racket VM per place and this makes them heavier than it would be in a standard system programming language language such as C, C++ or Rust.

I am not saying it is better or worse -- just different.

[1] https://www.cs.utah.edu/plt/publications/dls11-tsffd.pdf

Re:Rust in 2018: easier to use by z0ltan on Sunday January 14, 2018 @04:10AM (#16143429)
I have always been interested in OCaml, but I have a genuine question though - last when I looked at seriously at it, the standard library seemed to be a bit of a mess lacking a lot of features. A lot of modern resources seemed to focus on using Jane Street's Core(?) which I would not like to use - I'd rather depend on the standard language for standard features. Is this still a thing, or am I mistaken, or both? Please help! I really would like to use OCaml for a variety of hobby projects, including toy compilers. Which books/resources would you recommend?
Re:Rust in 2018: easier to use by xfer on Sunday January 14, 2018 @08:44AM (#16144211)
You don't need Core, the shipped stdlib is good enough for toy projects. There are other stdlibs like containers and janestreet has split their stdlib into smaller pieces. What's your issue with having to use alternate stdlibs?

Regarding books, Real World Ocaml is very well written, although some examples might need tweaking.

Re:Rust in 2018: easier to use by z0ltan on Sunday January 14, 2018 @09:35AM (#16144390)
Thanks for the reply!

Mostly wondering how people ship stuff if there are different variants of std libs? Say you write your code entirely using one std lib and then try to share it (the code that is) with somebody who uses a different std lib, then the onus of learning the new std lib is entirely on him, right? How does that work for teams then? I know that Jane Street is a big user and so they have considerable influence. That being said, does the std lib (the one bundled with the distro) have enough features (like all the necessary data structures, for instance) to make using it viable in a non-trivial project (off the top of my head, say writing a very simple web server)? If so then, I suppose that's good enough.

Any recommendations for learning material? I have a copy of "Practical OCaml", don't really like it. INRIA's materials seem quite substantial, but more like reference.

Re:Rust in 2018: easier to use by xfer on Sunday January 14, 2018 @10:23AM (#16144587)
The standard stdlib has all useful data structures, mostly the differences are in providing more convenient functions and monadic interfaces that you might have to write yourself, if you didn't use the alternate libraries. There is nothing to "learn" about using another stdlib since most signatures are the same. And they can use a different stdlib if they want.

The migration from standard stdlib to alternate ones is fairly trivial(some signatures might differ but typed language means the compiler will catch them for you), so you can start using the stdlib and if you feel like writing some trivial things that should be in the stdlib or you need some advanced data structures you can use the alternate ones.

Also you need `lwt`(most people prefer this)/`async` library for writing concurrent programs like a webserver. `Cohttp` is a good library for doing http based client/servers. I strongly recommend `Real world ocaml` and the reference manual is excellent at looking up some new type-level features. Also reading well-known libraries code is an excellent way to learn a language.

Re:Rust in 2018: easier to use by z0ltan on Sunday January 14, 2018 @12:05PM (#16145019)
Excellent. Thanks for the detailed answer - that really helps. To be honest, I want to use OCaml for writing some toy compilers to begin with, and I'm sure that that'll require only the core language, but I would like to use it for more serious projects after that!

I'll start off with "Real world OCaml" and see how it goes!

Re:Rust in 2018: easier to use by xfer on Sunday January 14, 2018 @01:43PM (#16145546)
Here is some resource for you to learn from: http://plzoo.andrej.com/
Re:Rust in 2018: easier to use by erk__ on Sunday January 14, 2018 @05:28AM (#16143626)
You could also take a look at F# wich is also a ML derived language so the syntax is very similar to OCaml.
Re:Rust in 2018: easier to use by z0ltan on Sunday January 14, 2018 @09:38AM (#16144405)
I did consider it seriously (especially after watching Scott Wlaschin's Parser Combinators video), but it seems a bit too MS-centric for my liking. Who knows, maybe if learning OCaml doesn't pan out that well, it might be F# for me! :D ... the community seems to be focused, so that's one big advantage.
Re:Rust in 2018: easier to use by b0rsuk on Sunday January 14, 2018 @04:22PM (#16146557)
I'm a Python programmer with no prior experience to systems outside university.

Browse Python projects on github and find some that strike your fancy. Especially those which may run slow, like puzzle solvers, image manipulation apps, etc. Bonus points if they have few external dependencies. Rewrite them in Rust.