Live data from Hacker News

Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

github.com

121–130 of 170 posts

Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

#122

>100% Rust - No unsafe code blocks It uses an unsafe code block. https://github.com/jedisct1/yes-rs/blob/main/src/main.rs#L12... It also appears to log other stuff than y. The uutils rewrite of yes into rust doesn't use unsafe and is much simpler. https://github.com/uutils/coreutils/blob/main/src/uu/yes/src...

[deleted]

Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

#123

Earlier quoted context omitted.

It's written using unsafe Rust which means that the compiler will not be able to verify that it is safe. It's not guaranteed to be safe just because it is written in Rust. Please understand this, the author of this repo is spreading incorrect information.

The difference between a zealot and an evangelist is the ability to understand when someone is making a joke. I’ll let you figure out how you’re coming across here on your own as a growth exercise.

I cannot tell if parent is making a joke, or is dead serious. They won.

Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

#124
post #2

Lines of Code yes (GNU) 50 Yes-rs 1,302 (26x more) The cost benefit analysis on this will be interesting given this is 26X more code to manage, and could also introduce a whole new toolchain to build base.

If you are looking for a non-joke implementation[0]. Excluding the test code at the bottom, the Rust version is a bit less than 120 lines. [0] https://github.com/uutils/coreutils/blob/main/src/uu/yes/src...

What do you mean non-joke? How can you tell? How is this a joke, and how is that not a joke?! What makes the distinction?

Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

#125

Earlier quoted context omitted.

GNU core utils is 134 lines of code, not 50, so the Rust version is even slightly shorter. You can make yes a lot shorter in both C and Rust, but this size goes into speed. For reference, OpenBSD's yes is just 17 lines of code[2]. It essentially boils down to this: int main(int argc, char *argv[]) { if (pledge("stdio", NULL) == -1) err(1, "pledge"); if (argc > 1) for (;;) puts(argv[1]); else for (;;) puts("y"); } Thi…

The OpenBSD version of true is also amazing: https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/usr... The GNU version of true/false is more interesting. All the logic is in true and false just redefined the EXIT_STATUS and imports all of true.c. https://github.com/coreutils/coreutils/blob/master/src/false...

For reference, here is true.c: https://github.com/coreutils/coreutils/blob/master/src/true.....

Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

#126
post #115

Earlier quoted context omitted.

GNU core utils is 134 lines of code, not 50, so the Rust version is even slightly shorter. You can make yes a lot shorter in both C and Rust, but this size goes into speed. For reference, OpenBSD's yes is just 17 lines of code[2]. It essentially boils down to this: int main(int argc, char *argv[]) { if (pledge("stdio", NULL) == -1) err(1, "pledge"); if (argc > 1) for (;;) puts(argv[1]); else for (;;) puts("y"); } Thi…

> This is as simple as it gets It unnecessarily duplicates the for loop. I would have written something like: char *what = argc > 1 ? argv[1] : "y"; for (;;) puts(what);

What a waste of 8 bytes! :)

Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

#127
post #115

Earlier quoted context omitted.

> This is as simple as it gets It unnecessarily duplicates the for loop. I would have written something like: char *what = argc > 1 ? argv[1] : "y"; for (;;) puts(what);

What a waste of 8 bytes! :)

It’s not about bytes, it’s about duplicating logic that should inherently be the same. If you change something about the loop or the puts, you now have to take care to change it identically in two places to be consistent. That’s a situation that should be avoided, and is what makes it not “as simple as it gets”.

Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

#128

Earlier quoted context omitted.

If you are looking for a non-joke implementation[0]. Excluding the test code at the bottom, the Rust version is a bit less than 120 lines. [0] https://github.com/uutils/coreutils/blob/main/src/uu/yes/src...

What do you mean non-joke? How can you tell? How is this a joke, and how is that not a joke?! What makes the distinction?

Have you looked at the source code? It’s obvious.

Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

#129

Earlier quoted context omitted.

so bad joke then??? good joke must be funny

Whether a joke is funny to a given person is context dependent. “A dog walks into a bar and says, ‘I cannot see a thing. I’ll open this one.’” Is this a good joke? Do you find it funny? If not, do you happen to be a Summerian circa 1983 BCE?

Good reference, but I think the context is needed for the joke to make sense in the first place, whather it's funny or not comes later.

Further reading: https://www.reddit.com/r/AskHistorians/comments/tbgetc/comme...

Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

#130
post #84

Earlier quoted context omitted.

Which implies you get pretty much 3M syscall per second. Which is a good order magnitude to know

I don't believe puts is performing unbuffered I/O though. It's a libc function, not a direct syscall. Correct me if I'm wrong of course

The write(2) libc function is just a C wrapper for the syscall. It's the functions from stdio.h that are buffered.
Post reply on HN