72 points · by gits1225 · 13y ago · 118 comments
If you build a webapp in Go, be prepared to spend a lot of time monkeying around with problems that are solved issues on most other platforms.
lis, err := net.Listen("tcp","127.0.0.1:80")
go http.Serve(lis, router)
lis.Close()
I can't see how this can be true in any real form if I can't completely turn off garbage collection. There's a lower bound to your ability to eke out additional perf when you have to take into account a stop-the-world garbage collector that you don't directly control.
I'm certainly not the best programmer around, but I tend to subscribe to the notion that perhaps complex and powerful exists because that complexity grants additional flexibility to those who know how to use it. (Hell, Rob Pike has admitted as much on his blog regarding why Go doesn't appeal to many people who are competent C++ programmers. Though he decided to frame it as if it's a negative, which I really appreciated.)
Scala works beautifully with IDEA IDE, one of the best IDE out there! GUI debugger just works out of the box.
I tried using Go for a little bit but I find IDE and tooling support for Go is a bit lacking. Do people consider these aspects anymore when they evaluate a new language? A proper IDE support can greatly boost your productivity!
I'm pretty sure GDB works now too, but again I have never really felt the need for it. But then, I've never really felt the need for syntax highlighting, code folding, or auto-completed function names. I feel like if my Go code has reached a level of complexity where it needs those things, I've done something wrong. My IDE is Acme, it lets me edit files, run my build scripts, and execute test programs.
Maybe I should just delete all these repos I've worked on for my job, the cluster management tool, the pedestrian simulator, the GSM radio emulator, the VM monitoring infrastructure, the distributed key-value store. They were written in Go, so I guess they weren't real programs.
My style is to only log when I'm debugging a failure I don't understand. Then I remove the log output.
I also make sure that my unit tests cover the problem case I was debugging, because problems that require this kind of detailed debugging tend to be the trickiest to keep maintained without regressions. And I try to make my code based on careful state management (or, if possible, statelessness), preferably with a state machine.
Maybe debuggers are useful to you in other scenarios, but they are by no means necessary. You don't need to be inflammatory about it.
There's still a lot to do, and much of that is stuck in my head at this time, but I'll do my best to put it all with the source soon. Plus I gotta work on "presenting" it a bit better (in a way that is more friendly towards other people seeing its long-term value and getting them interested in collaborating).
However, if I decide to go with Go as a framework choice, is there an active market of Go developers out there from which one can hire?
The language eschews some brevity in exchange for clarity, which gives me a lot of confidence that I can take a good developer from any background, give them a week and feel like they've got a decent chance of acquiring the knowledge they need to work with the language.
The newness of the language means that there isn't a huge ecosystem of libraries available, BUT the standard lib is pretty damn great, and there are more and more people coming to the language every day.
My favorite thing about go is it's overall sense of boringness - Go code seems very predictable. There's a culture of digging into the source throughout the community, and tools like go fmt & go vet ensure that most code looks similar.
It'd be worth spending a week with it to write something useful to get a sense of whether or not you truly like it, but my experience has been very positive so far.
I love the features, though, especially the concurrency ones. It was conceptually trivial to write a multicasting TCP proxy in it.
After a little while you start thinking about "can this code be clearer? Are the intentions obvious?" and that makes the code much easier to write.
Go is incredibly easy to refactor, so instead of worrying about being exactly right, you can focus on "is this easy to reason about?". My experience has been that this process will get you very close to idiomatic code on its own.
Not yet perhaps.
The best places to find these people would be golang-nuts mailing list, /r/golang, #go-nuts irc etc.
I am not sure.
Most people who know the important low-level languages well, are not likely to be a fan of Go. Seasoned C++ hackers will miss templates dearly (no, interfaces are not a replacement for templates, they are a replacement for abstract base classes) and C/C++ programmers dislike the lack of control over memory management. If you are using C or C++ in 2012, you probably have good reasons and Go mostly sacrifices the advantages of C and C++.
Someone who is familiar enough with Haskell, ML, or Scala, will dislike the fact that Go practically ignored (or rejected?) two or three decades of research an programming languages. From the perspective of PL research, Go is a weak language.
In other words, the low-level and strong typing crowds are not that much interested in Go. If there is a new imperative language that does interest them, it is probably Rust.
The question is, who does switch to Go? One would guess that these are mostly Python and Ruby programmers who have never written much C, C++, or Haskell, and are looking for something faster and compiled. Yes, this is a generalization, and there are plenty of exceptions. Not exactly the 'Python paradox', 'better than the rest', programmers.
Following the Google+ community, discussions on HN, and to an extend the Go mailing lists, confirms those suspicions. There are lot of grandiose claims supporting Go (one of my personal pet peeves are people claiming that 'Go interfaces are like Haskell typeclasses'). But if you look at the language spec, there is not much interesting. Goroutines are nice, but they are just green threads. Channels have been done elsewhere.
Go is just a very boring language (which isn't necessarily bad), pretty much like Java, without the good package management (no versioning), good IDEs, broad library support, or a performant garbage collector.
Boring languages attract more mediocre programmers than great programmers.
Edit: if you downvote, please, at least leave a comment ;).
I would add a bullet point to the list of reasons I like go: "Boring to people who bring up Haskell in every programming conversation" ;)
Seriously though, there are huge classes of problems in which the "interesting" part of the problem isn't the software that gets written but the business needs it solves. I am a fan of functional programming (I started the Clojure subreddit, and do a lot of "for fun" programming in it), but I've never run across a problem at my business where I felt like I needed to crack open Okasaki's book, or thought "this would be easier with an applicative functor".
Something I've enjoyed about learning Go is the open & accepting nature of the community; I don't think I've ever heard someone called "mediocre" because of other languages they use.
I am happy to feel like I don't have to be an incredible programmer to read the source code of the language I use, or the libraries I pull into my projects. I just want to get shit done so I can work on the problems that I find interesting, and for lots of us, that's just not going to be yet another implementation of datalog.
Interfaces aren't a replacement for templates, but they aren't a replacement for abstract base classes either. Interfaces in Go provide polymorphism through structural sub-typing. My limited knowledge of abstract base classes says that these are very much not the same.
> Someone who is familiar enough with Haskell, ML, or Scala, will dislike the fact that Go practically ignored (or rejected?) two or three decades of research an programming languages. From the perspective of PL research, Go is a weak language.
I am a Haskell programmer, but that crowd is impossible to please unless you've provided every PL feature out of research in the last few decades. I've seen virtually no appreciation for simplicity of language design as an entire unit.
> If there is a new imperative language that does interest them, it is probably Rust.
Yes. I can't wait for Rust to get a bit more love in the documentation department. Pattern matching? Algebraic data types? Thread local storage? Type classes? Yes please! Where do I sign up?
> The question is, who does switch to Go? One would guess that these are mostly Python and Ruby programmers who have never written much C, C++, or Haskell, and are looking for something faster and compiled. Yes, this is a generalization, and there are plenty of exceptions. Not exactly the 'Python paradox', 'better than the rest', programmers.
In my experience, most Go programmers are in fact coming from Python and Ruby.
The premise of the "Go" or "Python" paradox is that skilled programmers tend to be the first ones to adopt new languages. Then the less-skilled programmers follow when there is sufficient buzz. I think that if one accepts that premise, it is applicable for Go.
> one of my personal pet peeves are people claiming that 'Go interfaces are like Haskell typeclasses'
That is annoying, but completely understandable. They are deceptively similar on the surface. But I don't think this kind of confusion is unique to Go. You'll see it everywhere.
You know what else people confuse? That Go interfaces are just like abstract base classes! :P
> But if you look at the language spec, there is not much interesting.
That's kind of the point. If you don't accept the overall simplicity of the design Go as a feature, then I can't blame you if you dismiss Go. If all you want to judge a language by is whether it includes cool and exciting new features, then Go will never be a good choice for you a priori.
> Go is just a very boring language (which isn't necessarily bad), pretty much like Java, without the good package management (no versioning)
I am utterly baffled. Go's approach to packaging is literally the best tool of its class that I've ever used. The Go tool militates toward convention rather than providing a dizzying array of features. This makes it strictly less powerful than other packaging tools, but god dammit, it makes it dead simple to install packages.
You want to try my window manager, which is roughly 30,000 LOC (including my X libraries)? If you have Go installed: `go get github.com/BurntSushi/wingo`. That's it. You're done. I just ran it on my system, and it downloaded, compiled and installed my window manager---along with all of its dependencies---in less than 30 seconds.
You might say---other build tools can do this! But do you know how many lines of configuration I had to write for any of this to work? None. I didn't specify dependencies. No strange command line flags. Nothing. The common case Just Works.
> Goroutines are nice, but they are just green threads. Channels have been done elsewhere.
This is a vast understatement. Just green threads? And please, tell me, what other mainstream language supports green threads? I know Haskell and Erlang do. Rust will (yay). Anything else? No? (I know Java doesn't, but I can't remember if this is a limitation of the JVM or if Scala or Clojure have green threads). Go does. That's a pretty big deal. Go makes a solid concurrent style of programming in a C-like language virtually free. Sure, everything is still mutable, but there are powerful idioms that---in my experience---militate against race conditions. It's not as good as Haskell/Erlang/Rust in the compile time safety department, but I'll be damned if it isn't loads easier than my other choices: C, C++, Java, Python, Ruby, Lua, blah blah.
> Boring languages attract more mediocre programmers than great programmers.
And close minded folk think they have all the answers. It's possible for people to enjoy using more than one tool. I'm a hacker, and I love good tools. Go is a great tool. So is Haskell. I hope that Rust will be.
I wouldn't worry about an active market of Go devs to hire. If a language is any good, it'll attract developers. If you're a programmer, you should try out the language to not only do things you can do in other languages (to see how it fares), but more importantly, "What are the new things I can do with Go that use to be hard, but are now easy?"
Go ahead and make a mini Go app, re-implement half the features that Express in Node has, then benchmark the 2 with real data using the same data and templates.
Come back when you see that once you start pulling records in from mongodb or somewhere else and start rendering either server side templates with this mongo data or serving json back then the performance differences of the 2 frameworks begin to disappear.
Node will perform better under high concurrency too for most sized responses.
So where's the motivation to switch? If I switch to Go then I have to learn Go + I'm still using Javascript on the front end.
If I stick with Node then I can use my JS knowledge on both ends. This is a really big deal for day to day web app programming and is a deal breaker for html5 games.
Go cannot be taken seriously to be used for web apps until it offers actual performance gains over JS and gets something that lets you write Go but it spits out JS for the client, sort of like Java has GWT (ps. that bombermine mmo uses GWT).
There's also a serious lack of good light weight web frameworks for Go. None of them come close to what Express does for Node, and I'm not the only one who thinks Express is really close to an excellent mix of features without getting in your face.
Can you share evidence supporting this claim?
I used mgo with Go to connect to mongodb.
Then I filled it with 1,024 documents that was composed of 2 fields. One field with a few bytes of text and the other with a paragraph of text.
Then I created a few handlers to return:
1) 1x document as json
2) 7x documents as json
3) 15x documents as json
At 15x I decided this was likely going to generate a response large enough that there's no point going higher. It was about 25kb worth of json.
Then I used a lib called "routes": https://github.com/drone/routes
It's not really close to what express does but it's better than nothing. Then I added in my own etag generator using the same method that express does (it gens it off the body length) for responses > 1kb.
Then I benchmarked each route 3 times with ab using: -n 7500 -c {50, 250, 750, 1500}
I ignored the first and averaged the last 2 results.
I did this on a local VM locked down to 1 CPU with 512mb of ram with a c2d 2.13ghz CPU and a 7200 rpm sata HD.
Then I did the same with express using just bodyParser since neither setup had session support. Go didn't have a Redis store that was capable of working with the Gorilla session lib so I didn't use sessions on both setups.
I used the native mongodb driver for node.
Express was for the most part 10-15% faster where faster is more requests per second served. The latency was back and forth. I feel like the latency @ 99% was tighter with Go once the concurrency got really high but the amount was not enough to matter.
For example once I got to the higher concurrencies both were taking a ridiculous amount of time (over 7 seconds) on my old crappy desktop. Loading in 5.5 seconds instead of 7 seconds is not really "better" since it's abysmal on both.
Go is much better at responding with large amounts of data when the database call is eliminated. I can only assume its ability to deal with large strings is leaps and bounds superior to v8 which makes sense to me.
The thing is though, that's pretty much irrelevant. If I was going to serve static content I would be using S3 or nginx. If I'm serving dynamic content then I'm likely pulling this in from a database.
Go 1.1 (to be released early next month) is across the board faster than 1.03.
The ab tool is not ideal for testing the Go http server because the Go server is not tuned to ab's quirks. Siege might be better.
The mgo client has the most bells and whistles, but it's probably not the fastest client for Go. One of the other clients might perform better.
Why are the Go Redis clients not capable of working with Gorilla? A couple of the clients are well written and are fully functional.
In my own micro-benchmark, I've seen that BSON decoding takes big chunk of time when using mgo. That should explain why the go version got faster when DB access was removed.
This shouldn't come as a surprise as the node.js driver uses a BSON parser written in C++ by default.
Which is a shame, since it's otherwise somewhat interesting.
Haskell is a much better choice than Scala, as long as JVM isn't required.
A professor I knew, who was easily one of the more decorated in my university, claimed he knew Haskell.
I had used Haskell to parse biomedical data for my course on biometrics, as the data was inconsistent and full of errors, the correct design was to create a monadic structure. I consulted that professor, and he was flummoxed, just on the basic structure of the program (which was done in a basic top down style of declaring the types and breaking large functions into small ones).
I fully accept my inability to use the language in a useful way may just be symptomatic of me being an idiot. I fully accept that my professors inability to understand the language in a any way may be symptomatic of him being an idiot.
But as big a failure as I am at learning this language, I can't imagine the result of tasking someone who doesn't enjoy programming with maintaining Haskell.
If scala is worse, then that's just horrifying.
But if we consider the resources to learn the language along with the language, then I think Scala dominates Haskell. Haskell was painful for me to learn because to become proficient I had to trudge through not only books but wikis, blogs, and code. There is nothing like Odersky's Scala book in Haskell. Learn you a Haskell, the Haskell wikibook, and Real World Haskell are all _terrible_ at preparing someone to become a proficient haskeller because while they show you the language they don't train you to think functionally.
In imperative languages you're giving a lot of sequential instructions to a robot. In functional languages you're programming the robot to understand a new language, and then you describe the way things ought to be in that language.
What OCaml lacks, is a more modern implementation; I hear that the company OCamlPro are currently implementing a per-task GC strategy to allow for better multi-programming, there are alternatives to the rather minimalist standard library (Jane Street Core and Batteries Included), OPAM is poised to become the de factor OCaml package manager. I'm still hoping that built-in Unicode support will become a reality as well.
If OCaml gets better parallelism, it'll rival F# in usefulness, but without the annoying VM.
Haskell is much cleaner than Scala. But I think most people will get stuck reasoning about laziness (which is necessary to avoid space leaks). Another problem is that many modules require extensive use of the type system and advanced concepts to use (monads, arrows, lenses, existential typing, etc.).
I think that on the JVM Kotlin is a good candidate for eventually fixing most of Java's immediate shortcomings. Scala is there for people who'd like to go all-functional (regardless' its complexity). One of the nice things is that you get at least some amount of interoperability, e.g. one can perfectly write Play applications in Java and still get many of the benefits of Play.
Not to mention that many modules require various GHC extensions.
I'm not so sure about Kotlin. From what I can see, it's pretty straightforward, with no risk or ambition of achieving the anxiety-inducing Scala method signatures. On the other hand, it seems to be seriously lacking in the marketing department, which can often be enough to push forward a language even when a better option is available.
As a programming language, Haskell has many interesting features, and I would happily use it in various context, including as language of choice for a first "Introduction to Programming" course, but Haskell has several problems too. The most glaring is the 2nd rate support of state. The state monad has several good features, but in particular, it lacks a destructor, so local state use can't be hidden, even when global behaviour is purely functional. Moreover, modularisation is better supported in Scala than in Haskell.
I've looked at it a number of times, I don't like the syntax. When Java came out in August 1995 I was one of the first downloaders (and not even a fan of Sun in particular at that time, just interested in checking out Java) and it was clear just looking at it I would like it.
For about two years, many of the people I work with have been using Go almost exclusively because, while simple and fast like C, the things it adds are so useful we can't imagine trying to hack similar functionality together with C libraries. Things like built-in maps, slices, multiple returns, lambda functions, channels, goroutines... these are all things you can accomplish in C, but it's so much more painful (see: homebrewed hashtables, do-it-yourself pointer management on a big array, returning structs, function pointers, some sort of mutex abomination to replicate channels, pthreads)
And although I haven't tried it out myself yet, it does seem very promising for such use cases. You don't have to "give up" 30 years of existing C code if you are just using it as libraries and OS calls, not rewriting it.
I wouldn't. Nondeterministic garbage collection in a web server like nginx (as opposed to an application web server like Jetty) makes me very nervous. The HTTP (or pick-your-other-TCP-protocol) lifecycle is well-understood enough that you should be able to handle your own memory management.
There are lots of things in Go I like, but for me they're coupled with questionable abstractions that make it difficult to rationalize over C++.
I really don't have a problem with GC though. Its easier to optimise a GC than to fix memory and reference counting bugs. Memory management is not a problem I want to be dealing with after 60-odd years of computers being around.
I do have a side project of writing a DNS server, and my scribbled notes for it say to use Erlang for the protocol speaker and Go for the control plane.
I suggest that what Go needs is some kind of killer project that everyone can learn from. C had UNIX.
Goroutines and channels in particular are an interesting and useful abstraction away from threads and communication between those threads.
Linus Torvalds would disagree that C and C++ are the same language as suggested by "C/C++" and by the singular pronoun that follows.
http://harmful.cat-v.org/software/c++/linus
And maybe too much weight is given to Torvalds' views on this and other topics.
One can easily program as if it were C, using templates to avoid ugly macro mess for generic algorithms and types.
Edit: corrected is -> as.
Feel free to correct me if I'm wrong.
Can anyone explain WHY Scala seems to be ignored by most of the programming community, especially here on HN, where everyone seems to be in favor of either Node.js or Go... ? Is there anyone who can provide some constructive negative feedback regarding Scala (apart from the learning curve) over GO?
Scala didn't keep me curious for long enough to get good at it. I took a look at some examples, flipped through a textbook, and just came to the conclusion that there were way too many features and it appeared to be too clever for me to care. Things like impressive one-liners don't impress me; they do the opposite. That it's built on the JVM doesn't particularly appeal to me because I don't have any existing JVM-dependent projects. Examples like this: http://www.scala-lang.org/node/225
/** Turn command line arguments to uppercase */
object Main {
def main(args: Array[String]) {
val res = for (a <- args) yield a.toUpperCase
println("Arguments: " + res.toString)
}
}
the toUpperCase method being called without parens is bothersome to me, since it makes it ambiguous what is and is not a function call. The for loop being an expression is strange to me; it's a construct that appears to add no value to the programer, at a significant cost of clarity. It must make me seem very stupid to argue against looping constructs as simple expressions, but I think this type of notation is unnecessarily terse. Go doesn't have this type of thing, because the language is designed more for clarity than for terseness. I don't think that this is elegant: for (a <- args) yield a.toUpperCase
I think it's far too clever. Beyond the method call, another thing that appears to be hidden here is the creation of the target list to which the uppercase letters are being stored. How many memory allocations are there in this statement? What if the body of that loop is conditional and we don't know how much space we need in advance? Yes, it's nice to look at, and I can see how it might be exciting to understand that for the first time, but... everything that it adds seems to be completely unimportant, but the operations that much be happening have been hidden from view. Great, we've saved a bit of typing, but in the process, we've lost a lot of understanding about how our program behaves.Then there are other simple things. I really enjoy that curly brackets are mandatory on looping constructs in Go; I noticed that Scala has the feature that you can leave them off and it only includes the next statement. I find that feature profoundly annoying and prefer that it does not exist. I really like the way the tooling enforces formatting. I really like the way that Go is militant. When I write Go, I feel like I'm at work assembling an information processing machine; I don't feel like I'm writing poetry. I don't want to feel like I'm writing poetry. I'm happy to be making information machines, because that's the honest truth of the craft. The poetry lies in what those machines do; the art is in the output. To me, writing a boring program whose code is very clever is like writing a boring poem in beautiful calligraphy and arguing that the beauty of the calligraphy makes the poem better.
So that's why I went with Go, and not Scala. Of course, there are things I wish we had; specifically operator overloading and something akin to generics, the former we almost certainly will never get, while the latter remains an open question. A part of me misses having properties or Python's decorators, but... these are features that I've found can easily create maintenance problems; features that have caused trouble for me in the past.
Go, of course, has its warts (some would argue that the language made entirely of warts), but while learning the language I always got the feeling that the things that were annoying were good for me; that the warts were like being told to eat your vegetables. After a year and a half of programming Go regularly, I've found that to be largely true. My old code is much easier for me to go back to than the equivalent in other languages, and I've found my Go projects to be very easy to maintain, overall.
Go's code is the right level of terseness for me. It's far, far shorter than equivalent Java code and it's very clear. To me, elegance is clarity. To others, elegance is terseness. It's all a matter of opinion. I think you'd be hard-pressed to find someone that chose Go over Scala because of the merits of what can be built with one tool over the other; I reckon they're quite comparable in this regard.
Speaking as someone with a bachelor in fine arts, this rings very true for me. In Dutch, when an idea isn't working out, we have a saying: "het komt niet uit de verf," which literally translates as "it doesn't leave the paint."
With the exception of certain modern and contemporary art pieces, a painting is about what is being depicted, not about the fucking paint. The paint matters of course, but it shouldn't take the spotlight (again, ignoring self-referential topics like paintings about the experience of paint).
Maybe, at some point, if you have spare time, I recommend that you give a modern language like Scala, Haskell or ML/Ocaml/F# that don't distinguish statements from expressions a second chance.
On the other hand, Scala gives me a completely different feeling: when reading the docs and samples, I often ask myself:
How can I mentally parse this?
It's nice that I can abbreviate some common constructs (when writing), but when reading code, how can I tell which concepts are being used? How do I look up these operators when they could come from anywhere (global, first operand, second operand, implicit conversion, etc.)
How do I know when parentheses, dots, curly braces, are mandatory or optional? Could the compiler misunderstand me in complex situations? Where does this construct really end if so many things are optional? At least F# uses indentation, so I know the compiler will warn me if I wrote something that is not quite right according to the precedence rules.
There are too many implicit things going on, how do I know which meaning of _ (underscore) is meant here?
The poetry lies in what those machines do; the art is in the output. To me, writing a boring program whose code is very clever is like writing a boring poem in beautiful calligraphy and arguing that the beauty of the calligraphy makes the poem better.
To me, elegance is clarity. To others, elegance is terseness.
Its like a Swiss army knife with a million blunt obscure tools rather than 5 useful sharp ones, or a crazy girlfriend who has three violent ex husbands who keep coming round to your house and lives with a crackhead.
Go is a trip to your Volvo dealer - uneventful but you get what you want at the end of the day and get where you want to go and when you're done, you're done.
It's comprehensive, stable, capable, reliable and understandable.
>> is terribly complicated
EJB's are complicated, the JVM isn't complicated.
>> doesn't really give any benefits over anything else
Check the list of companies and people using the JVM and languages implemented on it.
People smoke. It doesn't mean its good.
I don't write webapps, but if I did, I would probably choose Clojure or Haskell or Python. You should learn to understand that by doing so, I am not insulting you or your language of choice.
Yeah, specifically I see it as part of the "worse is better" school of design, of which I am a great fan. A sort of 'cat -v' aesthetic. I find that working with a language, or on products, that have embraced that mentality is just so much... calmer. It puts me at ease, for lack of better terminology.