4 ms·
For anyone unfamiliar how rust helps, the idea is this: first, you can identify common usage patterns and build safe wrappers around raw system operations. The
by nercury 3y ago
For anyone unfamiliar how rust helps, the idea is this: first, you can identify common usage patterns and build safe wrappers around raw system operations.
The wrappers have no additional cost when compiled: A nested structure of Wrapper<OtherWrapper<OverSomePointer>> has a size of the flattened contained data, all the type info will be stripped away.
This part is the hardest, but the reward is that you can then use these wrappers without thinking about lower-level details. Of course, it is possible to do that in other languages, but rust type system can encode more information in types. That means more checks at compile time and less cautionary instructions are needed in the code comments.
I always hear arguments that "Rust still does not prevent X!". That's not the point. Rust type system simply can prevent more if used as intended.
- Ygg2 3y ago> I always hear arguments that "Rust still does not prevent X!". That's not the point. Rust type system simply can prevent more if used as intended. That's just the Nirvana fallacy. Just because it's not perfect shouldn't prevent you from improving stasus quo. Absurd example: "Seatbelts don't prevent impalements or drowning in car, ergo they are useless.
- stefs 3y agothe seatbelt example isn't a 100% fit as seatbelt-opposers argued that seatbelts actually increase the risk of drowning, so they're not a security improvement but a trade-off. of course, cases of drowning in an automobile where the passengers would have survived without a seatbelt are incredibly rare, while all other accidents where seatbelts help are comparably common.
- pjmlp 3y agoThe book unsafe at any speed, is a good background on the resistance regarding security improvements in the car industry.
- dralley 3y agoI have doubts that would even be true. I'll gladly take a struggle to remove the seatbelt over receiving a head trauma immediately prior needing to escape the car and swim to safety.
- Ygg2 3y agoFirst, the biggest problem for drowning in a car isn't seatbelts but windows. People will remember to unhook the seatbelts, and by that time it will be too late to open windows. In essence, you're arguing for the removal of windows, not seatbelts. Second, the nirvana fallacy is comparing actual things to unrealistic, idealized alternatives. You're comparing actual (seat belts) to an idealized alterative (something that prevents all car crashes, no matter the cause). Third, it's a less generalized example. Stuff seatbelts don't protect and might even lessen chances of survival - rockets, gunfire, rhinoceros, trains, meteors, nuclear blasts, black holes, multiversal collapse.
- stefs 3y agothe argument that seatbelts cause drowning wasn't mine personally but one an original advocate against seatbelts brought. shortly after the guy died in a car accident. i don't even back out of the garage without my seatbelt on. could have been this one: https://www.snopes.com/fact-check/seat-belt-advocate-killed/ https://www.snopes.com/fact-check/seat-belt-advocate-killed/
- Brian_K_White 3y agoSomething can be more then useless yet still be less than worth it. Not saying rust isn't worth it in this case, just that the extremes are not the only two conditions.
- Ygg2 3y agoSure, a Nirvana fallacy depends on the alternative being some idealized, unreachable state. In the Rust case, the alterative is - write better code (or everyone will use static code checkers)!
- csomar 3y agoIndeed. What I hate about C is a function that returns an integer, and go figure out the docs about what the value of this integer means. In Rust, an enum with "RequestSuccessul" usually means just that: a successful request. That means I have much less uncertainty about things and spend less time going through docs.
- msla 3y agoC has enums, too, you know. What do Rust enums do that C enums don't?
- cesarb 3y ago> What do Rust enums do that C enums don't? In Rust, an enum can also carry data along with the tag, and the type of the data can be different for each value of the tag. A Rust enum is more like a "tagged union" (a struct containing both an enum as the tag and a union for the extra data) in C.
- rgoulter 3y agoRust's enums are "sum types" or "tagged unions". Perhaps the most practical example of this is the Option type, where you can say an Optional value is either `Some(value)` or `Nothing`. With this, you don't have do deal with null pointers; a `null` pointer would instead be `Nothing`, and a non-null value would be `Some(value)`, and the compiler can enforce you're sticking to this.
- jerf 3y agoI wish "enums" would stay relatively simple numbers or something and "sum types" would remain full sum types, but, here we are. Now whenever I see someone asking for "enums" I have to ask them what they're actually saying, because the majority of the time they mean sum types, but only the majority. It is not even close to always. Sometimes people want more fully featured enumerations, too, e.g., better automatic stringification of a variety of types.
- _dain_ 3y ago
- trexrex 3y ago[flagged]
- deviantbit 3y ago[flagged]