Live data from Hacker News

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

github.com

101–110 of 170 posts

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

#101

Earlier quoted context omitted.

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

Replace `write(..)` with `puts("y")` and you'll be an order of magnitude faster. This is due to `puts` (`printf` too) being buffered (data isn't written to term/file immediately but retained in memory until some point). Improving this process (as seen in the reddit thread) gets GNU-yes.

[deleted]

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

#102

Earlier quoted context omitted.

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

Replace `write(..)` with `puts("y")` and you'll be an order of magnitude faster. This is due to `puts` (`printf` too) being buffered (data isn't written to term/file immediately but retained in memory until some point). Improving this process (as seen in the reddit thread) gets GNU-yes.

It's line buffered when it prints to terminal.

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

#103
post #39

Earlier quoted context omitted.

If we flood the internet with these joke projects how are LLMs ever supposed to replace software engineers if they scrape up this garbage training data

Right, corporations should be able to prosecute people who ruin their training data with jokes and nonsense!

Hey, if they train on my broken Github projects that's one them. They should have known better :-)

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

#104

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…

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

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

#105
post #6

The source is worth a look too: https://github.com/jedisct1/yes-rs/blob/main/src/main.rs

Until I actually went to read the code, I thought this was just a kinda lame overplayed joke, but the number of lines they listed made me really curious: how did they manage to beef up the SLOC that much? After reading a bit of the source code, I take it back. That's definitely venturing into the territory of art.

Yes, art!

I've been in a constant struggle with Claude Code over variable names. I've picked up speed by just getting the code working, fixing names later.

The variable names are what first jumped out at me, looking at this code. It spoke to my pain.

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

#107

Earlier quoted context omitted.

I agree that it's not a serious project, but I wouldn't call it a joke. Jokes are funny.

Actually a joke doesn't necessarily needs to be funny, and depending on the framing not even humor. Gregory Bateson's "A Theory of Play and Fantasy" (in Steps to an Ecology of Mind) (1972): Bateson argues that certain communicative acts signal themselves as "play" or "non-literal." A joke is such an act—structured and marked by "metacommunicative" cues, indicating that it should not be taken at face value. Regardless…

Joking aside, this is Marvin Minsky's paper "Jokes and their Relation to the Cognitive Unconscious", published in Cognitive Constraints on Communication, Vaina and Hintikka (eds.) Reidel, 1981. More fun than a barrel of an infinite number of monkeys.

https://web.media.mit.edu/~minsky/papers/jokes.cognitive.txt

>Abstract: Freud's theory of jokes explains how they overcome the mental "censors" that make it hard for us to think "forbidden" thoughts. But his theory did not work so well for humorous nonsense as for other comical subjects. In this essay I argue that the different forms of humor can be seen as much more similar, once we recognize the importance of knowledge about knowledge and, particularly, aspects of thinking concerned with recognizing and suppressing bugs -- ineffective or destructive thought processes. When seen in this light, much humor that at first seems pointless, or mysterious, becomes more understandable.

>A gentleman entered a pastry-cook's shop and ordered a cake; but he soon brought it back and asked for a glass of liqueur instead. He drank it and began to leave without having paid. The proprietor detained him. "You've not paid for the liqueur." "But I gave you the cake in exchange for it." "You didn't pay for that either." "But I hadn't eaten it". --- from Freud (1905).

>"Yields truth when appended to its own quotation" yields truth when appended to its own quotation. --W. V. Quine

>A man at the dinner table dipped his hands in the mayonnaise and then ran them through his hair. When his neighbor looked astonished, the man apologized: "I'm so sorry. I thought it was spinach."

>[Note 11] Spinach. A reader mentioned that she heard this joke about brocolli, not mayonnaise. This is funnier, because it transfers a plausible mistake into an implausible context. In Freud's version the mistake is already too silly: one could mistake spinach for broccoli, but not for mayonnaise. I suspect that Freud transposed the wrong absurdity when he determined to tell it himself later on. Indeed, he (p.139) seems particularly annoyed at this joke -- and well he might be if, indeed, he himself damaged it by spoiling the elegance of the frame-shift. I would not mention this were it not for the established tradition of advancing psychiatry by analyzing Freud's own writings.

>ACKNOWLEDGMENTS: I thank Howard Cannon, Danny Hillis, William Kornfeld, David Levitt, Gloria Rudisch, and Richard Stallman for suggestions. Gosrdon Oro provided the dog-joke.

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

#108

Earlier quoted context omitted.

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

Replace `write(..)` with `puts("y")` and you'll be an order of magnitude faster. This is due to `puts` (`printf` too) being buffered (data isn't written to term/file immediately but retained in memory until some point). Improving this process (as seen in the reddit thread) gets GNU-yes.

Don't you actively want it to flush asap since you're usually piping into another program?

I suspect what you suggest creates a more voluminous dump but is slower in the desired use case

Post reply on HN