Skip to content

Latest commit

 

History

History
28 lines (26 loc) · 13.4 KB

04-Claudia-Saxer.md

File metadata and controls

28 lines (26 loc) · 13.4 KB

66 hours of Rust

Live captioning by White Coat Captioning

CLAUDIA: So hi, everyone. I'm thrilled to be here and a bit nervous as well. So can you please switch the slide? Awesome. So I am going to talk about the good, the bad and the ugly of Rust I experienced in the last months learning Rust. Does anyone actually know the movie? Hands up. Oh, awesome. Nice, a lot of people. So who am I? My name is Claudia, I'm a software engineer working with C# in Switzerland in a big engineering company, so why did I learn Rust? How come I learned Rust at all? It's kind of a funny story. A friend of mine asked me to write a proposal for the RustFest and I don't know any Rust at all. Never - actually, I heard about Rust just doing my studying, like five years ago, hearing about the memory safety of Rust but nothing more and not really looking into it. Also in the C# world you actually hear about Rust with WebAssembly. C# and WebAssembly are getting a thing and a lot of examples actually with Rust. So I thought to myself: it would be fun to talk at the RustFest and writing a proposal. Not a lot of pressure at all, but I mean they are not going to take me anyway, so let's just try it. And they did! So I felt like this guy, Angel Eyes from the movie. You know, the pity is, when I'm paid, I always follow my job through. So that was a month ago and I started to learn Rust. So I'm going to talk about my journey, The Good, The Bad and The Ugly. Here you can see some kind of motivational chart. In the beginning it's awesome, like I can learn a new language. I can learn Rust. So it's a really great time. Then you can see the first bump. That was an experience with tooling. I am going to tell you about it. The second bump here is WebAssembly and the last one where I hit rock bottom was JavaScript. So that's how it started, like Clint Eastwood said: the way back to town is only 70 miles. So if you save your breath I think a man like you can manage it. Adios. So Clint Eastwood, the handsome guy here, is the good guy in the movie and that was like Rust for me as well. I started learning Rust with the Rust link page and some YouTube tutorials just to get to know the types and the differences with C# as well. Some parts that I really enjoyed, I found it really easy to read Rust itself. If you know some programming languages, you can look at it and you can somehow read it. I haven't looked at all the macros yet so I heard some rumours there. Traits and structs is something I really enjoyed because I come from the object oriented world, so I could use a lot of the same series there. Also the syntax, you know the dot dot you can use, I really enjoy that syntax. C# I think brought that at the last update with the array index and I was happy to see TO. I think my favourite part of the language was the loop statement. So this is the first language ever that I saw you actually have a statement for loop and you don't have to write "while true" and it just saved some time and that anyone thought about it and did it, I think that's really awesome. So stuff that I found a bit weird was the snake_case. I am used to camel case and Pascal case. I will get used to it. And then the return statement, but at the first examples I just thought it was like any other language, and then I saw you can actually just write one and it does the same. It returns one so I was asking myself: why does Rust have that? Why does it do it? And I was confused at the start. Now I know actually that it just returns the last statement every time, and I like it. It's nice. Then the ownership and the powering, it's a new concept for me. So I somehow found it hard. It's a very steep learning curve but it's I think one of the most important parts of Rust because of the memory safety. But I still have a lot to learn here. So the tooling. Here you can see Lee Van Cleef, the bad guy, but not everything is bad, like with Lee Van Cleef as well, so I will start with the parts I enjoyed. For me that tooling is like a friend. So I will sleep better. My good friend is by my side to protect me. I used Visual Studio code. As you can see from the icon, it's IDE. Also something to mention, I work with Windows and not with Linux, so I think the Visual Studio code is one of the age preferred IDEs to use if you work with Rust and I used cargo as a package manager and also after some time I realised: how do I format my code? I am going to have some possibility to format, so I installed rustformat and I was confused that it doesn't come with RLS. So another part of the tooling are the error messages from the compiler, so everyone I talked with about, the compiler messages from Rust, my expectations were up there about seeing the error messages, and then I happened to encounter this. So as you can see the message is not on the correct line. It's on the start of my implementation. And also the expected and found wasn't that much helping. That was a bit of a letdown, maybe because my expectations were so high. But most of the time they were very helpful. So what was the bad part of my experience of the tooling? You remember from my motivational chart, the first bump? It was here. So, "God's not on our side because he hates idiots also", and the idiot was me. I don't know if you recognise the icon. It's Visual Studio. So I set out my tooling with Visual Studio code and it worked perfectly fine, and I was like: why shouldn't it work with Visual Studio as well? Let's try it. So some guy actually wrote an extension for Visual Studio to work across some years ago for an old Visual Studio version, and I tried it out. So I installed it and started Visual Studio and it didn't work. I Googled and some guys found: hey, let's deinstall the RLS. If you start Visual Studio, it will prompt you to install it. It didn't. So that was like the low point and I said to myself: yes, it won't work. I'm kind of an idiot trying it out with an earlier Visual Studio. So it was 2019 and I used '17, and I used 2019, so then I got back to Visual Studio code and everything was working. I had to install RLS and install it all again but in the end it worked and I'm happy with Visual Studio. Don't try it. So then I began my journey. I looked at the language, the types, structs and traits and wanted to start a new project with WebAssembly. So I saw this awesome GitHub page for Rust and WebAssembly with a tutorial called Game of Life, which I followed like for the first quarter. I used wasm-pack to generate my WebAssembly package from Rust, which is really awesome. It reloads your web page if you change your code and run wasm-pack and it worked great, and very fast as well. Then the favourite part of my Rust experience, the console error panic codes, it's just two lines and it tests an error panic hook so it can see errors directly in the web page console so if anything fails you can actually see a message: it failed on this line. A really good error message. That was like the first time I was really happy to see an error message. Also, I talked with some friends who used C# and WebAssembly and they don't have it. So if anything fails, they just see nothing. The debugging with WebAssembly isn't that great yet. They are going to improve it, but it's quite awful. So those things, a life saver. So the frontend. My two last hiccups are here. You can see here the Ugly guy from the movie. For me, my experience like with WebAssembly was: who the hell is that? One bastard goes in and another one comes out. I started to use multi-threading with WebAssembly and Rust. I tried it on a normal Rust application to run in the console and it worked fine. It was fairly easy, I would say, and then I used it in my WebAssembly project and it said: awesome, we build it, smiley face. Everything is great. Then I looked at my web page, refreshed it and there was this error message. It cannot actually find multi-threading because it's not actually packed to the WebAssembly package. It cannot find the module. So that didn't work. Then I had to use for my little project like the system called time. I thought that has to work. So I called the time from Rust, packed it. Everything was built perfectly with wasm-pack, and then it failed again. It also hasn't yet [inaudible]. So these nice things with Rust that I just can't use with WebAssembly - one after another. So how can you still use the time that is obviously needed? You can actually define it in JavaScript. You can see here on the bottom. Just have a function like get current time in milliseconds. Then in the Rust part you can say: hey, in that JavaScript file this method exists, and then just call it in Rust like any other function. Beside this call and the manipulation, that's the only thing I had too it with JavaScript, which I really enjoyed. All the other functionality I could write in Rust and then call it from JavaScript. So that's like the first draft of my application. It worked but it wasn't pretty. I wanted to make it nice as well. So I had at the moment one huge Rust file, with all my functionality in it and I wanted to split it up, like have a folder universe with my whole universe from the application and the library and structs and traits, so I had to use mod and use and crate to split up my modules. That was quite hard. It was harder than I expected. Also I looked on Stack Overflow to see some examples of how it could be done. It didn't work. Later on I heard that in 2018 it actually changed, so there are still a lot of examples that will not work, so I used more hours than I wanted to say to make this happen. Then, as I said, I used structs and traits which I really enjoyed to have the inheritance that I'm used to. Also, I used a lot of generics, just to make it possible to have a functionality just written once. That was something I missed, something like nested structs. I wanted to make inherent runs struct into another, like you see in the example on the right. I hope to find something like that. But there's nothing possible to do it this way. Maybe it has something to do with the ownership that Rust isn't able to do it. I don't know. So I did it as you can see on the left example. I just have a struct, I call it here Part, that my other two structs use the fields from. Like count is used in Apartments and Roads. But I wanted to have it flat. But still in the end I could accomplish what I wanted. So then this happened. You remember my emotional chart? The last point, where I really hit rock bottom with the JavaScript? That was this. I was like suddenly seeing a lot of red lines, like: I'm your friend, please don't die, please don't die. And it did. So what happened? It couldn't find my WebAssembly module. It's like the one called city_inc_next and I tried to clean it, to do everything possible that I knew about, but I couldn't make it work again so I used git through my little project and just thought: let's just go back and see if it works there and what did I change to break it actually. Then I realised this one. When I started my WebAssembly project I used this comment to have wasm-pack-template which was pretty neat. It had a lot of things in it before but what it actually does, it clones this template into your www� folder so now you have a git repository in there, and if you do not delete that .git folder, that git directory, and you just work on your route and naively just write git add all, git commit, and don't look at the files, you will not really realised that you haven't committed anything from your JavaScript part, so I had no history at all. I didn't know what went wrong. So I had to start again. I created a new project and copied one file after another to see where did I fail, what did I do wrong, and I actually copied everything and it worked. So if anyone knows what could happen here and what went wrong, or anyone had the same problem, please come afterwards to me and tell me what I did wrong. And delete the git directory. So that's almost to the end. What were my key takeaways? I actually do recommend Rust. I love to - like, the whole language part of Rust, I really loved it, and I prefer it to C++, like way a lot. I do want to learn more, learn more about the whole memory concept, the ownership and the borrowing, and I do think it's quite a steep learning curve. A month, 66 hours, I don't think it's enough. I can now write some code in Rust, but I wouldn't say I'm like a Rust programmer. Yes. Thank you. [Applause] I think we have time for questions.

I'm going myself through a learning process. Here. Recently I have hit some points where the documentation was either confusing or could have been better, and in some places I just got stuck because I couldn't go any further, so what was in your case one or two places where the documentation and maybe something that could have been done better to get you over the hump of understanding some concept or issue, maybe some error or something? CLAUDIA: Hmm, I think more examples, just more coding examples, not just a hello world would help. Also in the Stack Overflow. Maybe some people can write a version for us. Just as an addition, you said you didn't look into macros. That was something that I hit recently, and just as a comment, if somebody is going to do this, give an example of a macro which doesn't have a variable number of parameters. That would be very good. CLAUDIA: [Laughing]. Any other questions? Not? Okay, thanks, Claudia. CLAUDIA: Thank you very much. [Applause]