Why Go? Use Racket!

Go Racket C/C++
channel channel blocking queue
goroutine thread light-weighted thread
select sync epoll/kqueue

I had expected Go could save us from the heavy burden of programming complex network applications (Web servers at frontend and RPC server at backend). However, I am disappointed.

It is true that Go’s concurrent programming facilities (goroutine, channel and select) works great and can remove all the asynchronous RPC calls and chains of callbacks.  For how Go can do this, you might want to watch Rob Pike’s talk, Go Concurrency Patterns, on Google I/O 2012.

However, the type system of Go is so complex; programmers need to know all the details about the implementation of standard types, before they can use them correctly.  For example, it is efficient to pass a channel as the parameter of a function all, because a channel in Go is as simple as a pointer to the channel data structure implemented in C.  It is the same for map and some other types.  But it is inefficient to pass an array or struct; instead, we should pass pointers to these types.

Another example is about interface, the base of polymorphism in Go. The reflection mechanism of Go makes it convenient to judge the real type referred to by an interface variable. But we are not allowed to convert the interface into that type. Instead, we can convert it into a pointer to that type.  This is because an interface variable is a pair of two pointers, one points to the real variable, and the other one points to a method list.

Given the pros and cons of Go, what I want is a language, which has a comprehensive type system and implements the CSP (communicating sequential processes) model. Also, I hope this language is open source (as Go), has a Web based third party libraries creation and publication system, and can express complex computing logic in an intuitive way.  I am feeling lucky that I found one — Racket.  Racket was formerly known as PLT Scheme.  I used it to learn Lisp programming 8 years ago.  I won’t know it was renamed if my old friend, Yin, do not tell me.

Racket is open source. It is an enhanced version of Scheme with macro and pattern matching functions. So it is much more powerful than C/C++/Java/Go in expressing complex algorithms. For example, using C/C++/Java, a multi-page Web-based wizard would correspond to a set of HTTP handlers, each for a page. However, using continuation, a well-known programming construct in Lisp, we would need only one handler! (Here is an example.)

Racket has hundreds of third party libraries, including network programming and Google protobuf, published on PLaneT.  And yes, Racket also implements CSP as Go, as shown in the table at the beginning of this post.

P.S. As noted in this post, Racket programs build and run much slower than Go programs.