7 ms·
Cool, I didn't know this existed. I think simple ones like `yes` can be very interesting just to see how the base code of a utility (that writes to stdout) is w
by version_five 3y ago
Cool, I didn't know this existed. I think simple ones like `yes` can be very interesting just to see how the base code of a utility (that writes to stdout) is written.
https://maizure.org/projects/decoded-gnu-coreutils/yes.html https://maizure.org/projects/decoded-gnu-coreutils/yes.html
- 38 3y agohere is a Go implementation for fun: package main import "flag" func main() { yes := flag.String("m", "y", "message") flag.Parse() for { println(*yes) } }
- sltkr 3y agoHere's a Brainfuck implementation: ++++++++++[->++++++++++++>+<<]>+[.>.<] (Unfortunately, Brainfuck doesn't support command line flags.)
- dale_glass 3y agoYeah, GNU yes could be about that simple but it's a good deal more complex to obtain the best performance possible: https://www.reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/ https://www.reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes...
- 38 3y agoum, who cares? most times people are needing to use "yes" as part of a "configure" script or similar. even if GNU yes was 10 times slower, it would NEVER be the bottleneck in any situation. so whats the point?
- the-smug-one 3y agoYou'll have to ask the author that. Now, I'd like to ask the author who cares how you implement 'yes' in Go ;-).
- 38 3y agoyes C lines of code: 112 yes Go lines of code: 9
- placesalt 3y ago16 lines of go, with comments & whitespace
- 38 3y ago134 lines of C, with comments & whitespace
- deleted 3y ago[deleted]
- not2b 3y agoThat isn't an apples-to-apples comparison. A C version could be similarly short, but the GNU yes implementer got carried away with efficiency considerations. If the Go program did the same, it would be longer.
- hunson_abadeer 3y agoIt feels like you're making a bad-faith argument here. You can implement 'yes' in a straightforward way in a couple lines of C, too. main(int argc, char** argv) { while (1) { if (argc > 1) for (int i = 1; i < argc; i++) printf("%s%c", argv[i], (i == argc - 1) ? '\n' : ' '); else puts("y"); } } The point other folks are making is that it's written differently for a reason. Maybe not a reason that's important, but at the very least, let's try to compare apples to apples.
- rcr 3y agoFyi before anyone else decides to read the idiocy that follows in this thread, this is guy is a known troll with a long history of this exact behavior. Same person: https://news.ycombinator.com/item?id=27862463 https://news.ycombinator.com/item?id=27862463 I think this person is just mentally ill unfortunately.
- 38 3y agowhen people resort to doxing, it shows how truly pathetic they are. I pity those people.
- version_five 3y agoReplying to myself because the thread got trolled: My point was in part that it's valuable for even a simple utility to be well written and optimized and that it's nice to have these minimal examples to learn about how to, e.g. write output very quickly. The program is so short that presumably the number of lines is unimportant, and if the author knows how to do it they might as well make it as fast as possible so it's never in the way, and so we can learn from it. That's why I think it's a good example.
- m1keil 3y agoalso quite interesting to compare with other implementations from the present and the past: https://github.com/openbsd/src/blob/master/usr.bin/yes/yes.c https://github.com/openbsd/src/blob/master/usr.bin/yes/yes.c https://github.com/freebsd/freebsd-src/blob/release/4.0.0/usr.bin/yes/yes.c https://github.com/freebsd/freebsd-src/blob/release/4.0.0/us...