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

A face-melting DSL that allows programming ON the iPhone (and iPad) A face-melting DSL that allows programming ON the iPhone (and iPad)
The secretGeek Disaster Recovery plan The secretGeek Disaster Recovery plan
Save KNVTn! Before it's too late Save KNVTn! Before it's too late
The Ultimate Agent of WERF Destruction The Ultimate Agent of WERF Destruction
The new prisoner's dilemma The new prisoner's dilemma
Original Premise for a road movie Original Premise for a road movie
What's a better game than Devshop? What's a better game than Devshop?
DevShop: The Cool Game that Makes Development Look Fun DevShop: The Cool Game that Makes Development Look Fun
Should be purple Should be purple
Kitchen Agile Kitchen Agile
Perhaps Perhaps "Go" is the new Visual Basic
zen-coding: turn those CSS selectors upside down zen-coding: turn those CSS selectors upside down
Debugging: It's all about finding Albuquerque. Debugging: It's all about finding Albuquerque.
The Real-Time online JQuery Editor The Real-Time online JQuery Editor
HTML5, a 3 minute guide HTML5, a 3 minute guide
Developer Codpieces Developer Codpieces
Agile for one: The Personal Story 'Wall' In Action Agile for one: The Personal Story 'Wall' In Action
Never work with thick people. Never work with thick people.
Cosmo: project status panel Cosmo: project status panel
Windows Search in Japan Windows Search in Japan
Project Management Zen Project Management Zen
Continuous Integration, Plugins and Going Too Far Continuous Integration, Plugins and Going Too Far
The Rules of Stand Up The Rules of Stand Up
Sydney International Airport: Stupid, Criminal, or Criminally Stupid? Sydney International Airport: Stupid, Criminal, or Criminally Stupid?
God No! ...The ReBuilder God No! ...The ReBuilder
Matt, The Office Mortar Matt, The Office Mortar
'Outlook style' rules for Subversion 'Outlook style' rules for Subversion
Really deep linking: Url + regex Really deep linking: Url + regex
hExcel -- A Hexagonal Spreadsheet hExcel -- A Hexagonal Spreadsheet
Is the remote control a thing of the past? Is the remote control a thing of the past?
The Utterly Thorough Guide To Awesome Application Compatibility on Windows 7. The Utterly Thorough Guide To Awesome Application Compatibility on Windows 7.
Astounding Hyperlinked Noticeboard Astounding Hyperlinked Noticeboard
Three Questions About Each Bug You Find Three Questions About Each Bug You Find
Recursing over the Pareto Principle... Recursing over the Pareto Principle...
Sometimes, The Better You Program, The Worse You Communicate. Sometimes, The Better You Program, The Worse You Communicate.

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
Reginald Braithwaite
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink
Joel Spolsky
Des Traynor

Aggregated Links

programming.reddit.com
dzone
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
n links today
new and notable
morning coffee
learning .net
weekly link post
(my del.icio.us account)

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

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