Perhaps "Go" is the new Visual Basic

As a cursed "magpie developer" I can't help but read up on every new thing I hear about.

And the latest shiny thing is Google's "Go" language. (Google Wave is sooo last month).

One of the authors is Ken Thompson, creator of Unix and the 'B' Language (pre-cursor to C).

I'm fascinated by little details, and here's one that I like:

If

In Go a simple if looks like this:

if x > 0 {
    return y
}

Mandatory braces encourage writing simple if statements on multiple lines. It's good style to do so anyway, especially when the body contains a control statement such as a return or break.

No parens required for an if... but braces are required. This is the opposite of other languages, but makes great sense to me!

It's kind of like Visual Basic, if anything.

In fact, there a whole bunch of things that are reminiscent of Visual Basic:

var s string = "";

This is the var keyword, followed by the name of the variable, followed by its type, followed by an equals sign and an initial value for the variable.

This is more than a little reminiscent of VB:

Dim s as string = ""

Although with GO:

we could go even shorter and write the idiom

s := "";

Similarities continue...

Functions are introduced with the func keyword

Much like the way the 'Function' keyword is used in Visual Basic, hey?

And nothing like C-family languages that begin a function declaration with the type being returned. (Personally I wish they'd gone a ML-style choice of keyword, and used 'fun' for function.)

How is the return type shown? Almost exactly like VB...

GO:

func Area(side int) int {
   //code goes here
}

VB:

Function Area(byVal side as Integer) as Integer
     'code goes here
End Function

The similarities end approximately there. Did I miss others?

(Note that the similarities with Javascript are just as pronounced, and just as superficial.)

Another superficial detail I like is that semicolons act as separators, not terminators.

The coolest little language-nerd item for me is that capitalization is used to indicate scoping.

In Go the rule about visibility of information is simple: if a name (of a top-level type, function, method, constant or variable, or of a structure field or method) is capitalized, users of the package may see it. Otherwise, the name and hence the thing being named is visible only inside the package in which it is declared. This is more than a convention; the rule is enforced by the compiler. In Go, the term for publicly visible names is ''exported''.

That is a beautiful little detail. I love the simplicity of this approach. If a language is going to be case-sensitive, then it should *do something* with the casing.

But superficial details aside and onto the important stuff...

Indentation

We use tabs for indentation and gofmt emits them by default. Use spaces only if you must.

Sorry Google, I'm afraid Go is not for me.


References

  1. Effective Go
  2. Go Tutorial
  3. Language Specification
 

My book "Choose Your First Product" is available now.

It gives you 4 easy steps to find and validate a humble product idea.

Learn more.

(By the way, I read every comment and often respond.)

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.