Perhaps "Go" is the new Visual Basic
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

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




'Micah' on Thu, 12 Nov 2009 10:32:20 GMT, sez:

The current version of VB.Net has type inference, so:
Dim s = ""
is valid, and declares s as a string. Unfortunately I've run into programmers who haven't kept up with the language and just assume Option Strict is off and that s is declared as an object.



'lb' on Thu, 12 Nov 2009 10:43:33 GMT, sez:

cheers Micah.
Also i fixed my invalid example of VB syntax (and shot two of my editors for letting it through) ;-)



'Eric' on Thu, 12 Nov 2009 12:49:05 GMT, sez:

I believe the tab-only output of gofmt is probably going to change. It's too lame to stand for long. But in any case, your own code doesn't have to use tabs.



'Jonathan Allen' on Thu, 12 Nov 2009 13:52:12 GMT, sez:

You are not alone, I thought I was looking at basic as well.



'John' on Thu, 12 Nov 2009 14:18:43 GMT, sez:

Yea, let the tab vs. space flames begin again :)



'Erez' on Thu, 12 Nov 2009 14:56:04 GMT, sez:

Javascript. Not VB.



'Annon' on Thu, 12 Nov 2009 16:50:06 GMT, sez:

This syntax still works in VB for declaring a string:

Dim S$
S = ""



'David Arno' on Thu, 12 Nov 2009 17:57:05 GMT, sez:

No version for Windows and the awful K&R braces as the official layout style. Perhaps Stop would be a better name...



'PhiLho' on Thu, 12 Nov 2009 18:12:25 GMT, sez:

I was amused by your conclusion... :-)
Personally, I prefer tabs, but I can live with spaces. As long as the editor is smart about them (mine is).

Funnily, I am discovering Nimrod, another (relatively) new programming language. http://force7.de/nimrod/

It has some similarities, and some opposite choices (case insensitive, using spaces only for indentation, which define blocks like in Python).



'Simple' on Thu, 12 Nov 2009 21:08:35 GMT, sez:

"Simple" is the new VB, not GO.



'Pies' on Fri, 13 Nov 2009 00:01:06 GMT, sez:

Hah! Google says tabs win :P



'Jz' on Fri, 13 Nov 2009 01:52:24 GMT, sez:

A problem with tabs:

It's hard to type tabs in a browser.

And web-based IDE's are the future.



'Giuliano Lemes' on Fri, 13 Nov 2009 08:30:59 GMT, sez:

I Swear you, "Perhaps "Go" is the new Visual Basic" was my first thought when i read about "Go"...



'DominicCronin' on Fri, 13 Nov 2009 19:44:59 GMT, sez:

Come on Leon - that is so totally VB. (The tabs thing, that is) "There will be no holy war. We will prevent this by arbitrarily choosing the wrong option."

10 million morts can't be wrong. (But these days, they're all writing PHP!)



'Steve Campbell' on Mon, 30 Nov 2009 16:09:36 GMT, sez:

I thought that in language circles it had been concluded that braces (or vb begin-end) were a bad idea, and Python had it right all along (readability is served better by the indentation than by the braces).




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. But the right to delete any post for any reason is reserved. Don't make me do it. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Who reads this legal bit anyhow?

TimeSnapper is a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

TimeSnapper won last year's Developer Competition at Larkware.com, and is used by over 10,000 people.

Articles

JSON Query Languages: 5 special purpose editors JSON Query Languages: 5 special purpose editors
What then, is b? What then, is b?
SQLike: A simple editor SQLike: A simple editor
Yet Another BizPlan Generator. Yet Another BizPlan Generator.
HOT GUIDS: A hot or not site for guids HOT GUIDS: A hot or not site for guids
How does life get better? One tiny hack at a time. How does life get better? One tiny hack at a time.
24 things to do, and 100 things *not* to do (yet) for building a MicroISV 24 things to do, and 100 things *not* to do (yet) for building a MicroISV
Venture capital won't kill Jeff Atwood, it will only make him Jeffer. Venture capital won't kill Jeff Atwood, it will only make him Jeffer.
A handy workflow image for newbie mercurial users A handy workflow image for newbie mercurial users
Fractal Feedback, a diversion into recreational programming Fractal Feedback, a diversion into recreational programming
Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe. Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe.
Suggested User Experience Improvements for DiffMerge Suggested User Experience Improvements for DiffMerge
SQL Style Extensions for C# SQL Style Extensions for C#
The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's
Sysi: the ultimate administrators toolkit Sysi: the ultimate administrators toolkit

Archives .: secretGeek :: Complete Archives
TimeSnapper -- Automated Screenshot Journal TimeSnapper.com    
Version 3.3: true productivity boost

Next Action NextAction
Managing the top of your mind

World's Simplest Code Generator (html edition) World's Simplest Code Generator

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed How to be depressed
You are not inadequate.



Recommended Reading

The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink

Aggregated Links

proggit
dzone
hacker news
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
weekly link post

LinkedIn profile
LogEnvy - event logs made sexy
ShuffleText - fuzzy search for .net
PC Smart Buys - Computer Hardware in Australia
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy