4 ms·
Some things are a lot simpler in Rust. For example, adding dependencies. And this one thing makes a lot of practical tasks simpler too, because there is a whol
by nicoburns 7y ago
Some things are a lot simpler in Rust.
For example, adding dependencies. And this one thing makes a lot of practical tasks simpler too, because there is a whole swathe of code you simply don't need to implement at all.
What's simpler: Implementing a HashMap in C, or `use std::collections::HashMap`? If you really need to understand what's going on under the hood then yes C might be simpler. But when was the last time you needed to inspect the details of your HashMap?
There are also things like C's declaration syntax, which is anything but simple. And header files (even for your own code).
- steveklabnik 7y agoOn that “use HashMap” line of thinking... http://dtrace.org/blogs/bmc/2018/09/28/the-relative-performance-of-c-and-rust/ http://dtrace.org/blogs/bmc/2018/09/28/the-relative-performa...
- aportnoy 7y agoWhat a weird article… The instruction count being about the same doesn’t make it the same program… Why isn’t he using -O3?
- throwaway17_17 7y agoIf you don’t need to understand/inspect the details of a HashMap implementation then you are not doing ‘systems programming’. The attitude that ‘someone has done it for me’ and therefore I don’t care about it is not a characteristic of ‘systems programming’. It may be simpler to just use some standard implementation of a data structure, but if that is the case, then you can get by with most of the commonly accepted language paradigms. I’m not saying everyone need to implement a unique hashing algorithm tailored to use case, but that is what systems programming is. System Programming is the custom tailoring of data conditioning to a particular set of circumstances and then taking responsibility for the benefits and consequences of that those choices that differentiates systems programming from the other broad categories of program construction. Rust is a fine language if it fits your use case, and you feel as though the purported benefits of the ‘borrow checker’ assist you in writing quality code, but if you just want a programming language that provides a large library of pre-written solutions, then the difference between language is dependent only on use case and usage requirements. Saying Rust is simpler than C because you can use a pre-written HashMap implementation is ridiculous, because you can do the same thing in C (I mean use someone else’s HashMap). But if ‘systems programming’ is the area of interest, being able to inspect/implement the actual HashMap is a key concern, and just dismissing that aspect is not an acceptable proposition.
- echelon 7y ago> If you don’t need to understand/inspect the details of a HashMap implementation then you are not doing ‘systems programming’. The attitude that ‘someone has done it for me’ and therefore I don’t care about it is not a characteristic of ‘systems programming’. Don't gatekeep. Rolling your own containers has no bearing on whether or not the language is a systems programming language. I'm using it to do real time audio and graphics, but I don't have the time to hand roll my own data structures because I have a demanding day job and other responsibilities. I still get to have the benefit of using a fast, modern, bare metal language. > Saying Rust is simpler than C because you can use a pre-written HashMap implementation is ridiculous No it's not. HashMap is literally there in std::collections to import and use. You don't need to find a library, know about the linker, etc. Rust makes working in this domain so much easier than C and C++. You can go from zero to productive in a reasonable amount of time.
- adev_ 7y ago> Rust makes working in this domain so much easier than C and C++ C++ has a hash map in its standard Library since 10 years. > You can go from zero to productive in a reasonable amount of time. That's definitively a very WRONG assumption. Anyone starting to use Rust, even with 10 years of C++ experience, will spend from HOURS to DAYS fighting the borrow checker. It is not "zero to productive", Rust is not easy to learn, nor productive for beginner. Is it however worth the effort ? I believe it is. Especially if you are looking for a language providing you safety first.
- echelon 7y ago> C++ has a hash map in its standard Library since 10 years. OP was talking about C, not C++/STL. > Anyone starting to use Rust, even with 10 years of C++ experience, will spend from HOURS to DAYS fighting the borrow checker. You might have learned Rust pre-1.0 or non lexical lifetimes. They've made a tremendous amount of work to improve the language and make it beginner friendly. A few weeks ago I watched one of my coworkers implement a simple toy state machine app after having just read a tutorial. The compiler literally hand holds you now. The meme that Rust is hard needs to die.
- DeathArrow 7y agoIt's far easier to use Dictionary in C# than HashMap in Rust. However we aren't comparing languages here but standard libraries. If we introduce modules in C instead of header files and add some simple data structures and algorithms to stdlib, I can see C being simpler. C++ has data structures in its standard library and will have modules starting with C++20.
- drran 7y agoRust HashMap[0] is much simpler to use than C# Dictionary[1]: Rust: let mut map = HashMap::new(); map.insert("foo", "bar"); println!("Value: {}", map.get("baz").unwrap_or("<none>")); C# Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("foo", "bar"); try { Console.WriteLine("Value: {0}", dict["baz"]); } catch (KeyNotFoundException) { Console.WriteLine("Value: <none>."); } [0]: https://doc.rust-lang.org/rust-by-example/std/hash.html https://doc.rust-lang.org/rust-by-example/std/hash.html [1]: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.collectio...
- pjmlp 7y agoI fail to see what Rust wins in the given example, when the C# code is written properly: var dict = new Dictionary<string, string> { ["foo"] = "bar" }; Console.WriteLine($"Value: {dict.GetValueOrDefault("baz", " <none>.")}"); Better look for another example.
- nicoburns 7y agoI'm with you on this one. The Rust and C# API's are more or less equivalent. That does still repudiate the grandparent's assertion that it's easier the use C#'s dictionary.
- deleted 7y ago[deleted]
- calaphos 7y ago