Go’s type syntax

The Go programming language’s main claim to fame is it is developed by Unix god’s Pike and Thompson. Go is an attempt to be a better system’s language than C. However, the type syntax is just weird enough to be off-putting. Pike explains why in this post. IMHO, any statically typed language developed in the 21st century should have type inferencing. Then you wouldn’t need to worry so much about cluttering your code with unreadable type syntax because there would be so little of it. The solution is to go back to OCaml and rewrite the runtime to support multi-processing [edit]. Unfortunately, the cheese-eating surrender monkeys in charge of OCaml refuse to ever add multi-processing support, so someone else will have to do it. How hard could it be? They added it to Haskell, which has a much more sophisticated runtime. Anyway, Go needs type inferencing. Someone please get on that.

Advertisements

3 comments

  1. Bartosz Milewski

    I always considered C’s declaration syntax insane. All modern languages (Scala, Chapel, X10) use the left-to-right declaration syntax. I’d side with Pike on this one.

    With the addition of “auto”, there will be a modicum of type inference in C++0x.

    As for OCaml, it actually has multithreaded support (see my blog: http://bartoszmilewski.wordpress.com/2009/03/10/futures-done-right/). What you are alluding to is the lack of multicore support. They are working on it, however. See http://www.algo-prog.info/ocmc/web/.

  2. Pinku

    “Beauty is in the eye of the beholder” applies to language syntax, too. To me, the keyword “func” muddles the syntax. He gives this example of a complex function pointer. To me, the Caml syntax is more appealing, but I can’t justify it rationally.

    Go: f func(func(int,int) int, int) func(int, int) int
    OCaml: f : (int->int->int)->int->(int->int->int)
    Scala: ((Int,Int)=>Int,Int)=>(Int,Int)=>Int

  3. Bartosz Milewski

    I think there’s more to syntax that meets the eye. For instance, C++ syntax is very hard to parse. You might say, who cares! But because of this difficulty, there are far fewer tools to help the C++ programmer than, for instance, in Java or C#. In C++, the simplest refactoring: changing the name of a variable, is virtually impossible to automate.

    Also, when you design a language, every syntactic choice limits the field for later choices. I think this is the main reason modern languages move away from C declaration syntax.

    Notice one think about your examples–the type of the return value is always to the right of the declaration. This is important for parseability and readability.

    Also, both Scala and Caml put the type to the right of an identifier, as in:

    type complex = { re:float; im:float };

    You complain about the keyword func, but you are used to keywords like class or struct that play a very similar role–introducing a new declaration.

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