Earlier quoted context omitted.
For reference, here is true.c: https://github.com/coreutils/coreutils/blob/master/src/true.... .
So basically they also introduced the complexity of respecting --help and --version.
Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
151–160 of 170 posts
Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
#152Earlier quoted context omitted.
...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?
The source code is extremely non-serious.
Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
#153Earlier 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!
Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
#154https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=705...
Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
#155Earlier quoted context omitted.
I disagree that it’s more explicit. The case distinction and the loop and the puts are exactly the same in both code variants. You can replace the ternary operator by an if if that’s bothering you, that wasn’t the point of the change. The point is to first determine what should be output repeatedly, and then to output it, because the output logic is independent from what is being output (in particular, `yes` and `yes…
How about: for (;;) { if (argc > 1) puts(argv[1]); else puts("y"); } ? You said "it’s about duplicating logic that should inherently be the same", but that is exactly how it is more explicit, by having this duplication. I assume your problem is with the two "puts()"?
Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
#156Earlier quoted context omitted.
I was being humorous, but tbh it’s not so clear cut! In 99% of cases, yes of course you’re right, factor this loop. In this specific case? This is trivial code, that will likely _never_ change. If it does change, it’s extremely unlikely that the two loops would accidentally diverge (the dev would likely not miss one branch, tests would catch it, reviewers would catch it). So if you get any upside by keeping the two l…
I agree that it’s borderline pedantic for this simple code, but I also find it an obvious code smell, contradicting the “as simple as it gets”. If you consistently deduplicate code that is supposed to do the same and evolve the same, then any duplicated code sticks out as a statement of “this isn’t the same”, and in the present case it then makes you wonder what is supposed to be different about both cases. In other…
> in that sense I disagree that the duplicated version is more readable
I didn't say it is, I agreed it's _less_ readable. I said it's trading off readability for 8 bytes of memory at runtime.
> If you consistently deduplicate code that is supposed to do the same and evolve the same, then [...]
I agree with all this. I'm not saying to consistently go for the deduplicated approach (I don't think anyone would say that), I'm saying it's a reasonable trade-off in this specific case (each branch is still trivial, and the code won't evolve much if at all).
> About possible performance reasons, those need an explanatory comment, exactly for the above reason.
Agreed.
> if performance reasons warrant complicating the code, then it isn’t “as simple as it gets” any more. I was commenting because I disagreed with that latter characterization.
Also agreed.
Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
#157Earlier quoted context omitted.
How about: for (;;) { if (argc > 1) puts(argv[1]); else puts("y"); } ? You said "it’s about duplicating logic that should inherently be the same", but that is exactly how it is more explicit, by having this duplication. I assume your problem is with the two "puts()"?
That's a whole lot less efficient than both other options, the condition will be checked at every loop, that's not cheap
Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
#158There is an enterprise-grade project written in Java: https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
#159So is this an argument against reinventing the wheel?
https://en.wikipedia.org/wiki/Build_a_better_mousetrap,_and_...
And boomers know that the grand-master of designing better mousetraps was Rube Goldberg:
Re: Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command
#160Earlier 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] ...
yes &
A few times is still my favorite way to push a cpu to max temperature for testing. Used it a lot to detect faulty Core 2 Duo MacBook back in the day. They would short circuit some CPU sensor due to thermal expansion or melting of the wire insulation. Yes was an easy way to get the CPU’s hot enough.