4 ms·
Gotweet - command-line Twitter client in Go
- dchest 17y agoTwitter clients are the new "Hello world" of programming. I wrote it to try out and get familiar with the language. While writing it I found a bug in JSON library (http://code.google.com/p/go/issues/detail?id=73 http://code.google.com/p/go/issues/detail?id=73), which has been fixed quickly by Go developers (in less than an hour). Currently their http library doesn't support basic authentication, and their http.send method, which allows tweaking headers, is private, so I had to copy and paste three methods from http package and add authentication (see http_auth.go). The hardest part for me was to get those io things right (I was confused by []byte vs bytes package, and io.Writers/Readers). I love cross-compilation: both binaries (for Mac OS X and Linux) were compiled on Mac.
- uriel 17y ago> I love cross-compilation: both binaries (for Mac OS X and Linux) were compiled on Mac. Indeed, the Plan 9/ken way of structuring compilers rocks. All compilation is cross-compilation! Simple, elegant, reliable.
- jrockway 17y agoI continue to not be particularly excited by Go. My first thought when reading this code was "wow, that's a lot of verbosity mixed with a lot of line noise". If this was Some Random Guy's project, nobody would have heard of it and nobody would care. But since Google is paying for it, it's suddenly amazing? No exceptions? Seriously? If you want a better system programming language than C, why not use Haskell? If it is better than Go in perhaps every measurable way. And there is already an HTTP library that supports basic auth...
- dchest 17y agoJust a note: don't rely on my code to get a taste of language, because, obviously, it was "hacked together while learning a language" instead of "programmed". There are sources for packages on Go website http://golang.org/pkg/ http://golang.org/pkg/ that are written clearly.
- jrockway 17y agoI think all the problems with your code are Go problems, not problems with how you used it. Things like Twitter clients always look ugly in low-level languages, however.
- ptomato 17y ago"is better than Go in perhaps every measurable way" speed of execution, speed of compilation.
- jrockway 17y agoYes, you are perhaps right about speed of compilation. I do my Haskell hacking in the REPL, so the number of times I actually compile my projects is minimal. I have never thought, "this is taking way too long, what a drag". There may also be a factor of 2 execution speed advantage for a few things that Go lets you directly write in a CPU-friendly way. But the slow part of a Twitter client is waiting for Twitter. In fact, even Twitter isn't written in Go or Haskell or C, and it still works fine.
- ptomato 17y ago"But the slow part of a Twitter client is waiting for Twitter." Undoubtedly. But if we're going from the position of systems programming languages speed of execution is inevitably going to be a factor. And you did say every measurable way... so what other measurable ways did you have in mind?
- jrockway 17y agoI should have not used the word "measurable".
- flogic 17y agoPersonally, Ken Thompson and Rob Pike carry more weight than Google. Also it is much easier to reason about memory and CPU usage with Go than Haskell. I think of Go as occupying a different local maxima than Haskell.
- jrockway 17y agoBut it's much harder to reason about whether or not the program will return the correct answer.
- pieter 17y agoI wanted to check out the source of the program, but getting to the source on that site is just too much trouble.
- dchest 17y agoI've added a link to zip archive to the home page.
- gcampbell 17y agoI note a comment in your code that "Twitter sends malformed JSON, with top-level array. Workaround: put it under 'tweets'." As I understand it, a top-level array is perfectly legal JSON (see http://www.ietf.org/rfc/rfc4627 http://www.ietf.org/rfc/rfc4627 - "A JSON text is a serialized object or array."). Are there other problems with Twitter's JSON, or does Go's JSON implementation fail to support top-level arrays?
- dchest 17y agoAh. Someone at #go-nuts said it wasn't valid, so I made the change and it worked. If it's valid, than yes, it must be a bug in Go's json package. Edited the comment, filed a bug report (http://code.google.com/p/go/issues/detail?id=114 http://code.google.com/p/go/issues/detail?id=114). Thanks!
- gcampbell 17y agoAs a note, top-level JSON arrays have been demonstrated to have some security problems in web browsers when delivered via GET requests; see http://haacked.com/archive/2009/06/25/json-hijacking.aspx http://haacked.com/archive/2009/06/25/json-hijacking.aspx for more. (This isn't relevant for JSON-as-interchange-format in other contexts, of course).