39 ms·
Rust in 2018: easier to use
- ohazi 9y agoAgreed. I've played with Rust on and off since ~v0.8. I tried to get through the Matasano crypto challenges a few years ago and gave up after hitting a few language hiccups. I recently gave it another go, and it's much easier to use now. I must have written around a thousand lines before needing a lifetime annotation, vs. something like 30 lines two years ago.
- QasimK 9y agoThe Matasano crypto challenges seem interesting and remind me of Project Euler. I used the latter to help learn Python a little, and I think the former would be even better for Rust!
- nafizh 9y agoAnyone has suggestions on learning rust for a python programmer who is also not strong on systems concepts?
- aaron-lebo 9y agoRead 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/ https://doc.rust-lang.org/book/second-edition/ http://shop.oreilly.com/product/0636920040385.do http://shop.oreilly.com/product/0636920040385.do
- z0ltan 9y agoUpvoted for Jim Blandy's book. That man can teach!
- red75prime 9y agoRead 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.
- littlestymaar 9y agoYou 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 ?
- red75prime 9y agoI 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.
- steveklabnik 9y agoI'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.
- steveklabnik 9y agoWhile it doesn't have this literal text, it already does have the equivalent: https://doc.rust-lang.org/book/second-edition/ch10-03-lifetime-syntax.html#lifetime-annotation-syntax 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.
- terminalcommand 9y agoFor 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/ 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/ https://doc.rust-lang.org/book/second-edition/ . And most importantly remember to have fun!
- StreamBright 9y agoDepends 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/ https://discuss.ocaml.org/
- papaf 9y agoI 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?
- grayrest 9y ago> 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 https://github.com/ocamllabs/ocaml-multicore/wiki
- StreamBright 9y agoI 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.html http://caml.inria.fr/pub/docs/manual-ocaml/libref/Thread.htm...
- papaf 9y agoThe 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.
- timClicks 9y agoHopefully 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.
- Dowwie 9y agoI appreciate your hard work and sacrifice. Really looking forward to learning from your material, when it's ready.
- chucksmash 9y agoThe 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.
- narimiran 9y ago> 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/ https://nim-lang.org/
- currymj 9y agoa 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/ 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.
- b0rsuk 9y agoI'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.
- stevedonovan 9y agoThe error messages are indeed _mostly_ marvelous (and there's an ongoing effort to make them even more marvelous). Often working with `rustc` feels like pair programming for introverts. But here's a question: `rustc` often gives _actionable_ advice - how far can can you get just following that advice? You can make `rustc` happy by following suggestions, but may end up puzzled as to the reasons for the changes it suggests.
- aaron-lebo 9y agoElm is like the next level of this.
- exikyut 9y ago> But here's a question: `rustc` often gives _actionable_ advice - how far can can you get just following that advice? You can make `rustc` happy by following suggestions, but may end up puzzled as to the reasons for the changes it suggests. Not-crazy suggestion: add a `--why` option to rustc that doesn't just shout (helpful) error messages at you but actually explains the architectural theory of why the error is occurring and provides documentation links that help outline the canonical "right way" to do whatever it is you're trying to do. The idea being that rustc applies a ton of heuristics and intelligence (perhaps by analyzing nearby code) to guess what your high-level goal is. There have been a couple of "programming helper" AI-type apps float past here recentlyish; that's what I'm getting at. The reasons I think this would be a good idea is that a) this would be really really hard to get right, but AI R&D is pretty much at the point where you could put something like this together and build it into the compiler and pull it off really well b) rust seems to have a ton of energy behind it so if any language was going to implement this, it looks like rust has a fighting chance to actually get it done c) rust hasn't stabilized yet so _now_ is exactly the time to fold something like this in. it would need to be integrated as early as possible as a bolt-on afterthought would never work the same way
- hateduser2 9y agoI like the idea but Rust has so many issues in front of it I’m not sure it has the energy to invest in something like hay.
- grayrest 9y agoI expect a "it's easier to use" evangelism push around the upcoming epoch release. There are a bunch of mostly completed but still feature flagged changes that should remove a lot of the borrow checker toe stubbing. Getting rustfmt (formatter) and clippy (linter) on stable Rust would ideally be part of the push. Aside from the almost completed features in the pipeline, I only see procedural macros (macros 2.0) and whatever happens to make async code easier to write[1] really impacting day-to-day code for most people. [1] I'd really like to see F# Computation Expressions instead of async/await. I know the language experts have said Haskell-like do notation doesn't work in Rust but I'm not sure if the F# tweaks would make it work or not.
- curiousGambler 9y agoWhy anyone would name anything "clippy" again is beyond me.
- jgtrosh 9y agoClippy is reborn from its ashes into a cultural icon; it made you react, therefore it's a fun name to choose. Kakoune uses a clippy ASCII art for its immediate help, it's nice.
- bjz_ 9y ago> Kakoune uses a clippy ASCII art for its immediate help, it's nice. Had to look this up - very cute! https://github.com/mawww/kakoune#screenshots https://github.com/mawww/kakoune#screenshots https://raw.githubusercontent.com/mawww/kakoune/master/doc/screenshot-i3.gif https://raw.githubusercontent.com/mawww/kakoune/master/doc/s...
- tomsmeding 9y agoTheir choice of executable name is slightly unfortunate in Dutch, where 'kak' basically means 'shit'.
- 9y ago
- StreamBright 9y agoWell it is super easy to develop hello world in Rust. Yay! Last time I checked there was no decent HTTP client and the documentation is just non existent for that subpar library. There were lost of promises about the newer version of async io library yet it is still WIP as of today. The performance was 30 times less than the same code in Java and after consulting many Rust developers nobody could tell me why. It is new, it is shiny but lets wait its 10th birthday before it can be taken seriously and pls provide a decent async io / http library before we even get started what else can be done in Rust.
- pingiun 9y ago> It is new, it is shiny but lets wait its 10th birthday before it can be taken seriously and pls provide a decent async io / http library before we even get started what else can be done in Rust. Have you not looked at it for a while or don't you think tokio/hyper is good?
- StreamBright 9y agoHyper is not good enough Tokio is WIP.
- xfer 9y agoYou do realize hyper depends on the tokio/future framework?
- StreamBright 9y agohttps://github.com/tokio-rs/tokio https://github.com/tokio-rs/tokio A work-in-progress rearchitecting of the tokio-core crate in line with tokio-rs/tokio-rfcs#3
- papaf 9y agopls provide a decent async io / http library before we even get started what else can be done in Rust I have found Rust library coverage to be really good for my requirements. Hyper (https://hyper.rs/guides/client/basic/ https://hyper.rs/guides/client/basic/) provides an async HTTP client although I have never needed it. Personally, if I had an application that was heavily using HTTP I would choose a different language -- Java, Scala and Go would be good choices.
- yen223 9y agoThis is going to sound weird, but I would like to see a garbage-collected Rust. Take away the borrow checker, and you still have a modern language with UTF-8 support out-of-the-box, algebraic data types, pattern matching, a focus on performance, and great tooling (cargo + rustup = <3). OCaml almost fits the bill (Rust is inspired by OCaml after all), but the tooling around it is lacking to put it mildly.
- trumpsamerica 9y agoGarbage collected allocation is coming. There's even an rfc I think. Manishearth is working gon it
- grayrest 9y ago> Ocaml almost fits the bill, but the tooling around it is lacking to put it mildly. I know the Reason guys want to tackle project setup / build / deps in addition to their syntax changes. I've found the current release's bsb toolchain to work pretty well for js targets but I haven't tried to set it up for native compilation.
- yen223 9y agoI've built several toy projects with ReasonML. I found the overall experience fairly positive, so please take this comment kindly. I'm concerned about the ReasonML -> OCaml -> Bucklescript -> JS compilation chain. The laws of leaky abstraction pretty much guarantees this is not a robust way to do things. I also wished the ReasonML folks started from scratch, instead of inheriting OCaml's baggage (no forward references, a plethora of file types to deal with, no UTF8 strings without bringing in an external lib, and so on).
- xfer 9y agoNo builtin utf-8 strings is a good/bad thing is debatable. You don't need to use bucklescript toolchain to write Ocaml, it has a very good package manager, the build-system tooling is getting better, already has great editor support for many years now(merlin). I think the tooling scene is much better than Haskell. Not sure what you mean by "no forward references"?
- karlding 9y agoOut of curiosity, how is the embedded story (for both bare-metal and RTOS) in Rust nowadays? I took a look early last year, and I remember feeling that the ecosystem still wasn't as mature as I liked. There's svd2rust [0] and dslite2svd [1], which is basically "bindgen for hardware". Please do correct me if I'm wrong, but from what I understood [2], most SVD files leave out a lot of information so a lot of what svd2rust generates is unsafe. Seems like the only way around that is to patch the SVD files. Is this still the case? In addition, what about compiling with no stdlib? And how does that interop with existing Crates (ie. do new "embedded-specific" Crates need to be created?) Super excited to see Rust gain traction! I'll definitely take another shot in my free time and see how the ecosystem has matured. [0] https://github.com/japaric/svd2rust https://github.com/japaric/svd2rust [1] https://github.com/m-labs/dslite2svd https://github.com/m-labs/dslite2svd [2] https://www.reddit.com/r/rust/comments/687b3l/embedded_in_rust_rust_your_arm_microcontroller/dhby29s/?context=1 https://www.reddit.com/r/rust/comments/687b3l/embedded_in_ru...
- jefftime 9y agoI tried exploring no_std Rust recently, and found it to be quite frustrating. After just using a Result type I was getting errors of things like `eh_unwind_resume` being undefined. Toggling LTO rectified my problems but didn't give me much confidence in reliably using no_std
- red75prime 9y ago`-C panic=abort` compiler option should have fixed the problem. If you want to be able to intercept panics, you need to provide implementations for `eh_unwind_resume` and `eh_personality`.
- jefftime 9y agoPerhaps it's just an issue of me not being educated enough with this kind of low-level Rust. Setting panic to abort in the cargo config did indeed fix `eh_personality` being undefined, but `eh_unwind_resume` still seems finnicky. Building in release will work, but building in debug will still complain
- grnadav1 9y agoA guy w/ 10 weeks Rust experiance and already gave a talk at RustConf?!
- dang 9y agoMost of the comments you've posted to HN have been unsubstantive. We ban accounts that do that, so could you please read https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html and stop doing that? This one was particularly uninformed.
- Manishearth 9y agoThe closing keynote at RustConf is generally someone who is new to Rust or has never used Rust but can bring in an interesting perspective. Last year we had Joe Duffy, who I don't think has done much Rust aside from perhaps basic experimentation, but has a lot of relevant experience from running the Midori (Microsoft's safe systems language) project. (also, the author isn't a "guy")
- Shoothe 9y agoIt's interesting because when I read about how Rust can rewrite iterators code into more performant direct loops I thought about Joe's blog posts that mentioned the same efforts for .NET. Also Span<T>. It seems .NET will have similar abstractions like Rust (of course not all can be migrated).
- pygy_ 9y agoLuaJIT does the same, down to an absurd level. From the luafun library readme (which uses iterators under the hood): https://github.com/luafun/luafun https://github.com/luafun/luafun ———— > Let's see an example: > -- Functional style > require "fun" () > -- calculate sum(x for x^2 in 1..n) > n = 100 > print(reduce(operator.add, 0, map(function(x) return x^2 end, range(n)))) 328350 > -- Object-oriented style > local fun = require "fun" > -- calculate sum(x for x^2 in 1..n) > print(fun.range(n):map(function(x) return x^2 end):reduce(operator.add, 0)) 328350 > Lua Fun takes full advantage of the innovative tracing JIT compiler to achieve transcendental performance on nested functional expressions. Functional compositions and high-order functions can be translated into efficient machine code. Can you believe it? Just try to run the example above with `luajit -jdump` and see what happens: -- skip some initilization code -- ->LOOP: 0bcaffd0 movaps xmm5, xmm7 0bcaffd3 movaps xmm7, xmm1 0bcaffd6 addsd xmm7, xmm5 0bcaffda ucomisd xmm7, xmm0 0bcaffde jnb 0x0bca0024 ->5 0bcaffe4 movaps xmm5, xmm7 0bcaffe7 mulsd xmm5, xmm5 0bcaffeb addsd xmm6, xmm5 0bcaffef jmp 0x0bcaffd0 ->LOOP ---- TRACE 1 stop -> loop > The functional chain above was translated by LuaJIT to (!) one machine loop containing just 10 CPU assembly instructions without CALL.
- eecc 9y agoJulia writes she wouldn’t yet use Rust to write webservices. Right there, this could be the mission for 2018. http://www.arewewebyet.org http://www.arewewebyet.org Nobody with a sane mind would write C or CPP micro-services, but post-Spectre and Meltdown any reclaim in performance is tangibility valuable. Rust could be the one to swoop in and claim the position
- banachtarski 9y ago> Nobody with a sane mind would write C or CPP micro-services why? I do this all the time. Maybe I should check into a nearby asylum.
- michaelchisari 9y agoIt must depend on what you're building with it. I haven't seen any reason why it couldn't be used for serving up data for an api. But as far as using it as a full featured web framework, a la Rails, Django or even Laravel, I can see why people say it's got a long way to go. That said, I haven't built anything production or large scale in Rust, so I can't claim to be an expert.
- shadowmint 9y agoThe point isn’t that no one does it, its that its hard to do right. ...and that is flat out the case for c++, unequivocally. In rust you’d expect it to be better, because of (reasons rust is good here, like safety, having a package manager and an ecosystem, etc etc), but practically, there are too many halfbaked solutions, too much ‘use nightly’ and few good stable proven solutions to look at. Rust isn’t the right solution for every problem, but it should be a good solution for secure very high performance network services. Its definitely a good goal for the year~
- e12e 9y ago> ...and that is flat out the case for c++, unequivocally. Arguably, this is why Google made go. But I'm not sure c++ micro services are a terrible idea. I think the real problems come with a) feature creep as opposed to writing new micro services, and b) the temptation to write "fast" c++. Just writing plain obvious c++ should give you a leg up on most languages (esp for micro services). But then, rather than refactor and think about the algorithm and data structures (and get a 10x performance benefit from a simpler solution), you could probably get a 2x improvement from a more convoluted, "special" c++ implementation. And that's where you're likely to encounter elder horrors lurking. [ed: I'm however more and more convinced there's no such thing as "plain obvious c" that doesn't have a number of serious issues along the lines of not checking mallloc return values, to utf8 string handling etc.]
- karo_ops 9y agoEach time I try to read an article by Julia, I get alienated by the chidlish style of writing (count the exclamation marks and caps). Which is a shame, because the article is otherwise fine.
- hateduser2 9y agoYou can probably just ignore that right?
- z0ltan 9y agoWhy the aggro? He's just expressing his point of view.
- hateduser2 9y agoIs it Aggro? I took his comment as a criticism of the author for being playful, and I’d rather the author not get criticism for that.
- z0ltan 9y agoNow you're attacking me. Brilliant.
- karo_ops 9y agoNot really. Writing style is an inherent part of journalism. `s/\!\+/./` would cut it, though.
- fyfy18 9y agoI feel the same as OP in regards to spelling mistakes. It just erks me so much that I find it really hard to continue reading. If someone hasn’t bothered to take the time to proof-read their work, what does it say about the topic they are writing about? I don’t mind if the mistakes are because they are learning English, but I’m talking about really obvious spelling mistakes.
- xstartup 9y agoIs there something like Helix (Rust) for Python?
- fafhrd91 9y agoThere is PyO3 library https://github.com/PyO3/pyo3 https://github.com/PyO3/pyo3
- eximius 9y agoRust-cpython is excellent.
- steveklabnik 9y agoMy siblings have given good answers, but there's also https://blog.sentry.io/2017/11/14/evolving-our-rust-with-milksnake https://blog.sentry.io/2017/11/14/evolving-our-rust-with-mil...
- dmitriid 9y ago- "I'm an intermediate programmer" - "I'm writing a profiler" - "I wrote a mini-OS" - "I had a talk at RustConf" Other than that, it's really good to see Rust improving.
- pygy_ 9y agoIntermediate Rust user. Obviously she excels at coding.
- reacharavindh 9y agoJust an idea: I wish there was an official wiki in the lines of Arch Wiki that shows how to do things with Rust with lots and lots of examples. True there is the Rust Programming Language v2 book and several other learning resources online, but they all carry redundant information and pass it on the user to discover what they want to learn. A legendary wiki which acts like a cookbook of all things Rust could be awesome and anyone can pick what they want to learn about and go at it. I would happily contribute and do it, but I'm just starting to learn Rust. Perhaps it is easier for other experienced Rustaceans to do it right.
- chillydawg 9y agohttps://rustbyexample.com/ https://rustbyexample.com/
- reacharavindh 9y agoThanks for the link. I thought it was a small effort to show around the language features. Like a live(runnable code) version of the Rust programming language book. Very useful for someone trying learn the language feature by feature. What I'm writing about is a how-to style wiki. For example, How to do things with Rust: How to read from stdin? How to read and write from a text file? How to make a REST API call from Rust? How to parse JSON content in Rust? How to connect to PostgreSQL in Rust? How to issue Unix commands to a remote host via SSH using Rust? How to create threads for parallel work in Rust? You get the idea..
- stumpelrielzchn 9y agoSurprised no one mentioned the long compile times yet. For me, while I'd really like to try Rust, these are a deal-breaker.
- Sammi 9y agoLooks like incremental compilation has been enabled in nightly: https://github.com/rust-lang/cargo/pull/4817 https://github.com/rust-lang/cargo/pull/4817
- stumpelrielzchn 9y agoThat's a welcome improvement from last time I looked at it. Does anyone know a ballpack figure for how many LoC/s you can expect on a beefy workstation?
- steveklabnik 9y agoIt really depends. That is, thanks to monormorphization, 1 LOC in your source doesn't necessarily mean 1 LOC compiled by the compiler. Furthermore, this is the start of incremental: we have more stuff coming down the pipeline.
- shmerl 9y ago> like – maybe Rust is not for people who are already C++ experts and who are happy with C++? I don’t know! I think Rust is very good for C++ experts. Some key concepts like ownership / RAII and etc. are well known in C++, and they should be easy to understand.
- cesarb 9y agoYeah, people with C++ experience have an advantage when learning Rust, since they're used to these concepts, and the Rust compiler enforces things they already know to be careful with (like not mutating a container while there's a live iterator to it). On the other hand, Rust lacks some things C++ has like being generic over values instead of just over types, so for instance implementing a trait for every fixed-size array of a type is currently AFAIK not possible (the usual solution is to use a macro to manually implement the trait for every size up to 32).
- shmerl 9y agoSure, there are differences as well, and there is no point in always mimicking C++ approaches in Rust 1:1. But I think overall, coming from C++ to Rust should be one of the easiest transitions.
- TillE 9y agoAs someone who's extremely comfortable with C++, I've tried Rust multiple times but keep bouncing off. Ultimately my problem is just that it doesn't have enough exciting features to lure me away, especially with C++ improving every few years. Compiler-enforced safety and a built-in package manager are really nice, but it doesn't quite make up for the loss of a lot of handy C++ features.
- steveklabnik 9y agoWhich features do you miss the most?
- jnordwick 9y agoThis guy's writing style (is really annoying!)
- steveklabnik 9y ago(The author is not a guy)
- b0rsuk 9y agoI'm learning Rust by writing graphical / glitch art software. Not too much exposure to 'systems' programming although color spaces are more complex than you'd think. Performance is important when you shuffle thousands of pixels around, and some of it is easy to parallelize.