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.

About these ads

17 Responses to Why Go? Use Racket!

  1. Josh says:

    channle?

  2. [...] my previous post Why Go? Use Racket!, I pointed out that CSP facilities provided with the Go programming language also exist with [...]

  3. asdf says:

    Can’t click on “(Here is an example.)”

  4. Me says:

    CSP = Communicating Sequential Processes

  5. Me says:

    Racket was formally known as PLT Scheme, not DrScheme

  6. A bag of ricks says:

    What I heard was: I don’t want to use go, because I don’t want to learn about type system and crucial part of how stuff works in it.

    Whine less and don’t expect static language people to pick a dynamic type language just because of some minor/inferior features.

  7. Allen says:

    I’m not sure I understand; your complaint with Go has to do with efficiency, so why use a language which you admit is less efficient than Go? Why not switch to some other fast concurrent language like Haskell, Rust or ML (all of which have pattern matching, btw).

    • Wang Yi says:

      That is because Racket provides similar concurrent programming facility as Go. However, I changed my mind during recent months, as I had been developing a large scale machine learning system using Go, which makes me feel that high performance is really critical. Given Go authors have been successfully improving the runtime performance of compiled-code, I still have to program some computation intensive parts of the system (mostly Gibbs sampling) using C++ and make the Go program to call C++ routines. I believe Haskell, Rust and ML are superior than Go in many aspects, but I see Go on a track of fast performance improvement.

    • cxwangyi says:

      You are right. Haskell is a good choice. I am not sure ML is as good as Haskell from the perspective of concurrent programming. Anyway, I am lazy to remember syntax things, and among all Lisp-style languages Scheme has the most concise syntax. That is the reason I always put an eye on the development of Scheme.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 28 other followers

%d bloggers like this: