Rust Casting, Shadowing, Consts and Static

Ғылым және технология

A mix of topics of casting, shadowing, constants and static variables inside the Rust Programming Language.
This Rust programming language tutorial series is aimed at easing your training step by step. Rust is a systems level language aimed at speed and safety and can be run cross-platform, including embedded systems and even the browser with WebAssembly (WASM)! I use the VS Code development environment to help you learn the core topics. Please join me on this journey with this fantastic new programming language.
Topics include coding basics, hello world, primitives, cargo, toml, rustup, arrays, borrowing, shadowing, string vs str, tuples, enumerations (enums), println and so much more...all free on youtube!

Пікірлер: 26

  • @dougmilford7814
    @dougmilford78144 жыл бұрын

    Thanks for clicking 'Like' and Subscribing!

  • @BonifaceMakone
    @BonifaceMakone3 жыл бұрын

    I hope you do a concurrency and multithreading video soon. As usual, your videos are so informative.

  • @wutong4524

    @wutong4524

    Жыл бұрын

    Yes please! I like this video but couldn't find a video about that on your channel as you mention at the end. :(

  • @tomglod9376
    @tomglod93764 жыл бұрын

    Learned alot from this video. Thanks..... I come from a language that lets me do the craziest stuff. But so far so good. I am loving learning rust ...... 50 years of programming experience .... turned into a language. Your videos are great Doug!

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    Glad you like them!

  • @hamol3d
    @hamol3d Жыл бұрын

    Really looking forward for the concurrency and multithreading videos. Thanks again for sharing these amazing videos. Really enjoying it.

  • @dripcaraybbx
    @dripcaraybbx7 ай бұрын

    Anyone who says developers are uncreative has never heard one emphatically describe the danger of static mutables.

  • @coderoam
    @coderoam3 жыл бұрын

    Awesome

  • @arturczajkowski4255
    @arturczajkowski42554 жыл бұрын

    Shadowing can be done even without scope. It feels a) weird b) error_prone.

  • @VivekYadav-ds8oz

    @VivekYadav-ds8oz

    3 жыл бұрын

    Weird that it is paranoid about messing with global mutables, but allows something like this which can be easily used wrongly. Especially if you use one letter variables (they're often used when implementing mathematical algorithms, so as to keep the mathematical nomenclature and programming nomenclature consistent).

  • @G11713

    @G11713

    3 жыл бұрын

    @@VivekYadav-ds8oz There is a big difference between local and global scope. The breadth of a single function should be inherently transparent while a global scope is inherent opaque for non-trivial programs.

  • @arturczajkowski4255

    @arturczajkowski4255

    2 жыл бұрын

    @@jonathanmoore5619 This is absolutely not correct and very misleading. Please do check before you post. No deallocation is made at the point of second binding.

  • @arturczajkowski4255

    @arturczajkowski4255

    2 жыл бұрын

    @Jonathan Moore ibb.co/Nj1QVm0, No it is not simply matter of compiling or not. Especially that in your previous post you've stated that there is deallocation happening.

  • @yurikolovsky
    @yurikolovsky2 жыл бұрын

    What's the difference between an immutable static variable and a constant?

  • @hansisbrucker813
    @hansisbrucker8133 жыл бұрын

    So non-mutable static variables are a bit like readonly variables in C# 😊

  • @konstantinrebrov675
    @konstantinrebrov6754 жыл бұрын

    Can't you just put locks or guards around all accesses to the static global variable in a multi theraded program?

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    Hey, great question! I'll be dealing with that topic when I do the concurrency video. Simply locking multiple static global variables has it's own issues, just like in other languages. Specifically, sync lock is still an issue. You can lock up the entire program when two threads tie up resources the other needs. Also, race conditions are still rampant in that situation. Spitting up global state behind multiple locks is still treating your data like global mutable state. Multi-threading is such that it seems like things are working ok until one day... BOOM, an issue occurs at the worst possible time. If you're careful and structure your code in a certain way, you can bypass both issues. One possible solution is to have a single global static variable, but obviously locking that every time you need to read or write really diminishes or eliminates the value of multi-threaded programming. But Rust has some fantastic mechanisms to do multi-threaded programming. Hopefully I can get to that topic sooner rather than later, because it's an important one. One particular pattern I've fallen in love with (in programming in general, not just Rust) comes from functional programming with immutable data and leveraging the Redux pattern for updating your data. But that's not the only way. Hopefully that answers your question. This is an extremely important topic in Rust and I hope to get to pretty soon.

  • @dheerajJha03
    @dheerajJha033 жыл бұрын

    The scope is not required for Shadowing as per standards. doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing

  • @michalbotor
    @michalbotor Жыл бұрын

    i would have been fine with ``` fn main() { let x = 1; println!("{}", x); { let x = 2; println!("{}", x); } println!("{}", x); } >>> 1 >>> 2 >>> 1 ``` but why this?! why?! ``` fn main() { let x = 1; println!("{}", x); let x = 2; println!("{}", x); } >>> 1 >>> 2 ``` variable x is supposed to be immutable, and yet i've mutated it.

  • @gosnooky
    @gosnooky4 жыл бұрын

    This is the most frustrating language I've ever tried to learn. It's the Australia of programming languages -- tons of rules to protect you from yourself. Live dangerously... stick with C++, it's worked well for me for the last 25 years, and it will continue to do so. Screw Rust.

  • @yuribudilov5638

    @yuribudilov5638

    4 жыл бұрын

    Well, I can say the very same thing about C++. The modern C++ is the largest and most complex main-stream programming language ever invented and is still growing in complexity. Using C++ is the main reason why Microsoft spends ~$150K per bug to fix each and every security/memory flaw in Windows - so it's many millions each year. Some ~70% of all bugs in Windows C++ code would not be possible in Rust - at *compile time*. There is an official Microsoft blog post about it. The main thing that keeps C++ still alive today is the vast installed code base and ecosystem (30+ years of development). Sure, as you said, C++ works, but, no, you would not choose to use it if you did not have to. If you want to learn how to program in Rust while still trying to adhere to C/C++ rules then you are destined to fail. You need to get rid of the "baggage" of C++ to be able to learn Rust. I am coming from C and Java and Python, which all have baggage that needs to be "dumped" to learn Rust. Now, I would hate to program in any language other than Rust (and perhaps Kotlin/JVM too).

  • @wiktorwektor123

    @wiktorwektor123

    4 жыл бұрын

    @@yuribudilov5638 I couldn't say it better. 1 month before I started learning Rust after knowing C++. For the first week I hated Rust compiler. It behaved like grammar teacher that will fail your exam if you make one simple mistake (ie. forgeting dot at the end of sentence). Now I can't imagine going back to C++ or any other language. I think it's called Stocholm Syndrome ;-D Edit: I found blog post you mentioned: msrc-blog.microsoft.com/2019/07/22/why-rust-for-safe-systems-programming/

  • @torb-no

    @torb-no

    3 жыл бұрын

    If you're in a situation where you don't need the safety features of Rust then C++ is certainly reasonable to use. However if you're doing something where memory safety og data races could be a problem then I think Rust is probably a better option. Personally I like Rust because I find it more ergonomic in some areas and I'm okay with having to be careful in the way Rust requires, but I realize that this might not be correct for every project.

Келесі