4 ms·
People are actually claiming that Rust is more readable than C?
by MikkoFinell 8y ago
People are actually claiming that Rust is more readable than C?
- Ericson2314 8y agoForrest vs trees..... Sigh
- littlestymaar 8y agoIt depends what you call “readable” I guess, if you think it as : “I can have a glance at this code and feel comfortable”, then obviously C is more readable than Rust, because Rust has a quite a few specific syntaxes that will feel alien to anyone not accustomed. But I'm not sure this metric is relevant. And on the other hand, if you call “readable” the ability of someone knowing the language to get on board of an existing project, understanding the control flows and feeling confident to make changes, then Rust wins easily because the type system gives you all the information you need straight in front of you. The first time I had a look at Servo[1], I was able to change what I wanted (which were quite a lot of thing: a few dozens of lines in something like 5 or 6 different files) in a few hours. And when I compiled it it worked fine. Good luck doing the same with a C project you just discovered. And I wasn't even a professional Rust programmer at that time. [1] the experimental browser engine form Mozilla
- MikkoFinell 8y agoWhich information in particular is missing from the C type system in your opinion?
- weberc2 8y agoFor better or worse, Rust has a lot more built into its type system, including semantics for type safe generics and safe memory management. This makes it harder to write a correct Rust program, but also it makes it harder to write an _incorrect_ Rust program.
- littlestymaar 8y agoThe two major important improvements Rust type system brings are : - the ownership of your object (who is in charge of free-ing it) and the lifetime of the pointers that targets this object. (the whole ownership system & the borrow-checker) - is some data-structure thread-safe. (the Send and Sync traits) With those, you can take any Rust code and play with it without having to ask existential questions. Your code will never segfault or exhibit a strange intermittent bug ones you add multi-threading. Less important but still really convenient on a daily basis: - will this function mutate the value I give it. (&mut pointers) - has this variable already been consumed, which means I should not touch it anymore (affine type)
- MikkoFinell 8y ago> the ownership of your object (who is in charge of free-ing it) and the lifetime of the pointers that targets this object. (the whole ownership system & the borrow-checker) Having to bear the cognitive burden of making the lifetime explicit in all of the code is a steep price to pay for the benefit of securing the small subset of the code that is actually complex enough to potentially cause a problem. I wouldn't mind having such a feature be optional though, so that you'd enable it for the most precarious parts, something like a safe{} block rather than unsafe{}. > will this function mutate the value I give it. (&mut pointers) We already have const. Yes I agree it's better to enable by default.
- Too 8y agoDoes rust have something like shared pointers? In c++ that's usually a quite easy way to bail out of the cognitive burden of understanding complex lifetimes.
- steveklabnik 8y agoWe have two! Rc is non-atomic, and therefore not threadsafe. Arc is atomic, and therefore threadsafe. The compiler can let you know if you are using Rc inappropriately, so you get some extra speed if you are single threaded.
- 8y ago
- rkangel 8y ago> then Rust wins easily because the type system gives you all the information you need straight in front of you The trait system can actually make following execution a bit harder (just like runtime polymorphism in C++), because you have to find the allocation to know the concrete type of what you're looking at. C is much clearer from this point of view (but more limited for the same reasons).
- littlestymaar 8y agoCough!, void pointer, cough! Traits are used to express generality, when you need it. If you don't need to be generic over your input, you don't need traits. And when you need it, Rust makes it more explicit than C (and also more performant because it's statically dispatched by default).