7 ms·
C complicated? It is a very small, simple language for a system programming one. C++ complicated compared to Rust? They offer roughly the same features and bot
by jfkebwjsbx 7y ago
C complicated? It is a very small, simple language for a system programming one.
C++ complicated compared to Rust? They offer roughly the same features and both are complex languages if you want to understand what is really going on.
Rust is a very good language that competes with C++. The main feature it brings to the table isn't simplicity (Rust, like C++, isn't simple at all), but the borrow checker.
Please avoid making comparisons between languages if you don't know them (as you claim).
- nicoburns 7y agoSome 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
- ancarda 7y ago>C complicated? It is a very small, simple language That's a bit misleading though. Yes, C is very small - but that doesn't mean it's magically easy to understand. It's size has a huge consequence; the language doesn't do much for you, so it's up to you to fill in the gaps, e.g. correctly manage memory
- Koshkin 7y agoC is easy, programming, hard.
- elcritch 7y agoC is easy, programming it correctly, hard.
- DeathArrow 7y agoIt might depend on what you use C for. Programming web apps and lob software in C might be tough. As would trying to program systems software in Python or Java.
- gens 7y agohttps://stackoverflow.com/questions/21177436/is-there-a-published-language-format-standard-for-rust-yet https://stackoverflow.com/questions/21177436/is-there-a-publ... 6 years ago. I was going to compare how many pages the rust standard has, and compare it to the C standard (plus 20% for the "correctly manage memory" that you pointed out as something extremely complicated). http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf Anyway.. C is a rather simple language. No matter what the opinion of rust programmers is. Please don't respond to this post. At least not with the bog standard "undefined" "unsafe/memory" and other shallow conceptions.
- bsder 7y ago> plus 20% for the "correctly manage memory" Sorry. "correctly manage memory" in C is not 20% more problematic, it's like dividing by 0, infinity% more problematic. Nobody has gotten it right. Ever. Nobody. The Mozilla team switched from C to C++ trying to get memory right. Failed. Then they tried GC. Failed. Then they tried to go back to manual. Sill failed. So they wrote their own language to solve the problem--Rust. Jury is still out, but the situation is a lot better than when Mozilla started.
- dagmx 7y agoC itself isn’t complicated. But everything around it is harder than Rust imho. Stuff like build systems, setting up dependencies, understanding memory allocation etc... Rust has its own steep learning curve but C is only really simple in terms of a language, not the experience of using the language.
- ModernMech 7y agoI teach Rust and C to college sophomores and juniors. By far the things they have the hardest time with in C are manual memory management, when to free variables, how to debug segfaults (usually called by incorrectly freeing memory), and how to correctly link code. We spend so much time on this I can't tell you. With Rust none of these things are issues and we get to actually spend time solving problems in the language instead of just understanding the language. Yes, C is as simpler language, but it's got no safety rails, and when you're a beginner at systems programming it's nice to have a friendly compiler who can help you pinpoint errors rather than to be shown "SEGMENTATION FAULT" and feel like you're on your own.
- calaphos 7y agoC++ might not be harder in theory but at least for me right now it is a lot harder to learn than rust. C++ just has so much stuff and different ways of doing things (of course, it's been in use for decades) that it I feel quite lost as a beginner on what to actually use. Also in my experiences the rust compiler errors are extremely helpful, especially compared to the c++ template stuff.
- aldanor 7y agoI'm using C++ daily at work and know Rust since it's alpha versions. C++ is miles harder to learn and write in than Rust, partially because of layers of legacy cruft in the standard, some bad decisions made that they can't undo now so they will stay forever (e.g., 50+ ways to initialise an instance, with constructors and all that, vs. Rust's lack of ctors). I still reach for reference all the time when writing in C++, but barely if at all when writing in Rust.