280 points · by zemo · 14y ago · 195 comments
This made me laugh, thank you.
Then again, maybe I'm reading too much into it. For the record, I think Haskell is a strictly superior choice to Go, so I'm what he would probably call "gray-bearded" :P. (And I'm certainly working on a beard, even if it shouldn't be gray any time soon.)
no, you got it. It's not really meant to be a criticism of Python itself, it's just behavior that is common among 20-something web developers, which is representative of some areas of the industry, and is specifically the target audience for the post. You know, the kind of developer that is advanced enough that they can build non-trivial projects, but not experienced enough to have wisdom forged in the furnaces of years of industry experience (that's ... me and a lot of other HN users). The same type of attitude can be found in all languages and isn't specific to the Python community; the specific swipes at other languages are just what you get if you apply that attitude to Python. Judging people by the tools they use is a pretty useless metric.
>For the record, I think Haskell is a strictly superior choice to Go
I'm pretty sure it's the best programming language, that's why I put them in the gray-beard category. Or maybe it's OCaml or some Lisp dialect; it doesn't really matter. It's even why I further apologized to Dons and acknowledged that Haskell programmers tend to be able to solve harder problems than other programmers I know, but even after I twice acknowledged the superiority of Haskell, he basically just looked at me and said "you're a stupid idiot, and by the way, look at how many numbers I can compute with my superior Haskell program that runs on a lot of machines". Uh, ok, that's cool... I guess.
But every time I sit down with Haskell programmers and they explain to me how elegant their code is, I just don't really care. It's not what makes me interested in computer programming. I don't really care to use the best programming language; I really only care to make the best programs. PHP (and other shit technologies) have shown us that you don't need to understand monads to make people happy.
A friend of mine, who is a very strong programmer that I have a tremendous amount of respect for professionally, once showed me how to use Coq to prove that multiplication is commutative. I found that very boring, and it didn't make me want to learn Coq. Mind you, I spend between 40 and 60 hours a week working with software. I'm in it because I like to build things that are useful to people, and I think software is a great creative medium. I think that's a fairly common attitude.
Every time I say the name Haskell I am sorry for it, because every time I say the name Haskell I am met with bitter condescension. It makes me sad that despite talking about having experience with seven programming languages in my post, or mentioning having built a variety of things that are very different, Haskell programmers consistently treat me like I am a stupid person. So I'm glad you're not like that, and I'm glad that you understood I didn't mean to dismiss Haskell on technical grounds. Thank you for your comment.
Care to elaborate?
I do run into a lot of egos but these don't seem much different from the types I see posting comments like this on Hacker News. And a lot of Python people have picked up Node or Go these days, so I wouldn't be too sure that you weren't damning a significant part of your own favorite community here.
Concurrency support is possible in Python, without gevent-style monkey patching (or callback madness). Have a look at concurrent.futures and http://www.dabeaz.com/coroutines/index.html. It really needs a lot more work before it's part of the language's DNA, though. Also, pypy needs much wider adoption as quickly as possible, to address the speed problems (and its STM branch holds huge potential).
For me, Go's major shortcoming is its community's lack of focus on readability as compared to Python.
Can you be a bit more concrete here? Because whether you like the code styles enforced by gofmt and the compiler itself or not, Go is the most consistently readable language I've ever used (once you adapt yourself to the language). IMO, this seems like an especially odd problem for someone to have with Go.
I think we, as a profession, have a tendency to focus on what's "easy" (syntax and constructs we're already familiar with) to the exclusion of other, potentially more important factors. I am and have been guilty of this myself, so I'm not claiming any sort of sainthood, just making an observation.
Often people pick on the use of single-letter variable names as "unreadable." This is mostly a matter of keeping the code light on the page, as they put it. If you're dealing with a package centered around Foo, especially methods on same, it's customary to just abbreviate it to f. That clashes with a lot of people's instincts even though, once you get used to it, it works well.
"Once you get used to it" is key -- this is true of any language with substantially new or different syntax/semantics from what a programmer is used to. All else being equal, familiarity ought to be orthogonal to merit; the mere presence of a learning curve ought not be a deal-breaker.
Anyway, Go is one of the most readable languages I've ever seen, given that it is not a scripting language. Among other things, type inference and literals make the code very clean, to the point where you can in short order read the standard library code and expect to understand it.
For example there are issues with scope (what happens when I need a second or third "f" variable" and maintainability too (6 months from now I have to remember if "f" stands for "foo" or "file").
However, the built-in arrays, slices, and maps (which are parametrically polymorphic) seem to have covered all the cases where I need parametric types so far. Maybe I'm just lucky or haven't written enough lines of Go but it seems like an 80/20 sort of feature in the presence of the built-in maps.
Idiomatic Python: http://python.net/~goodger/projects/pycon/2007/idiomatic/han... (doesn't cover a number of important things)
When comparing the two, I'm not impressed with Go.
I know that I frequently kick myself in Python when I typo a name somewhere, and everything dies far beyond where I made the mistake because it goes along happily storing something into that typoed variable, and then when I read it later it has the wrong value, and it takes me a while to trace back and find where I made the typo.
that was deliberate. There has been a glut of "introduction to Go" blog posts, and the documentation for introductory Go from the Go Team is quite good, so I didn't feel the need to author another introductory post. Most of the stories about why people use Go are bigger, established companies, so I wanted to show how it was perceived by a different audience. I don't remember where I saw it, but someone talked about using Go in contrast with Java, and the overwhelming reaction was "that's cool but I'm a Python programmer, I'm curious what Python programmers think", so I was just trying to give it that angle.
>Have a look at concurrent.futures
but this is part of the problem: it's a library. Concurrency deserves language-level support. Adding concurrency at the library level is like adding an object system at the library level.
I have seen more Python/Ruby programmers interested in Go than Java or C++ programmers. Rob Pike seems to have observed it as well.
I was asked a few weeks ago, "What was the biggest surprise you encountered rolling out Go?" I knew the answer instantly: Although we expected C++ programmers to see Go as an alternative, instead most Go programmers come from languages like Python and Ruby. Very few come from C++.
http://commandcenter.blogspot.in/2012/06/less-is-exponential...
Which is not a problem at all. Lisp and Scheme have been doing that since forever.
His arguments have much to do with what the compiler doesn't know, which could potentially be solved with macros.
I absolutely agree, which is why I said it needs more work.
Source code changes could be saved as log-structured patch files, which could then be thrown away or applied to the source tree as desired. One could also steal some ideas from the Smalltalk Change Log tool by adding similar editing, search, and filtering commands.
With tools like this, one could recompile for "interpreted debug mode," have complete visibility and control of runtime state to debug a problem, then take the resulting patch file and apply it to the source tree. It would be a best of both worlds scenario -- all the enhanced debugging of an interpreted runtime with the type safety and speed of compiled code.
At a Go talk he did, I raised the idea with Russ Cox of having a "repl" package that would allow one to instrument a running program with a live REPL to do debugging and development on it.
The reflect package is powerful enough to make some of that relatively straightforward, but one major problem is that Go can't construct new types at runtime. Another challenge would be dynamic linking of new code -- because the Go toolchain doesn't support dynamic linking there would seem to be no hope of say entering anonymous functions on the REPL.
Unless one builds a full Go interpreter -- but who wants to be in the business of maintaining a fully compliant Go interpreter that can interoperate with the Go runtime?
Still, calling existing functions and banging on variables would be pretty useful.
The current implementations can't. I don't see any reason why one couldn't. In any case, I don't think that's such a big deal. One just goes from completely seamless interactive coding to mostly seamless interactive coding.
> Unless one builds a full Go interpreter
That is precisely what I was proposing. (Are you implying some sort of hard VM/interpreter dichotomy? I've met some people who implement VMs who think this is somewhat arbitrary.)
>but who wants to be in the business of maintaining a fully compliant Go interpreter that can interoperate with the Go runtime?
There would be no need to interoperate at all with the current Go runtime. One would have to have their own Go runtime, however. As an alternative, one could just target an emulator with no optimizations, then use debugging information and dirty tricks to map the new code with the old state in an entirely new process.
package main;
import (
"fmt"
"net"
)
func main() {
hosts := []string { "www.google.com", "www.example.com", "www.python.org" }
c := make(chan string)
for _, h := range(hosts) {
go get_ip(h, c)
}
for i := 0; i < 3; i++ {
fmt.Println(<-c)
}
}
func get_ip(host string, c chan string) {
addrs, err := net.LookupHost(host)
if err != nil {
fmt.Println("Host not found:", host)
c <- host + ": <error>"
return
}
c <- host + ": " + addrs[0]
}Lack of exceptions means the deeper the call stack the higher the proportion of error handling code relative to a normal (non-exceptional) code path.
For example, if you decide to refactor some code from a bigger function into its own smaller function then all error handling code have to be repeated twice (first in the child function then in the parent that calls it). It introduces unnecessary clutter and boiler-plate.
Exceptions allows you to limit the error handling to two places: the place where you detect an error and the place where you are ready to handle it and not throughout the whole call stack.
Language with a builtin garbage collection can (should) afford a builtin exception support.
I like that Go excludes some language features on purpose but in the case of exceptions Python has its merits.
However, I was interested to learn that Google style guide for C++ recommends not using exceptions. I don't know C++ (shame), but at least some of their reasoning is applicable to Python as well:
For example, when you start raising an exception in a Python function, you have to check its callers, whether they (or their callers) handle it. And vice-versa—when a Go function has “expected” error in its signature as return value, it's very obvious what you need to handle when you're the caller.
“Expected” error as return value also encourages single responsibility principle, I suppose. E.g., for a function that decodes JSON, bad syntax is “expected” error, the rest is a reason to panic().
I'm not sure if I get your example with refactoring, but it may be a case when you use panic() in inner function, recover() in outer, and return an error as usual.
That said, I've never actually used Go yet, so it's just theorizing.
[0] But then my Python code that (to me) looks more or less “solid” appears to contain a comparable amount of error handling lines, so not sure if it's a good metric.
The insight to async I/O is that this server, for this I/O bound task, will perform as well as your GOMAXPROCS example:
require('http').createServer(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
But it's a lot simpler. You don't need to bolt on parallelism when you don't actually need parallelism. There are valid reasons to use Go, and there are valid complaints against Node. I don't see any of either here.This was a great pity because I think it probably is one of the best languages ever made and didn't get the take up it absolutely deserved.
Like for example show me how to suspend the HTTP request and wake it up later when you receive a message back from some long running process.
Or simpler: show me how to start a long running async task from a request handler.
Will it?
Luvit, which is implemented on Node's libuv outperforms Node in the trivial case because of higher lua performance (and lua->c interop performance).
No, it doesn't scale on multiple CPUs if you don't use the 'cluster' package.
There's an awful global lock on the actual execution of python code, but unless the problem is performance or contention worrying about it is premature.
"As a Django developer, there wasn’t a straightforward and obvious way to just do things in the background on a page request"
I started thinking, "um, django produces http responses, you can only respond once...".
Clearly, from his gevents example, he's looking to do things that take time, and wants to do them as concurrently as possible, then send the whole response at once. But if he really doesn't want the user to wait, then this is not something you should be doing in a webserver anyways. You really should be building that into the front end javascript, and let it handle all the async data grabs from small, fast, cacheable web requests, then redraw the page as the data comes in.
var cluster = require('cluster')
, http = require('http')
, os = require('os')
if (cluster.isMaster) {
os.cpus().forEach(cluster.fork)
} else {
http.createServer(function(req, res){
res.writeHead(200)
res.end('Hello world')
}).listen(8000)
}In any case, it's still not an apples to apples comparison. The node.js example forks separate processes that share nothing, while in the Go example it all runs in one process so the HTTP handlers can communicate with each other via channels or other shared data structures.
The documentation has the primary goal of explaining how things work, not being the canonical style guide.
Take a similar example from the Go documentation:
const NCPU = 4 // number of CPU cores
func (v Vector) DoAll(u Vector) {
c := make(chan int, NCPU) // Buffering optional but sensible.
for i := 0; i < NCPU; i++ {
go v.DoSome(i*len(v)/NCPU, (i+1)*len(v)/NCPU, u, c)
}
// Drain the channel.
for i := 0; i < NCPU; i++ {
<-c // wait for one task to complete
}
// All done.
} http = require 'http'
server = http.createServer 'localhost', (req, res) ->
res.writeHead 200
res.end 'ok'
app = server.listen 3000 os.cpus().forEach(cluster.fork)
Should be: os.cpus().forEach(cluster.fork.bind(cluster)); var fork = require('cluster').fork
Cluster methods keep a reference to the main object inside the module, see https://github.com/joyent/node/blob/master/lib/cluster.js#L4...That could have been written better. Thanks for the feedback.
> Haskell I would argue against being an industry language
FYI, the problems the Haskell community has been working on are things like scalability, performance and safety because they're critical to industrial problems. Toy approaches don't work at the scale we operate at -- you need real computer science.
You want 1,000,000 Haskell threads in your app? You've got it. Want to write numerical models that compete with C++ code, in a fraction of the development time? Done. Want to guarantee the app won't crash? Solved. Run models over 10,000 cores? It happens.
Because we put the work in.
---
/me wanders back to a multi-million line Haskell codebase running systems in 25 countries, processing billions a year in financial transactions.
This is not fair on Haskell but that is what people think and that really is the issue that Haskell has to overcome.
Curious... Can't be a bank, too conservative. Hedge fund? I know Jane Street love their OCaml so functional does have a place in that world. But 25 countries? You'd have to be huge.
Reality and PHP would disagree for 90 to 99% values of "you".
Hope the codebase runs well, because that's the bank I use in Singapore ;-)
Has you/anyone written something about how Haskell got picked for the task by that particular bank? Is the language used at other financial type businesses? I've heard some firms use Ocaml.
Is there some sort of Go package manager? How does all this shit work?
Yes, the Go tool comes with package-management capabilities. "go get labix.org/v2/mgo" will download the very excellent MongoDB driver mgo, for example.
From https://github.com/bmizerany/pq/blob/master/conn_test.go:
func TestExec(t *testing.T) {
db := openTestConn(t)
defer db.Close()
_, err := db.Exec("CREATE TEMP TABLE temp (a int)")
if err != nil {
t.Fatal(err)
}
r, err := db.Exec("INSERT INTO temp VALUES (1)")
if err != nil {
t.Fatal(err)
}
What is it exactly that you tried and failed? Because looking at conn_test.go the API is dead simple and pretty much like any other db API of this kind.You will get an answer quite fast.
It's not really that hard. I just latch on to a broker that I'm already using elsewhere in my stack (Redis). Celery makes it super simple to run a command in the background.
What's more, the strategy of just spawning a thread to do with async processing doesn't scale. Once you hit the limit of requests that a machine can process, you'll need a distributed work queue anyway. Or do Go coroutines run through some sort of managed execution queue?
There's way too much focus today on new languages that are designed to work on just one machine, and scale there – as if vertical scaling was the true problem we all face, when in fact, it's not. /sigh
Of course if speed is important, you should ditch CPython anyway.
A language is just one tool in your toolset. I love using Go very much, but I would recommend learning on Python. There's much more literature out there, more people you know will know it, and if you are looking for work, there are effectively zero entry-level programming jobs in Go.
The reason you keep hearing about Go is that it just very recently hit its 1.0 release, so it it a comparatively new language, and it's just a topic of conversation. Talking about Python isn't really newsworthy in the same way, because for most people, it's just a fact of everyday life. Go, however, is this new thing that's a little mysterious, that most people haven't tried yet.
Have you ever heard the phrase "you can never really know yourself until you know others"? Well, that's true of programming languages, too; learning new languages can help you to write better code in a language you were already familiar with. Learning new languages is great practice for any programmer.
But to start, I would just stick with Python and write some things that make you happy. That's the most important part; to figure out how to use code to make yourself happy. Which language you use is really just an implementation detail.
Actually, not without going out and meeting new people. I'm a physician, so meeting anyone who knows anything about IT is quite challenging. And the helpdesk folks at the hospital usually aren't in the mood to troubleshoot those kinds of errors!
https://groups.google.com/d/topic/golang-nuts/bP6_KD51ed4/di...
I'm sure Go will mature here and the defaults will evolve along with that. Whether that will take years or not is up for debate but at least it's a possibility and doesn't cost the programmer anything other than a recompile if they start with careful use of goroutines today.
.. until you set runtime.GOMAXPROCS(runtime.NumCPU())
Is it too early to switch from Python/Ruby to Go? Maybe it would be better to wait for Dart.
I known that Mozilla and MS won't support Dart however they also don't support Go.
narrows eyes...
/nerdhate
Sure, the go example is shorter, but the JavaScript version reads much nicer (at least to me).
Third party libs still are more uneven, but that is not much different from Python.
It's a usability thing. If you make something easier to use, more people use it; as a result, node.js has introduced the topic of nonblocking i/o in a way that other technologies have been unable to do. It also allows you to share code between the client and the server, which may or may not matter, depending on your project. And for a lot of developers, node.js means using a language you already know.
The guys at Kitchen Table Coders do a workshop where they make a physical game paddle with an arduino, and then hook it up to a node.js server, so that two people can play pong with physical controllers in their browser. They're able to teach that workshop in a day. I think that speaks volumes for types of things that you can do with node.js, and its mass appeal.
But, like I said in the article, I find that node.js becomes disorganized quickly, and I just plain don't enjoy debugging JavaScript. On top of that, if you need to do CPU-bound work, node.js basically forces you to create an isolated process and perform i/o with it, but now you have an OS process for each of these instances, whereas in Go, creating a goroutine and communicating with it over channels is much more lightweight. Node.js has its merits, and I don't mean to say "nobody use node.js ever!", I just don't like using it.