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
- Effective Go
- Go Tutorial
- 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).
|