Go入门系列

Go入门系列(一)伊始

2020-02-24  本文已影响0人  RabbitMask

欢迎来到Golang入门系列,说起这个系列出现的缘由,1、Golang的潜力无疑;2、笔者希望把所有有价值的主流语言全学一遍。

首先,我们来明确下定位,Go始于07年,在09年开源,官方团队来自Google。

然后是最耐人寻味的一点,它是一门面向对象的or面向过程的语言?

Yes and no. Although Go has types and methods and allows an object-oriented style of programming, there is no type hierarchy. The concept of “interface” in Go provides a different approach that we believe is easy to use and in some ways more general. There are also ways to embed types in other types to provide something analogous — but not identical — to subclassing. Moreover, methods in Go are more general than in C++ or Java: they can be defined for any sort of data, even built-in types such as plain, “unboxed” integers. They are not restricted to structs (classes).
Also, the lack of a type hierarchy makes “objects” in Go feel much more lightweight than in languages such as C++ or Java.

官方给出了一个十分“绅士”的回答,Go允许面向对象的编程思想,但并没有提供面向对象的语言结构,它的语言习惯更倾向于C语言,所以我们也没必要纠结了,或者,把这个问题的答案放在系列最后吧。

在使用Go语言前,我们简单提一下环境配置。

Golang安装:
https://golang.google.cn/dl/

然后可以像配置java/python环境那样,将bin目录添加到环境变量path。
所有语言的开始,hello world!

package main

import "fmt"

func main() {
   fmt.Println("Hello, World!")
}

如果你已经像刚刚那样配置了环境变量,即可通过go run hello.go运行。

关于go语言的基本语法,通过小样例我们也看到了:

// 单行注释

/*
 多行注释
 */

关于IDE的选择,这里选择了JetBrains全家桶中的GoLand,在后续教程中会捎带涉及使用。

然后,没啦,不许说我短!
就像当初学习python一样,我们从零开始,只有小白真真正懂得小白需要什么!预计完成时间,两周。如有错误,欢迎大佬指正,一定虚心改正。

上一篇 下一篇

猜你喜欢

热点阅读