I do like that this forces me to think carefully every time I allocate something, about whether or not what I’m working with should be mutable, or if I could get away with immutability. so "intVar" will act like a traditional variable. The "mut" keyword means we're "opting in" to mutability here, This is an integer without the "mut" keyword, and therefore For instance, in Go, you have to use either the keyword var, or const accordingly: However, you typically have to explicitly declare it this way. This is offered typically because the underlying implementation for constants is simpler and less expensive, so if you know a certain value isn’t going to change once you set it, choosing to declare it as a constant is the better option. In Go, and many other languages, you typically have the ability to define variables, or constants. This is made very evident even in fundamental concepts like defining variables. Reducing runtime uncertainty and forcing the programmer to be intentional with what they’re allocating lends itself to a more stable application. I think they did a good job of showing you a practical example that piques interest before diving into the deeper reference-style content of chapters 3+.Īs I mentioned in my previous post, what I’m liking a lot about Rust is just how much it forces you to let the compiler do all the work. I do recommend going through Chapter 1 on a real hello, world example, and the subsequent Chapter 2 which is a slightly more advanced hello world example that doesn’t dive super deep, but is a nice whirlwind tour of the basic, basic concepts in Rust. For this, a good place to start is Chapter 3 - Common Programming Concepts where I can make some comparisons to what I know. ![]() I’ll make observations about things I see and lessons I learn, as well as some comparisons to concepts I’m already familiar with. The way I’ll write this series is by going through the Rust book and basically providing commentary on it. I believe we learn best by building on what we know, so I’ll be making a lot of these comparisons for my own edification. I realize not everyone is going to Rust from Go, but that’s my perspective, and it will be impossible to keep this perspective from showing through and making comparisons between Rust and Go or Python. This will be the first in a series of posts on Rust, mostly written from this perspective. In the last post I wrote about my journey from Python to Go as my primary language, and how I am now exploring Rust.
0 Comments
Leave a Reply. |