Go, Programming with Google



Google has released a new programming language called Go. Google wants to offer a couple of benefits from their language: fast compilation, easy analyzing of dependencies, static types that nevertheless feel more lightweight compared to some other languages, and multi-core machine support.

Go is not (not yet anyway) an approved official Google-internal language, but apparently more of an experiment for "adventurous users", started in September 2007 by Robert Griesemer, Rob Pike and Ken Thompson. The motivation for a new language is explained at the Go site:

Go is an attempt to combine the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language. It also aims to be modern, with support for networked and multicore computing. Finally, it is intended to be fast: it should take at most a few seconds to build a large executable on a single computer. To meet these goals required addressing a number of linguistic issues: an expressive but lightweight type system; concurrency and garbage collection; rigid dependency specification; and so on. These cannot be addressed well by libraries or tools; a new language was called for.



Why doesn't Go offer generic types? Google explains that the language does not offer them yet, but that they may well be added at some point. The site says:

Generics are convenient but they come at a cost in complexity in the type system and run-time. We haven't yet found a design that gives value proportionate to the complexity, although we continue to think about it. Meanwhile, Go's built-in maps and slices, plus the ability to use the empty interface to construct containers (with explicit unboxing) mean in many cases it is possible to write code that does what generics would enable, if less smoothly.


This remains an open issue.



Here's a bit of Go code to give you an idea, and much more is explained in Google's tutorials. I've just copied some syntax samples into this bit of code, not to create a compilable valid program but for the sake of showing off some of the := declaration syntax, the "missing" if and for brackets, the use of semi-colons as separators but not terminators (the tutorial code seems to be inconsequential about this, or I'm missing something), the implicit break in the switch statement and more:


package main

import fmt "fmt"

const (
Space = " ";
)

func main() {
var s string = "";
for i := 0; i < 10; i++ {
if i > 0 {
s += Space
}
s += "foo"
}

var a int;
b := 0;
c := 0;
switch {
case a < b:
c = -1
case a == b:
c = 0
case a > b:
c = 1
}
}



[SOURCE]

Comments

Popular Posts