I always find it a bit unfair when I see sloppy C programs used for shock value. What if the Rust developer uses fork().unwrap_or(default_value) in a hurry, or writes if let Some(child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } or if let Some(ForkResult::Child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } Now, if you're about to tell me that the examples above are to…
Rust and Nix = easier Unix systems programming
31–40 of 85 posts
Re: Rust and Nix = easier Unix systems programming
#32I always find it a bit unfair when I see sloppy C programs used for shock value. What if the Rust developer uses fork().unwrap_or(default_value) in a hurry, or writes if let Some(child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } or if let Some(ForkResult::Child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } Now, if you're about to tell me that the examples above are to…
Sure, you can have the same higher level API in C. Though Rust will not compile if there's no exhaustive match, and you cannot access the `int ret` if it's in the wrong state, but it's close enough.
Re: Rust and Nix = easier Unix systems programming
#33In reliability theory "X failed" is a poor error message. What we want to know is which failure mode has been triggered. The function of kill is to kill a given pid, so there are two failure modes : "the pid didn't exist" or "the pid didn't die"
thread '' panicked at 'kill failed: Sys(ESRCH)', ../src/libcore/result.rs:746
So you know that it failed because of ESRCH (no such process).Re: Rust and Nix = easier Unix systems programming
#34I was very confused. I thought this had something to do with Rust and nix[1]. [1]: https://nixos.org/nix/
Same here. I thought "A match made in heaven" But it will probably never happen, because Cargo is too good, haha
The nix package manager has (admittedly, undocumented) support for Rust / Cargo projects.
Re: Rust and Nix = easier Unix systems programming
#35I was very confused. I thought this had something to do with Rust and nix[1]. [1]: https://nixos.org/nix/
Re: Rust and Nix = easier Unix systems programming
#36I always find it a bit unfair when I see sloppy C programs used for shock value. What if the Rust developer uses fork().unwrap_or(default_value) in a hurry, or writes if let Some(child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } or if let Some(ForkResult::Child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } Now, if you're about to tell me that the examples above are to…
struct fork_status {
enum { ERROR, PARENT, CHILD } state;
int ret;
};
I think the point of tagged unions (as in OP's example) is that you cannot access `child` if the call failed. Your example does have an exhaustive check (by a compiler warning), but it doesn't prevent you from misinterpreting `ret` as a pid. Does C have a method to enforce this restriction?Re: Rust and Nix = easier Unix systems programming
#37In reliability theory "X failed" is a poor error message. What we want to know is which failure mode has been triggered. The function of kill is to kill a given pid, so there are two failure modes : "the pid didn't exist" or "the pid didn't die"
1. there are more failure modes than these (POSIX kill(2) can set 3 different errnos)
2. kill(2) signals process, it doesn't usually kill them (let alone kill them outright in such a way that this information could ever be returned)
3. kill(2) can signal process sets of cardinality > 1
4. the `unwrap` panic message will print the unwrapped value, which includes the ERRNO
Re: Rust and Nix = easier Unix systems programming
#38I was very confused. I thought this had something to do with Rust and nix[1]. [1]: https://nixos.org/nix/
Re: Rust and Nix = easier Unix systems programming
#39I can't help but think they're trying to fix something that isn't broken at all. Adding new abstraction layers rarely helps when doing systems programming. You (as in "the developer") want to be as near to the machine as possible. C does this pretty well. Perhaps I'm just getting old :-(
In this day and age with big software packages, security being an increased concern it really is high time programming languages do more to help us avoid bugs which expose us to hackers and crackers.
I do have an affinity for C, but as a Objective-C programmer currently coding in Swift, I am really seeing how many more bugs the compiler helps me uncover.
I think Rust is on the right track. It is a long overdue change to systems programming.
Re: Rust and Nix = easier Unix systems programming
#40I always find it a bit unfair when I see sloppy C programs used for shock value. What if the Rust developer uses fork().unwrap_or(default_value) in a hurry, or writes if let Some(child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } or if let Some(ForkResult::Child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } Now, if you're about to tell me that the examples above are to…
struct fork_status { enum { ERROR, PARENT, CHILD } state; int ret; }; I think the point of tagged unions (as in OP's example) is that you cannot access `child` if the call failed. Your example does have an exhaustive check (by a compiler warning), but it doesn't prevent you from misinterpreting `ret` as a pid. Does C have a method to enforce this restriction?