TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Rust and Nix = easier Unix systems programming

255 点作者 kalmar大约 9 年前

13 条评论

zuzun大约 9 年前
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<p><pre><code> if let Some(child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } </code></pre> or<p><pre><code> if let Some(ForkResult::Child) = fork() { do_only_child_stuff(); } else { do_only_parent_stuff(); } </code></pre> Now, if you&#x27;re about to tell me that the examples above are totally stupid and no developer would do such a thing, then you know how I feel about the sloppy C versions. Doing a system call and not checking for error is totally stupid as well.<p>By the way, you can also write your own wrapper functions in C, that transform the return value into something like<p><pre><code> struct fork_status { enum { ERROR, PARENT, CHILD } state; int ret; }; </code></pre> Then Clang and GCC will warn you about missing switch cases.<p>That said, the libc bindings in Rust are pretty low-level and a project that offers higher-level wrappers can be very helpful, so I hope my comment doesn&#x27;t create the impression that I&#x27;m ripping on the project itself.
评论 #11495127 未加载
评论 #11497513 未加载
评论 #11495384 未加载
评论 #11495462 未加载
评论 #11495589 未加载
评论 #11498767 未加载
评论 #11497995 未加载
评论 #11497251 未加载
geocar大约 9 年前
I was very confused. I thought this had something to do with Rust and nix[1].<p>[1]: <a href="https:&#x2F;&#x2F;nixos.org&#x2F;nix&#x2F;" rel="nofollow">https:&#x2F;&#x2F;nixos.org&#x2F;nix&#x2F;</a>
评论 #11495581 未加载
评论 #11495066 未加载
评论 #11495253 未加载
评论 #11495265 未加载
评论 #11495636 未加载
评论 #11506621 未加载
subway大约 9 年前
Neat library, way too already-overloaded name.
评论 #11494813 未加载
justincormack大约 9 年前
I maintain LuaJIT syscall bindings <a href="https:&#x2F;&#x2F;github.com&#x2F;justincormack&#x2F;ljsyscall" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;justincormack&#x2F;ljsyscall</a> - they cover quite a lot, namespaces, netlink and so on. I spent quite a bit of time making them more intuitive than the raw bindings, with consistent error handling, also namespacing constants and so on. It is definitely useful to have these types of interfaces not in C.
评论 #11507900 未加载
bigger_cheese大约 9 年前
Minor nit pick but don&#x27;t you typically do something like this in C<p>pid_t childPid;<p>switch (childPid = fork()) {<p>case -1: ... &#x2F;<i>error handling </i>&#x2F;;<p>case 0: ... &#x2F;<i>Child Specific</i>&#x2F;<p>default: sleep (5); }<p>edit - seems to mangle formatting but something like that seems fairly clean.
评论 #11494942 未加载
评论 #11494773 未加载
评论 #11494717 未加载
评论 #11494807 未加载
sergiolp大约 9 年前
I can&#x27;t help but think they&#x27;re trying to fix something that isn&#x27;t broken at all.<p>Adding new abstraction layers rarely helps when doing systems programming. You (as in &quot;the developer&quot;) want to be as near to the machine as possible. C does this pretty well.<p>Perhaps I&#x27;m just getting old :-(
评论 #11494904 未加载
评论 #11496034 未加载
评论 #11495152 未加载
评论 #11497447 未加载
superobserver大约 9 年前
This gets me thinking how awesome it would be to have functional programming on *nix systems, like Haskell (specifically). At least then it might be forcibly designed to be made more useful and ultimately get more people on board. One can dream.
评论 #11497618 未加载
SixSigma大约 9 年前
In reliability theory &quot;X failed&quot; is a poor error message. What we want to know is which failure mode has been triggered.<p>The function of kill is to kill a given pid, so there are two failure modes : &quot;the pid didn&#x27;t exist&quot; or &quot;the pid didn&#x27;t die&quot;
评论 #11495557 未加载
评论 #11495599 未加载
评论 #11494821 未加载
评论 #11496658 未加载
评论 #11494847 未加载
bogomipz大约 9 年前
The term NIX is becoming a bit overloaded - we&#x27;ve got the Nix package manger which run on NixOS, Nix the Rust library all of which can run on most &#x27;Nix systems.
ZephyrP大约 9 年前
I feel there are more promising options for a name than &quot;Nix&quot;.
etrain大约 9 年前
type systems are great.
larozin大约 9 年前
We have switched to Nix as internal dependency manager for our C++ project. It is really exciting! No more &quot;after commit XXX you need to (re)build&#x2F;update YYY with ZZZ&quot;. Developers just type `nix-shell` and get sane guaranted to work environment on their local machines corresponding to git HEAD. If we need to add or patch dependency we just edit and commit nix file. And if developer need to rollback to old commit&#x2F;branch it will get old&#x2F;custom environment from cache without submodule rebuilds.
评论 #11494910 未加载
peterwwillis大约 9 年前
<i>&quot;the return value is conveying three different things all at once. [...] That’s a lot of information for one poor little pid_t—usually a 32-bit integer—to convey!&quot;</i><p>Someone never had to bit-pack their programs to save memory, disk space, or bandwidth. In fact, it&#x27;s a huge waste of memory; if you only need 3 bits, a &#x27;char&#x27; would have sufficed. Saves 24 bits!<p>Of course, we could use nibbles to make data structures where the fork return value only takes up 3 bits instead of a whole byte, but that could be considered micro-optimizing. (the compiler may do this for us anyway, though)
评论 #11499792 未加载