Scott Lee, who joins to talk about Rust Language, is CEO of Elega Corporation, Senior Salesforce Developer, Game Builder, and PluralSight Author.
Main Points
- How did Scott start learning Rust
- Why is Rust fast
- How to learn Rust
- Is Rust a OO language
- Can Rust do things high-level languages do
- Expand knowledge and learn new languages
Links
- Scott’s LinkedIn
- Scott’s Twitter
- Scott’s company site
- Scott’s PluralSight Author Profile
- Scott’s Steam Game – Kalling Kingdom
Video Teaser
Contact Me
If you enjoy this podcast, please reach me out to let me know your thoughts or simply say Hello. My (Xi’s) contact info:
Take care, until next time :)!
Transcript
AI-generated, unedited.
[00:06] Hi, this is a continuation from the last episode.
[00:12] I
[00:17] know you started to learn a new language called Rust. We talked a little bit about it at the beginning, so you learned Python, which was a new language for you, and then you again learned this Rust, a new language. So, what made you to to learn another second language? Yeah. So Rust came about because of a number of the things I just talked about. It was like understanding, okay, the machine is capable of being a lot faster. It's capable of being very efficient. And throughout
[00:55] using Python, there were times when I encountered performance problems. So in the standard Python runtime. And this also probably applies to a great extent on other things like Node.js or Java. Java is probably quite a bit faster in a number of cases than Python would be. But all the same, you will encounter times when if you're trying to do something with very large data volumes. Or you're just doing something that's very demanding. You may discover that the traditional way in which you're writing code, and the the speed at which that language is executing your instructions with its regular, its regular runtime, it may be too slow. There was another point at which I said when I discovered how fast C was, I said. Why aren't we writing this stuff in C plus plus? You know, like so. By the way, the the scenario that I'm talking about is like, imagine it's the energy industry, and imagine you have. Hundreds of thousands of customers, and you need to get numbers off of of these meters for measuring energy production, and you need to do that every fifteen minutes for hundreds of thousands of customers. It's a ton of data, right? Yeah. And so, I ran into some big challenges trying to apply Python to that type of problem, and unfortunately, there was no one. More experienced at the time, who came along and hit me over the head and said, "What are you doing?" You know, so so so. What I had to do
[02:25] is I had to figure out how how do I make Python work for this problem. So anyway, so I I asked them, "Why don't we use something like C plus plus?" and The response I got from one of the lead developers was just like, "You trust me? You don't want to use C plus plus? C plus plus is how, you blow your leg off. It's it's so dangerous. And and yeah, it may be fast, but." You will not have any of the things you're used to. You know, you will not have package management, which Rust would give you. You will not have memory safety, which Rust does give you. You know, and so at the time, I was understanding that okay, there are these trade-offs we can make with memory safety versus performance. So, that eventually led me to Rust because the question was: Is how can I get better performance with memory safety guarantees? How do I counter the challenges that were raised a number of years ago? Now by that lead developer I spoke with. And, and what is something that companies and businesses would be willing to adopt, given the fact that so many of them who have been around for a while had such nightmare memories of working with C and C plus plus back in say the nineteen nineties when some of these really troublesome, really obscure sort of memory safety bugs may have existed. So
[03:56] that what Rust does is it tackles the problem a different way. It still compiles the way that C and C plus plus do. It compiles to native machine code. It has package management through something called Cargo, which is very similar to npm or pip, or in our case with DX packages, right? So it has package management, which makes dependency management very, very nice. Was the overall like? Yeah, so you mentioned the C plus plus and the C. I remember, the difficulties those like a star points, right? In the C languages, I I don't remember anymore. It's like you have you can even use like two stars in front of the variables. I don't really remember, but I I do remember is that maybe seventy percent of the the bugs I introduce are really coming from those memory. Jumping memory allocations, so I have to really strictly control how I assign the memories to to my programs, and yeah, as a lazy Apex developer nowadays, I only need to care about the logic, how I make sure the business logic is is fulfilled. So life is so much easier. But again, as you mentioned, you you kind of do the trade off with the speed. So the languages it can be only this fast. If you really want to be really low latency, then you have to go with the low level programming languages, like
[05:26] you said, the C plus plus or Rust. Yeah, it really depends on what you're after. With me, and it depends. I would say it depends a little bit on your philosophy. So, if your philosophy is like mine, and you say, "Well, you know, within within reason," within reason being a relative term. We should try to get the best performance possible at all times, and I used to have conversations with different folks about this idea of pragmatism versus purism. Right? If you're a purist, you want to go for perfection. Yeah. And there's folks who used to call me a purist. But really, I think at the end of the day, for me, I just lean toward purism a little bit more than than some might. Apex can be very, very frustrating because.
[06:21] If something is already optimized the way that Salesforce tells you to do it, you don't have a lot of options at that point. You, you know, there's a lot of there's also a lot we can't see with the Apex implementation. Yeah. So if we talk to Salesforce, and I've had a few. Brief exchanges with folks like Chris Peterson or Daniel Ballinger on over Twitter. Who are the Chris Peterson is the the product manager for language services at Salesforce, and then Daniel Ballinger is the Apex product manager currently at the time of recording this. And I've had a few interchanges with them about you know can we can we do anything about this you know can we for for how long it takes us to run these tests these Apex tests. Could you give us the ability to run them in parallel when we deploy to production, or I'll show a performance comparison of Apex doing something versus Rust, and Rust is in some cases doing arithmetic thousands of times faster, and that's that's the literal math if you calculate, and they can give you hints about. How certain things work, but ultimately the answer is usually there's only so much we can do currently. There's only so much you can do to adjust it. Yeah, you may need to go to Salesforce functions. You may need to write this in Java. You may need to go off platform. Whatever the case, and and if
[07:51] you then discover that there are things that need to happen that need to be even faster than Java. What do you do now? You know how many of these use cases are you realistically going to come across? I think for many of us, we won't really find a lot of use cases where these are enormous problems. These things are not beyond the realm in a lot of instances for what is acceptable to users. Yeah. But I would also kind of argue that part of the reason for that is because. A lot of software we use today is excessively slow compared to what it could be. If you compare the Lightning Experience performance to the performance of Classic. the The pages in classic might be kind of ugly, but they load very very fast. Indeed, by by comparison, yes. So there's a lot of questions around when do you really need the performance, and that is for. A combination of the users and for the developers to answer, I think. But for me, the way I look at it is: is if the user could get this five thousand times faster, they deserve to have it five thousand times faster. If if that's possible, if that's reasonable. Hmm. Yeah, you you mentioned that as a Apex developer, there is not too much we can do because it's a closed source the project, right? It's a commercial product, so we can talk
[09:21] with them. We can ask some hints. But yeah, I think that's the reason you go outside of Salesforce and you studied the Rust, you studied Python. You can really dig into the things if you really want to, and then you can ask those open source communities. How is the community in Rust? How is the ecosystem over there? I have not interacted a whole lot with the Rust community, but my impression is is that it's really really nice. I spend a bit time to check. I go to the internet to search Rust land. And then I definitely found a playground for us. You don't need to install anything in the browser. You type the language "Hello World," and then it sends back to the server, compile, and then send back to you. You know, yeah, that's a good experience. And there are free books from the community, like teaching you how to do the language. There are free courses there. And and even people recommend you like what's your programming level, and then according to that, you can go to these these these open source projects. You can study their code if that that's what you prefer to. So no matter how lazy you are, as long as you put time, all the resources surround you. You know, you just need to pick the fruits that you want, and then that's right on that. That's right. No excuses. Yeah, it's so convenient nowadays.
[10:51] Yeah, so it's very good, and you know, I I'm still. I don't even know if I would be considered an intermediate person. I probably would, I guess, based on probably just things I bring over from my experience in other areas. But I still have a lot to learn in Rust as well. There's advanced areas of optimization that I I still haven't gotten into. It's also possible to go and write. Quote unquote, sort of unsafe code in Rust. If you need to, for some reason, so if you need to, for example, dereference raw pointers, the asterisk bit in C or C plus plus. If you need to go and do that for some reason to make something even faster, Rust allows you to to go and do that. And okay, I've written lots of Rust code now. I've written probably. At least eight thousand lines at this point with my experience writing Rust, and I've never had to write a block of unsafe Rust code to do something like that yet, because. What's my comparison? My comparison is normally to something like Python or Apex, and Rust is. I just compile it, and it's automatically so much faster. Normally, so I I get wild, you know, ten to thirty x plus performance gains in a lot of cases. I. I don't. I don't even have to do that trade-off to to to get those those gains.
[12:22] So it's been very good. Is Rust? Uh, we haven't even talked about it. Like, is Rust like object-oriented or functional programming language? It has, it has the ability to kind of do both. It borrows a, it it does borrow a lot from ideas in C plus plus, so. You can write, yeah. I mean, your your objects would probably be structs as opposed to classes. Similar to so that's that's something in C as well, right? C you'll you'll write structs, but you can do a lot of the same things. You can attach behavior to those and all those kinds of things. But you know, with object oriented programming, I. Always caution in general to use certain ideas from object oriented programming sparingly, especially inheritance. Inheritance is probably, on a performance basis, what you would pay the most for, and how much does inheritance inheritance help us? It might help us in some cases with readability and maintainability, but for what you pay in performance, is it actually worth it? And is it necessarily that much more understandable in certain cases? I mean, I've I've seen inheritance abused. Yeah, yeah. I've seen you know abstractions of abstractions of abstractions of abstractions. It gets to a point where you can't hold the program
[13:52] in your mind, and you don't know what's going on. And a problem happens, and you don't know where it's coming from. So. I've definitely had I've had cases like that with Rust. Like when you write Rust, and this is you know this is of course true in any low low level language or lower level language. You you will think a lot more about what the machine is doing with Rust. You'll and this is how I kind of tackle a lot of things as I am writing it. I try to actually visualize in my mind. What is happening with the memory when I write the syntax? Okay, and in Apex, you won't think about that. No, you're you're thinking in terms of S objects, and you're thinking in terms of fields. You're thinking about maybe some database operation. You're not really thinking about memory. No, but the truth is, is that memory is this giant thing that is going on at all times. And so in Rust, I think a lot about, okay, you know, if I create a list, how much memory is that taking up, right? What is the what's the real size? If I imagine little boxes of memory with bytes going into them. How many how many little boxes are there? How many bytes are there? And and I think about that a lot more in Rust than I would in Apex for sure. I know Rust is the low level system programming language. If you want, you can really talk with the bare metals in your machine, right? But
[15:23] how about the higher level things? Can I also use it to create websites? Do do some high level programming language usually do? Well, that's the wonderful thing, in my opinion, about all lower-level languages. You can use them to create deep things like embedded systems or operating systems, or like Firefox, the web browser. Right? You can use them to make you can you can make very very demanding applications with those things that run against bare metal. And you can also use them for other things too. If you can build an operating system with a language, then yeah, you can definitely use it for web development and all the things that you're. Perhaps more used to if you if you've only worked with higher level languages, right? So
[16:08] yeah, you can definitely do that. I think a lot of I think a big question in a lot of folks' minds is, okay, yes, I imagine I could do that. Will it be as easy or as convenient? That's exactly my next question, and and that's key. And the answer, honestly, is it will probably be a little less convenient. However, what do you get in exchange? Well, in exchange. You'll get something that's probably a lot faster if you've if you've done it correctly, right? So, yeah, it's a trade off. Is it true that you'll you'll you'll spend probably less development time with throwing together a website with Python? And I and I have thrown together websites with Python. I. Like Flask, the Flask framework. It's a great framework. It basically allows you to just set up endpoints. If you wanted to, you could build a REST API with it, and you can basically just say, "Hey, if you go to this endpoint with this type of HTTP request, then I want to do these things." And you just define it, and it's nice because if you're not If you're not thinking about all these little things like like the little memory boxes I was talking about, then you can you can very rapidly just worry about as you said, sort of just the the business logic, just what is my logic and what do I want to get done, and it's elegant and it's beautiful and it it's fast to to type out. And
[17:38] you can get something up very quickly. The trade-off with Rust is you will be you'll be doing those same things, but with a little bit of an additional layer of okay, what is happening in memory? What in which ways am I working with memory, and how am I referencing things in memory? You'll think a little bit more about that, and it will take a little bit long. I mean, especially. You know, there's a learning curve that comes with Rust, and that's—I would say—that's probably one of the primary obstacles. Is that there is this friction that happens because it's giving you the powers of that memory management and that high performance. And in exchange for that, there's this friction that happens where you need to learn how to work with how Rust provides those guarantees with the borrow checker, and so there is a learning curve with that. Once you're past that learning curve, I would say it's still going to take you a little bit longer than it would with something like Python. But at the end, how much faster will it be? Well, it could be a lot faster. But you do have to keep in mind, right? I'm not I'm not making any promises here about architecture. Architecture is still important. All the fundamental things that you're used to worrying about, those are still important. Yeah. Some of the lessons you may have learned in Apex with bulkification. Some of those things do carry over, right? As they would to other languages as well. So yeah, you you do have to be realistic about what exactly are the trade offs. Thanks, Scott. I think we had a lot of
[19:08] content in this session. We started like we worried about our careers as Salesforce developers. Last time we talked over a year ago, when the pandemic just started, and now it's lasted such a long time, and the world totally changed. And then now we're thinking about five years later. We don't really know if Salesforce still this hot in the market. That's definitely the big question. And for our developers, for our Salesforce architects, I just want our listeners to understand that if you spend your time to really follow your passion, you learn to expand your knowledge on some other areas, other topics. Then, the day when the day really came. You can easily find another job. I think that's what I want to maybe you want to share with us, right? You have such a knowledge on all these different topics. You can be again developer in the future. You can be like a professional author, like professional author. Yeah. So you're confident that you can easily get another job. I think that's important. Well, yes. Again, with all the time I've had to to prepare and to do all things, yes. I think it's definitely increasingly important for Salesforce developers, in particular, to you know, it doesn't have to be Rust. I love Rust, but it doesn't have to be Rust. But I think it is a very good idea to go learn at least one
[20:38] other language outside of outside of the even if it's JavaScript, because the JavaScript you know on the Salesforce front end. Is not exactly the JavaScript that other web developers outside of Salesforce are used to. I know Salesforce kind of claims it is, but the fact is there's a lot of Salesforce specific things there. You know a lot of security things, strict mode, using having to use React or Angular as a static resource, all those kinds of things. It can be worthwhile to step outside of the Salesforce box and learn how would this be done if we're just running it on a server, if we're just going to a computer somewhere and we want to start from scratch. Learn those fundamentals because that will serve you so well once you know if for whatever reason. The trivia of Salesforce ends up being not as useful. Yeah. So appreciate that. That's also one of our goals on this podcast. It's not just about Salesforce. We definitely want to be a good software engineer. Thanks. Talk to you next time. Then, bye bye.