Live data from Hacker News

Gonix – Unix tools written in Go

github.com

51–60 of 85 posts

Re: Gonix – Unix tools written in Go

#51
post #37

Earlier quoted context omitted.

I don't know much about go, but taking a quick look at implementations - they seem to be written by a programming novice, and the are quite primitive. Don't mean to be negative, just my opinion.

I am a novice, and that is one of the reasons why I started this project (to learn).

The problem is something like tail should not read the whole file into memory. tail works on a 100 gig file even with 100 megs of ram.

Re: Gonix – Unix tools written in Go

#52
post #47

Earlier quoted context omitted.

bytes, _ := ioutil.ReadAll(os.Stdin) lines := strings.Split(string(bytes), "\n") Tip: use bufio.Scanner. scanner := bufio.NewScanner(reader) scanner.Split(bufio.ScanLines) for scanner.Scan() { // Do stuff } And you can iterate over the lines 'lazily'. If you don't want to consume \r's, make your own ScanLines :).

[deleted]

You mean bufio.ReadLine? As the documentation says, it's low-level, since you have to do the buffer allocation yourself. ReadBytes/ReadString are nicer interface-wise, but it allocates new buffers on every call.

I like Scanner because it provides a nice high-level interface, but still maintains an internal buffer, reducing GC pressure. Of course, it's not one size fits all.

Re: Gonix – Unix tools written in Go

#53
post #48
post #46

Earlier quoted context omitted.

We really need a busybox in Rust or Go. The existing one has licensing problems and security problems, and is built into too many embedded devices.

Busybox is GPLv2. That's the same license as the linux kernel; it's not a problem. You just have to release your modified version of the busybox source if you distribute it in a product. The only difference is that busybox developers enforce the license against the many companies who can't be bothered and respond to requests with lawyers. That said, a bsd-licensed re-implementation of busybox (still in c) that's pret…

Also, Toybox will replace Toolbox in Android M.

Re: Gonix – Unix tools written in Go

#54
post #7

Why do Go programmers always want to redo everything? It's rare to see something actually new written in Go, proving that Go can do everything C can (except make shared libraries and produce small binary sizes) but not that it's actually better .

Because that is the whole point.

If C is still present in the stack, the typical C exploits are possible, which were how many Oracle JVM exploits came to be, for example.

Reducing C presence to the same as Assembly, will just make everything safer in our systems.

Not that it will ever happen in UNIX systems, given how C came to life.

Re: Gonix – Unix tools written in Go

#55
post #47

Earlier quoted context omitted.

[deleted]

You mean bufio.ReadLine? As the documentation says, it's low-level, since you have to do the buffer allocation yourself. ReadBytes/ReadString are nicer interface-wise, but it allocates new buffers on every call. I like Scanner because it provides a nice high-level interface, but still maintains an internal buffer, reducing GC pressure. Of course, it's not one size fits all.

I tested it by on a several megabyte text file (not that large) and I can see a huge improvement in speed when I use a reader vs. loading the whole thing into memory as I did at first.

I can see now how much of a difference it can make on a really large file, like in the gigabyte range.

BTW, I deleted my earlier comment because the problem I had wasn't anything to do with bufio. I had just made an obvious mistake elsewhere in my code, which I've fixed now.

Re: Gonix – Unix tools written in Go

#56

Earlier quoted context omitted.

I am a novice, and that is one of the reasons why I started this project (to learn).

bytes, _ := ioutil.ReadAll(os.Stdin) lines := strings.Split(string(bytes), "\n") Tip: use bufio.Scanner. scanner := bufio.NewScanner(reader) scanner.Split(bufio.ScanLines) for scanner.Scan() { // Do stuff } And you can iterate over the lines 'lazily'. If you don't want to consume \r's, make your own ScanLines :).

Tail also doesn't always need to read its entire input. When given a file path, it can read backwards from the end of the file until it has found its n lines. That makes tail fast on huge files (as long as they have normal line lengths), but it also complicates the code.

And you may want to mmap the file, rather than open it. Whether that is a speeds up things depends on OS, OS version, file size, file system, available memory, phase of the moon, etc.

Re: Gonix – Unix tools written in Go

#57
It would be cool to have a "busybox" alternative targeted at Plan9 commands. I personally find Plan9 utils much more logical (and easier to implement!). Something like 9base from suckless, but as a single binary and hopefully in a more modern language (most of the code like sam or rc is not so easy to understand).

Re: Gonix – Unix tools written in Go

#58
post #18

Not meaning to bring up a Rust vs Go debate, but since there are a few comments claiming that this is a waste of time, I figured it's worth mentioning the Rust based re-implementation of coreutils: https://github.com/uutils/coreutils/ And another by suckless in plain C: http://git.suckless.org/sbase/tree/README

nice. This is the first time I actually read Rust code, and aside from "something macro" that scares me, it's actually mostly readable. Will definitely check out.

Re: Gonix – Unix tools written in Go

#59

Heh, this brings me back. I was a young guy at Sun, perl 4 was a thing, I actually argued that we should redo /usr/bin in perl. In the days of a 20mhz SPARC. Silly me. Maybe it makes sense now.

There's "Perl Power Tools: Unix Reconstruction Project" [0], which doesn't seem to have activity since 2004. I remember something older than 2004, I think, back from when perl was first available on Windows, to bring UNIX command line utilities to Windows through perl. It's great that they all have inline POD documentation too. [0] http://search.cpan.org/dist/ppt/

The "Perl Power Tools" project has been revived by brian d foy: https://metacpan.org/pod/PerlPowerTools

Re: Gonix – Unix tools written in Go

#60

Heh, this brings me back. I was a young guy at Sun, perl 4 was a thing, I actually argued that we should redo /usr/bin in perl. In the days of a 20mhz SPARC. Silly me. Maybe it makes sense now.

I'm curious: what was your main motivation? I can understand it as a worthy challenge, but it would probably have led to a worse performance than the C-based utilities, no?
Post reply on HN