Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
[flagged]
kunai on April 9, 2013 | hide | past | favorite


The title is very misleading, judging the whole userland with this example is just unfair, besides, FreeBSD's one isn't pretty either still the OP choose to only bash on GNU.

Also, if you actually read the code it's the --help that takes up most lines in GNU's case. That's probably a standard inside coreutils codebase.



This shit again? And this time with such a bullshit title...

GNU echo simply does a lot more than the other echo implementations. And believe me it's much more useful in daily usage. That's why the GNU tools are so successful. All the minimal (often broken) utilities you had to use on commercial Unices were no fun. So everybody installed the GNU stuff.

I use -e and -n options of GNU echo regularly. Even if

    echo "foo\nbar" | remove-trailing-space | expand-escape-sequence
would be the "UNIX way" of doing it.

The only thing of poor quality here is the submission title!


So the GNU command line utilities do much more than their minimal counterparts on other Unix platforms and this was a reason for why they became so popular. Then this would be an argument against "Do one thing and do it well." This needs to be brought up whenever anyone extolls the Unix philosophy.


As someone using 'echo -e' all the damn time I find the rant misdirected, poorly thought out and pointless.


GNU code is ornate. GNU code always tries to do more than other implementations of tools.

"Quality" is in the eye of the beholder. Some people might like the extra features and in the usage documentation built into the GNU product. Other people hate every excess line of code that they need to maintain.


Part of the reason is standard options, as mentioned elsewhere in this thread: https://news.ycombinator.com/item?id=5520962

Another part of the reason is that GNU code, historically, tried on purpose to look different at the source code level from other Unix systems, to reduce the possibility of accusations of illegal copying.


More to the point, some confuse 'I never need this' with 'Nobody needs this' and jump from there to 'Anything that implements this is bloated'.


I find the FreeBSD one more embarassing, to be honest. The GNU version just does a ton of annex stuff (hex handling, usage(), etc). I have no idea what the hell the FreeBSD one is trying to do.


The FreeBSD version is building up an iovec (which is effectively an array of (pointer, length) tuples) to pass to writev. I believe this is done for two reasons --

1) It reduces the number of syscalls -- a single call to writev outputs everything, rather than multiple fputs calls which may or may not be buffered (I haven't checked the impl details of fputs).

2) It reduces the number of allocations. Since an iovec is just an array of pointers, we can reused the data passed in via argv; the length of the iovec is capped at argc, so we can get away with one allocation without scanning the input.

For a comparison, here's a brief overview of each of the implementations (assuming fprint/fputs is not buffered):

* Unix V5: 0 allocations, N syscalls, no argv scan

* OpenBSD: 0 allocations, N syscalls, no argv scan

* Plan 9: 1 allocation, 1 syscall, scans argv

* FreeBSD: 1 allocation, 1 syscall, no argv scan

* GNU (without -e): 0 allocations, N syscalls, no argv scan

"argv scan" basically means calling strlen on every passed argument, or otherwise iterating over them. Naturally, "which one is faster" depends on how fast your allocations/syscalls/strlen's are, and how fprint/fputs is buffered.


If you have multiple programs writing to the same terminal, their write calls can get interleaved. To ensure that a single echo command's output remains unbroken, it should be output using a single write call.

GNU relies on stdio's buffering for this. Plan 9 allocates a buffer for the entire output and copies the arguments there. FreeBSD wants to avoid linking to stdio, and wants to avoid copying memory (both for reasons of efficiency, presumably), so it uses the writev call instead, which lets you pass the kernel an array of buffers to write, without having to build up a single buffer in advance.


GNU userland is more usable and complete. It's also occasionally a little gilded.

When working on Solaris or OS X, one of the first things I do is get the GNU utilities into my path ahead of native ones. That way, I get the same environment on all 4 platforms I use - Cygwin, Linux, OS X and Solaris.


Since when does "has more lines of code" equate to "poor quality"? This reeks of trolling, flagged.


Stupid. "This orange is a poor quality apple."


I'm fine with GNU echo being so much more robust, besides most of the time the shell's built-in echo is the one actually called.

echo --version vs /bin/echo --version

What I can't understand is the terrible malloc() implementation in glibc still being there after all these years.


> What I can't understand is the terrible malloc() implementation in glibc still being there after all these years.

Now you can't lead off like that and not tell us what is so bad about it, and what I should use instead!


Try tcmalloc.

Among the many problems with glibc's malloc (when I tested, anyway) is that it slows down considerably as soon as you start up a thread, even if you immediately shut it down.


Not surprised at all that this translated to "...is not Plan 9" (I would've counted "was not written by DJB", too).

There seems to be some kind of computer nerd pecking order, similar to the "Trekkie->Larper->Furry" sequence. Lispers->Smalltalkers->Linuxers->9fans? (With Niklaus Wirth standing on the sideline, shaking his head)


But who uses echo(1) anyway? It's not portable. Code quality aside, that much should be obvious from this gist.

Use printf(1) instead.


Why isn't echo allowed to use getopt(3) option parsing (as noted in a comment of some versions)?


I would imagine it comes down to the POSIX definition and the need to echo everything but -n and not eat it.


> Users don't want programs to be consistent, they want them to do what they want them to do.

That comment nails it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: