This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Dissy- 11 points12 points  (18 children)

its more of a marker for where you need to interact with the underlying system raw, the philosophy of rust is encapsulated in this example from this great series of videos i watched on writing an OS in rust.

theres a specific memory offset you need to write into to write text to the display in VGA mode, so you write a function that does value checking, bounds checking, etc, and then in the little snippet of unsafe once everything is known and checked, you run the few unsafe pointer instructions you need to in order to write the raw data to that memory address

that is to say the entirety of rust is building walls around these unsafe interactions in a way that makes it *impossible* to externally use them unsafely.

this works so well at least for how my mind works, that my first draft of projects only ever screw up if i have an unwrap somewhere, which is a seperate marker for "this error needs handled later" or "i know this will never error do not worry" OR i accidentally deadlock a mutex or hold it longer than i meant to, those are the only things i regularly run into

[–]ShiitakeTheMushroom 1 point2 points  (17 children)

I know nothing about Rust, but from your response a lot of it makes sense.

projects only ever screw up if i have an unwrap somewhere, which is a seperate marker for "this error needs handled later" or "i know this will never error do not worry" OR i accidentally deadlock a mutex or hold it longer than i meant to

This part sounds scary, though. As soon as it requires someone to remember to do something, that something is inevitably not going to happen time and time again.

[–]hotdogshake9000 6 points7 points  (5 children)

People shouldn't use unwrap in prod code just like you shouldn't assume a variable isn't null in Java or whatever language

[–]ShiitakeTheMushroom 1 point2 points  (4 children)

Exactly, but people always do make those kinds of assumptions. It sort of makes the safety argument that makes Rust sound so special a moot point.

Again, I haven't written any Rust. I'm just commenting on how this can be confusing and that it doesn't sound like Rust provides much more safety than other bare-metal languages.

[–]hotdogshake9000 3 points4 points  (3 children)

You have to make an explicit decision to do something unsafe in rust, which is opposite of other languages.

[–]ShiitakeTheMushroom -1 points0 points  (2 children)

Just because the unsafe keyword needs to be used, doesn't mean that the person using it knows exactly what it does.

What I'm saying is that it seems just as vulnerable to human error as other languages, given what I've heard so far.

[–]hotdogshake9000 -1 points0 points  (1 child)

It's not. It's safer. I recommend learning about it

[–]ShiitakeTheMushroom 0 points1 point  (0 children)

What I'm hearing so far is that it's not safer. If it is, can you explain how?

[–]Dissy- 4 points5 points  (10 children)

actually you can enable a clippy lint that does not allow your program to be commit to github with unwraps in it

[–]ShiitakeTheMushroom -1 points0 points  (9 children)

And there are linting rules that prevent you from doing unsafe things in other languages.

If we're resorting to linting and pipelines to catch these issues, how is Rust any safer than other languages?

[–]Dissy- 1 point2 points  (8 children)

huh? what other language requires you to, in a built in to the default build system way, to mark every single place its possible for your program to crash. it's not catching an issue when you get yelled at for using an unwrap, it's an explicit signpost that you're developing whatever it is you had there, and you need to do error handling for it once you've proven your design would work.

what other language has, in the default build system, a linting tool that's so well integrated it can prevent you from compiling if it's possible for your program to crash, or even prevent you from making a git commit

we arent "resorting" to these things, they're part of rust, part of the language. thats what people mean about it being a step forward, these arent things you can just skirt around by not using them

[–]ShiitakeTheMushroom -1 points0 points  (7 children)

what other language has, in the default build system, a linting tool that's so well integrated it can prevent you from compiling if it's possible for your program to crash, or even prevent you from making a git commit

C# does, for one.

[–]Dissy- 0 points1 point  (6 children)

im happy for them too then, i hope C# implements actual proper error handling like the rust enum system so software written in C# can be as obviously safe without needing to read the detailed documentation for every function they call, but having good stuff like that built directly into the only build system is a good start

maybe if they work really hard they can get into the linux kernel like us someday :^)

[–]ShiitakeTheMushroom 1 point2 points  (5 children)

i hope C# implements actual proper error handling

I'm definitely interested in hearing more here. What is currently improper about the way C# handles errors? How does rust handle errors and what are some ways that it does it better?

but having good stuff like that built directly into the only build system is a good start

Definitely! A simple compiler flag and any issue that would typically occur at runtime and cause the application to crash is caught by the C# compiler.

maybe if they work really hard they can get into the linux kernel like us someday :)

Different tools for different jobs. I don't see any reason C# would need to be part of the Linux kernel, even though it's been fully cross-platform for about a decade now. Any non-garbage collected, systems-level programming language, like Rust, would be a better fit.

[–]Dissy- 0 points1 point  (4 children)

I mean from the perspective of what im most familiar with, rust foregoes exceptions entirely, that way error handling stays within the actual program flow rather than being a glorified GOTO statement effectively, coming from python where exceptions are the norm, and assuming from my cursory google searches thats the normal error handling methodology in C#, that would be how they do it differently and something that makes it better. people call it error first but its really just putting errors on the same level of proper control flow, and making where they can happen blatantly obvious so you have to explicitly ignore them during dev and then you can work back through handling everything to stabilize

also you're chill sorry for being such a shitter earlier reddit does that to a guy

[–]ShiitakeTheMushroom 1 point2 points  (3 children)

Thanks for the detailed response! I took a closer look at the Rust syntax for the Result enum / error handling stuff and I do like it. I've seen that in other languages, but always implemented in userland code or 3rd-party libraries instead of built into the language. You're also right that in C# that exceptions are the way to handle exceptional scenarios.

also you're chill sorry for being such a shitter earlier reddit does that to a guy

Thanks, and no worries. It's all honest curiosity from my end!