Go语言先睹为快
delphidoc
2009-12-18
转载自:http://www.cnblogs.com/niuchenglei/archive/2009/11/16/1604118.html
2009年11月10日,就在这个光棍节的前一天,我们伟大的Google为了不让我们这些单身可怜的程序员们在光棍节那天空守寂寞,特意推出了Go语言,我猜意思是Why don't your courtship to a sweetheart?go,go,go…… 哈哈,上面的内容纯属虚构,如有雷同纯属巧合。下面进入正题Go,Go,Go Introduction Go语言是一门动态的编译性语言,是一种类C、C++语言,它简单、快速、安全,速度比python还快,而且开源。 进入HelloWorld 05 package main
10 fmt.Printf("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界\n"); 11 } $ 6g helloworld.go # compile; object goes into helloworld.6 $ 6l helloworld.6 # link; output goes into 6.out $ 6.out Hello, world; or Καλημέρα κόσμε; or こんにちは 世界 $ gccgo编译器使用: $ gccgo helloworld.go $ a.out Hello, world; or Καλημέρα κόσμε; or こんにちは 世界 $
05 package main
08 "os"; 09 "flag"; // command line option parser 10 )
15 Space = " "; 16 Newline = "\n"; 17 )
20 flag.Parse(); // Scans the arg list and sets up flags 21 var s string = ""; 22 for i := 0; i < flag.NArg(); i++ { 23 if i > 0 { 24 s += Space 25 } 26 s += flag.Arg(i); 27 } 28 if !*omitNewline { 29 s += Newline 30 } 31 os.Stdout.WriteString(s); 32 }
11 s := "hello"; 12 if s[1] != 'e' { os.Exit(1) } 13 s = "good bye"; 14 var p *string = &s; 15 *p = "go"; 数组的声明的形式为: var arrayOfInt [10]int; 它还支持字典类型: m := map[string]int{"one":1 , "two":2} Allocation分配(new一个对象) Go语言可以使用new关键词分配一个对象,它返回对象的指针 type T struct { a, b int } var t *T = new(T); 当然可以更简单些: t := new(T);
今天先到这里了,没有把文档看完.期待Go可以给我们更多的精彩,Just Go
|