26 ms·
Tour of Rust
- rimutaka 6y agoI think much of the official "rust-by-example" would benefit from using the rust playground instead of the printed examples.
- the_mitsuhiko 6y agoAll code blocks in rust by examples can be edited and have a play button.
- rizky05 6y agoAnd most of that cannot be run on playground because of incomplete source code, missing dependency or wrong configuration.
- steveklabnik 6y agoThat has to do with the contents, not the playground. Also, many examples have hidden context that if you open the example in the playground, you’ll see and will make compile.
- vanderZwan 6y ago> Execution operation failed: Compiler execution took longer than 12000 ms Are my privacy add-ons too strict or is the server overloaded at the moment?
- pcstl 6y agoProbably getting the good old HN hug right now. Might want to try later.
- jki275 6y agoIt times out a lot. Try reloading the page, for some reason that helps sometimes.
- AnonC 6y agoI got the same error too, and gave up on the playground (I posted a top level comment and then deleted it after seeing I wasn’t alone).
- siraben 6y agoIs the naming inspired by Stroustrup's "A Tour of C++"? [0] [0] https://www.amazon.com/Tour-2nd-Depth-Bjarne-Stroustrup/dp/0134997832 https://www.amazon.com/Tour-2nd-Depth-Bjarne-Stroustrup/dp/0...
- Laremere 6y agoThis looks very much like the Go tour: https://tour.golang.org/welcome/1 https://tour.golang.org/welcome/1
- jay_kyburz 6y agoThanks for the link. It was great to read them side by side. I had my suspicions, but I think I'm more of a Go person than a Rust person.
- wdroz 6y agoUnfortunately for me, they don't mention macros in this tour of rust. Even after reading the official book, I'm still not comfortable with macro and macro syntax. Do you have any recommendations?
- kd5bjo 6y agoThe Little Book of Rust Macros is a pretty good, but dense, overview of how macro_rules! can be used. (Procedural macros are a completely different beast). https://danielkeep.github.io/tlborm/book/index.html https://danielkeep.github.io/tlborm/book/index.html
- 65536 6y agoAlso, there are a lot of uses of macro_rules! in the Rust compiler and standard library repository. https://github.com/rust-lang/rust/search?q=macro_rules&type= https://github.com/rust-lang/rust/search?q=macro_rules&type= Looking at some of those and reading https://doc.rust-lang.org/rust-by-example/macros/syntax.html https://doc.rust-lang.org/rust-by-example/macros/syntax.html and https://doc.rust-lang.org/reference/macros-by-example.html https://doc.rust-lang.org/reference/macros-by-example.html can potentially be instructive.
- burfog 6y agoDepending on your preference for macros, run "info m4" or "info cpp" to read the documentation. You can use both. You can run them more than once, perhaps changing the source with a sed or perl script between passes.
- kd5bjo 6y agoNative Rust macros are generally preferred, because they prevent a few classes of error that can happen with the purely textual macros cpp and m4 use. In particular, they prevent unpaired delimiters from appearing in the macro expansion and name collisions between the macro implementation and the callsite.
- kibwen 6y ago
- blondin 6y agorust doesn't look like it has a steep learning curve. not to me at least. the discouraging thing is the "weird" syntax. i feel like rust is the result of diverging ways of looking at things. not saying it's a bad. just wish some effort were put into making a consistent syntax. seems weird to me that whoever decided on the function keyword "fn" would write the "Option" type. they would have written "Opt". but no, it's "Option". consistency is very underrated. and these things just look odd to me but the rust community think it's okay, so, oh well...
- kibwen 6y agoThe general wisdom of language/library design is that abbreviations should be used only for very common things, and only when those abbreviations are unambiguous in context. Prehistoric Rust had a rule that all keywords could be no longer than five characters (in defiance of Javascript's `function`), but forums (including HN) endlessly complained about `ret`, hence today it's `return`. :P (I admit that I wanted to Rust to change its `fn` to `func` once Swift showed its hand, but such is life.) Meanwhile, in 2020 `Option` might be on its way to becoming a widely-accepted concept in language design, but back in 2011 it was still a radical idea that Rust was trying to smuggle over the border from functional languages, against the will of people used to languages with pervasive nullity. The language that eventually supplants Rust someday might call it `Opt` (in the same way that Rust turned C++'s `vector` into `Vec`), but back then `Option` needed all the lubrication it could get without having to get bogged down in the abbreviation bikeshedding.
- zozbot234 6y agoThe thing is that 'return' is not very common either, because Rust has shorthand for returning at the end of a function :-P I think the standard library ought to use slightly longer names since it's far less strictly bounded than the set of language keywords, so I'm fine with 'Option'. 'Vec' is a bit awkward from that POV, but then again 'Vector' would be a lot worse. 'Box' is also awkward in the same way but thinking about it, it's not easy to convey the notion "this value is behind a pointer" so you might as well use a conventional name and get it over with.
- swordbeta 6y agoThe playground is rather slow, is it possible to run this locally much like how go's tour can?
- marvinblum 6y agoFrom what I've heared, Go compiles much faster than Rust. But I'm only experienced in Go... [Edit] I mean you could just install Rust, copy the samples and run them locally?
- bouncycastle 6y agoYes, I've noticed the Rust compiler does fancy stuff like check for similarly named constants, check constants have uppercase names, do static analysis to check that I've kept my immutable variables immutable, check that a semicolon is always at the end, and so on. I've never found those necessary in Go...
- ylyn 6y agoThose are negligible in terms of compile time.
- bouncycastle 6y agoIndeed. I suspect this is just the tip of the iceberg?
- oconnor663 6y agoThe bigger costs as I understand them, are that everything needs to get passed through LLVM, and that the widespread use of generics increases the amount of generated code that passes through LLVM.
- ATsch 6y agoLast I heard, the biggest source of compile time in rustc is emitting absolutely enormous amounts of LLVM IR and leaning on aggressive low-level LLVM optimisation passes to clean things up. There are efforts to make most of these optimisations earlier that have been landing in recent releases, but I'm not sure what the overall state of it is.
- The_rationalist 6y agoI think this tour of Scala should interest rustaceans as many discover in rust their interest for advanced type system/functional features. And Scala in this aspect represent what rust should be in the next decade! http://dcapwell.github.io/scala-tour/Partial%20Function.html http://dcapwell.github.io/scala-tour/Partial%20Function.html
- mrkeen 6y ago> When building apis that are given PartialFunctions, its your responsibility to make sure the given input is proper for the function. That's not exactly the first 'feature' I'd want Rust to get.
- fctorial 6y agoToo bad mr crabs isn't the guide.
- armSixtyFour 6y agoHe asked for too much money
- hn_reader_75 6y agoOff topic. Asking seriously, will there be any point learning some language other than rust in coming days? Will rust be ubiquitous in future?
- AnonC 6y agoJust an opinion. Rust will never be ubiquitous in the future. It could aim to be as ubiquitous as C++ is, but I think those systems will be split among Rust and other languages whenever they’re rewritten and someone decides C++ should be eliminated. It requires some additional upfront effort that many practical projects may not have the luxury for (people/management types think it’s ok to fight random bugs in the future). Rust may not have the rich and mature library ecosystem like certain other languages either. But learning Rust will likely help in being a better programmer.
- jfkebwjsbx 6y agoRust (and others like D, Ada, Zig...) won't be ubiquitous because it is a systems programming language intended to replace C and C++. This kind of languages are specialized and more costly to develop in them. Everything else (the world of Java, C#, Go, Python, JavaScript, Swift, etc.), which is the majority of the programming done nowadays, will stay the same.
- bhaak 6y agoI'm surprised that you put Go in the latter group and not in the same group as Rust and C/C++. What features of Go disqualify it as a systems programming language?
- _hl_ 6y agoIt’s not that fantastic for low level systems programming due to garbage collection and the runtime. If you’re working with C et al, you’re generally doing something that requires extreme control, and Go is too high level to do that nicely - you can use it of course, but it’s just... weird. C++ is not really a low level systems language because, very broadly speaking, low level stuff doesn’t benefit as much from the extreme flexibility and abstraction capabilities of C++. It’s used more as a high-performance application programming language for large, complex stuff. Go doesn’t fit that niche because it’s just not a very powerful language. The niche where a simple language like Go is applicable for systems stuff without being too slow or high-level is extremely small. It’s a fantastic language for working on business-logic type stuff, web backends, etc, and excels when working with less experienced developers or larger teams. It’s as easy as python et al but actually has reasonable performance. But it’s not really a systems language for serious systems stuff.
- deleted 6y ago[deleted]
- swagonomixxx 6y agoI'm not sure if I'm the only one that this happens to, but every couple of months I end up re-learning Rust, and because I don't really have any use of it in my day to day job (Python and Go, some C++) I end up un-learning it, and then the cycle continues. What kind of projects are a best fit for Rust, for those who are experienced with it? Any recommendations for projects to make Rust stick? Thanks!
- Fiahil 6y agoHigh-throughput web APIs is a pretty good fit for a rust project. Otherwise, any data system leveraging heavy parallel computations.
- cmrdporcupine 6y agoYes, I have the same experience. I've 'learned' it many times, including from back when it was really obscure and a twinkle in Graydon's eye. I am a big supporter of what it is. But at this point in my life I'm not going to be able to dedicate a chunk of time to a fresh project of my own in it. I really would just like a $job working in it. But there's a bit of a chicken and egg problem there.
- estebank 6y agoSome companies, like the one I work at (https://developer.commure.com/ https://developer.commure.com/), will hire people to work on a Rust codebase even if their prior experience doesn't include it but are willing to learn. I would say it's worked quite well for us so far.
- jlokier 6y agoI just visited your link, as I would like a Rust job. Got back a page with nothing but this: We're Sorry... Commure is unavailable in your location. We’re required to comply with US sanctions laws that restrict the use of our site in certain jurisdictions. Because of this, our services are not available in Crimea - Region of Ukraine, Cuba, Iran, Iraq, Syria, North Korea and other US embargoed countries. But hold on a minute. I'm in England! Whatever happened to the special relationship? :)
- mendyberger 6y agoThis site can actually be used on mobile, cool!
- philipov 6y agoDid anyone else notice Interlingue in the language options? Maybe we could get a Tour of Rust written in Esperanto :)
- richardanaya 6y agoTour of Rust english author here, David https://github.com/Dhghomon/ https://github.com/Dhghomon/ our Interlingue writer was one of our most passionate translators. We'd be happy to have Esperanto.
- vandal_at_your 6y agoPushing this language and Go as required, responsible, NG languages is another one of the foibles of the cloud/web and it's owners. For those of us in HPC and scientific compute where is the practical reason to switch from C/Python and the unix toolset?
- DoctorOW 6y agoI'm in the web field generally. Those I've spoken to outside of that field find Rust a much faster way to develop safe and stable programs that would have otherwise been written in C. Feel free to take this with a grin of salt. I suspect the C devs who don't like Rust haven't taken the time to discuss it with me.
- seanalltogether 6y agoEvery time I try to learn more about Rust, I keep hitting a wall around OOP. I know Rust takes the stance that composition is better then inheritance, but I've never found the examples to be very convincing. How do rust developers deal with complex structs that contain lots of properties and features. For instance, if I need to create "CustomButton" that means I have to implement all the Traits from Button, which maybe requires Traits from LayoutView, which requires Traits from View, etc.... Additionally I need to maintain duplicate properties of those objects in my Custom Button rather then inheriting from a Button struct. It sounds like a headache to maintain.
- zozbot234 6y agoYou can do almost everything with a combination of traits (for interface inheritance), simple composition and the Deref trait (to auto-forward unimplemented functions to the contained class). The one feature you're missing compared to actual OOP inheritance is open recursion, which is a big footgun more than anything (see: the "fragile base class" problem). The Rust docs include an in-depth explanation of how Rust relates to traditional OOP: https://doc.rust-lang.org/book/ch17-00-oop.html https://doc.rust-lang.org/book/ch17-00-oop.html
- afranchuk 6y agoThere's a lot of detail and intricacy here (in that you could likely architect a design that didn't really rely on the sort of hierarchy you describe at all), but generally if you wanted something similar to [single] inheritance you could implement std::ops::Deref for the child types. That doesn't necessary cover things like virtual methods, but those could be implemented simply as boxed functions that child instances assign on creation.
- estebank 6y agoYou use composition and leverage the Deref trait to make the methods of specific fields available on the parent. This works on arbitrary levels of nesting which makes it look like OOP, but depending on what you're doing this is a good idea or not. https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=6961c82a243ed64594a7263db88110c8 https://play.rust-lang.org/?version=nightly&mode=debug&editi... As you can see this can be verbose, but you could have derive macros (like the Debug one I'm using here) to do this boilerplate for you. An alternative way of dealing with OOP inheritance is by using traits, where you implement the behavioral relationships by writing new traits for the behavior you want, adding super traits for them. https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f895c919b5aa26ecb2f32e1922061454 https://play.rust-lang.org/?version=nightly&mode=debug&editi...
- tptacek 6y agoThis is good, but the string handling stuff should be earlier in the tour, because Rust's strings are idiosyncratic (whole blog posts have been written about str vs. String, an issue that doesn't appear in most other languages). It'd be a nit, but handling strings is one of the most important things you usually need to know to be productive. I'd love a version of this for people who know Rust that was just Rust idioms, similarly explained. I hang out in Slack channel with a bunch of Rust programmers (because I'm bumbling my way around in Rust as well) and it feels like there's a lot of communally understood idioms that aren't super apparent from the Rust Book.
- steveklabnik 6y agoWe learned the hard way with the Rust book that this is important: one of the biggest structural changes we made between the first and second editions was re-orienting the entire book around "how can we get to Strings quickly", and for exactly the reasons you state. And yeah, the intermediate area is where things are worst now, for sure. It's sorely needed.
- richardanaya 6y agoI think the big difference between Tour of Rust and the Book is my example sizes were meant to be as small as possible to demonstrate one concept at a time. Most of the concepts require no strings at all to explain. Particularly through the procedural programming chapters.
- steveklabnik 6y agoSure. The issue is, it’s something that people run into very early when they try to actually write code. They won’t go through the whole Tour before trying to do so. They certainly don’t with the book :) Anyway the author should do whatever they want. I’m glad folks other than me are writing docs! I haven’t managed to actually go through the Tour yet myself, this is just a riff on the observation made in my parent’s comment.
- richardanaya 6y ago
- jasonzemos 6y agoAs a skeptic of Rust I really appreciate this. I was very pleased to find the ASM option in the drop-down menu specifically. Coming from C/C++ I've found it difficult to understand how and why Rust generates the code that it does. Rust appears slightly less direct in its description of programs than C++ as it's shed the hardware-driven abstraction of memory and physical layout. My comfort level with seriously considering Rust for a next project is proportional to my understanding of what it's doing under the hood. Thanks! Looks great.
- steveklabnik 6y agoThe Compiler Explorer supports Rust as well, and is very good at this kind of thing. You may want to check it out if you don't already use it for C++ stuff.
- JulianWasTaken 6y agoMaybe a bit offtopic, but two minor UX issues hit me the first 15 seconds of trying to open this; sharing in case someone who maintains this sees and hears similar minor feedback -- First when I saw the splash screen, and saw it say "Press to Continue", I well first was confused for a split second on "press what?", then assumed it meant "click", so I clicked my mouse, then when that didn't work assumed it meant "a key" so I hit a random key, then when that didn't work, summoned my conscious brain and figured "well I guess it means click specifically on top of this link text". And then once on the next page, glancing at a long list of languages without really reading the text I said "ok I speak English, guess I should click on that", only to see the same exact page refresh. "Maybe it's broken?", so I clicked again. When it didn't work the second time, again, conscious brain again -- "OK, guess there's a next link somewhere here", and scrolled to the bottom.
- sieabahlpark 6y agoIt was underlined which has historically means it's a hyperlink. "Press to continue" means to click the link. Not sure how this is a UX issue. "A long list of languages", you mean the 10 or so listed? Then a 3 short sentences later the "next" button you seek? They're plainly visible. I'm not sure if this is a UX issue and more one between the keyboard and chair.
- fold_left 6y agoI was caught out by the 2nd one too, I hit "English" expecting to be taken to the English version of the start of the Tour.
- pen2l 6y agoSorry, off-topic, but something interesting I just went through: in the first page, where it offers you multiple languages to choose from, one of the options is "Interlingue". I've never seen it before, I didn't realize it was a conlang. Anyway, I used my google-translate addon to select a couple sentences, while having that lang selected... and it gave a comprehensible translation... and recognized original lang as Spanish. I selected the next sentence, it gave a comprehensible English translation, but recognized original lang as Romanian! Another sentence: good output, but French! Another sentence: again, perfectly good translation offered, but input lang recognized as Corsican! Truly a bizarre experience.
- CubicsRube 6y agoTour de Rust? No? OK, I'll show myself out...
- bytematic 6y agoWhy does the compile debug information get printed to the standard error area?
- cryptonector 6y ago> With so much difficulty in working with Unicode, Rust offers a way to retrieve a sequence of utf-8 bytes as a vector of characters of type char. > A char is always 4 bytes long (allowing for efficient lookup of individual characters). Please fix this! A 4-byte char is NOT a character but a codepoint.