Live data from Hacker News

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

github.com

111–120 of 170 posts

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

#111

Earlier quoted context omitted.

>is to indicate that the compiler should be extra careful when compiling the code No, it disables some static analysis making it less careful when compiling. Please reread the chapters I linked to you because it seems like you fundamentally misunderstand what unsafe rust is. I'm happy to answer any questions you may have to clarify it.

I literally just asked ChatGPT and Claude, they both clarified to me that Rust is safe. The website for Rust even says so. If you have any questions, I would be happy to forward them to my ChatGPT Pro subscription, and then relay the answer back to you. Rust is an AI native language, it's best to start there.

Will using rust on my Intel® Core™ 13th gen cpu cause it to oxidize?

This would be terrible, I thought rust was a safe language...

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

#113

Earlier quoted context omitted.

I recommend reading through this section of the The Rust Programming Language book to learn more about the existence of Unsafe Rust which is a part of Rust and not a different language like C or C++. https://doc.rust-lang.org/book/ch20-01-unsafe-rust.html

My friend on the off chance that you truly don’t see it: they’re teasing you

I cannot tell if he's playing along or genuinely this ASD.

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

#114
With the only real tangible thing I know about rust being that the "Rust by Example" introduced a macro in the very first example, it took me waaay too long before it clicked that this might be a joke.

The WASM related annotations had me rolling my eyes a bit, yet I'd seriously read to around line 200 before I started thinking "are you kidding me"

Good on you, you got me!

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

#115

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...

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);

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

#117
Looking at the source code, this seems to be missing localization. I would have thought that Rust’s type system would catch that. For example, the Uzbek word for “no” starts with a “y”, so this will lead to insidious bugs in that locale. Not locale-safe at all.

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

#118

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…

That reddit thread has some amazing benchmarks. The GNU-yes $ yes | pv > /dev/null ... [10.2GiB/s] ... The way I (not a C programmer) would have written it void main() { while(write(1, "y\n", 2)); // 1 is stdout } $ gcc yes.c -o yes $ ./yes | pv > /dev/null ... [6.21 MiB/s] ...

If you compile your variant with -O3 I imagine it will be much faster? Iirc, the default is for GCC is to not optimise

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

#119

>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...

> The uutils rewrite of yes into rust doesn't use unsafe

Yes it does, it uses 'stdout.write_all', which ultimately uses unsafe to call libc.write

https://github.com/rust-lang/rust/blob/d76fe154029e03aeb64af...

The "unsafe" in uutils is just better hidden.

I personally like my lack-of-safety where I can see it, which is why I find it much more relaxing to drive a car when the engine is already on fire, rather than one where I can't see any visible flames.

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

#120

It is abundantly clear here who reads the source code before commenting.

...when you can't make the distinction between a joke and a serious Rust project. Is it not a joke just because the author intended it to be serious?
Post reply on HN