7 ms·
The thing that really ticks me off about RUST is it has compiler optimizations that can’t be turned off. In C++, you can typically turn off all optimizations, i
by perth 3y ago
The thing that really ticks me off about RUST is it has compiler optimizations that can’t be turned off. In C++, you can typically turn off all optimizations, including optimizing away unused variables, in most compilers. In RUST it’s part of the language specification that you cannot have an unused variable, which, for me kills the language for me since I like having unused variables for debug while I’m stepping through the code.
- coldtea 3y ago>which, for me kills the language for me since I like having unused variables for debug while I’m stepping through the code. If they're unused, then they're not helping with debugging either... It's quite a bizarre reason
- Buttons840 3y agoNot true. Their debugger might display the value of the variables, which are unused outside the debugger. There are other options in Rust though, like logging. Create your "unused variable", and then use it in a debug log or dbg macro, etc.
- groos 3y agov = function_call(); // inspect v in debugger but it's 'unused' to the compiler. At least this is how it works in C and C++.
- cesarb 3y ago> In RUST it’s part of the language specification that you cannot have an unused variable I believe you're confusing Rust with Go. In Rust, an unused variable is just a warning, unless you explicitly asked the compiler to turn that warning (or all warnings) into an error.
- deleted 3y ago[deleted]
- vacuity 3y agoThere isn't a Rust language specification, and you can use #![allow(dead_code)] at the root of the crate I'm not sure what you mean by "optimizing away unused variables", so I'm interpreting it as variables that are literally unused after declaration.
- fruffy 3y agoRelated: https://xkcd.com/1172/ https://xkcd.com/1172/
- dralley 3y agoThis is just wrong? You can absolutely have unused variables in Rust. It's a compiler warning, not an error. What you cannot have, is uninitialized variables which are used.
- justinpombrio 3y agoIf your development style demands uninitialized variables, you can set them to `= unimplemented!()` during development. And as someone else said, if all you want is unused variables without warnings, you can say at the top of the root of the crate (`main.rs` or `lib.rs`): #![allow(dead_code)]
- oconnor663 3y agoIt might be worth noting that unimplemented!() is a thin wrapper around panic!(), so if execution makes it to that line, your program will crash. Rust actually does allow uninitialized variables, even in safe code. But it'll be a compiler error if you try to use them in any way before initializing them, so this is mostly just a curiosity: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5ecbe6a666cfb6efd7368938cc53d0ea https://play.rust-lang.org/?version=stable&mode=debug&editio...
- IceSentry 3y agoUnused variables just generate warnings. It will still compile.