Go(1)
1. 왜 Go를 배우나?
그냥 새로운 걸 하고 싶었다.
학교에서 배우는 것 말고 나만 할 수 있는 무언가가.
그러던 중 관련 강의가 많이 올라왔고 이제는 공부할 수 있겠다 싶었다.
그래서 시작한다.
2. Hello world
fmt.Println. Println이 대문자로 시작하는 이유는 GO의 export시스템과 관련이 있다. 첫 문자가 대문자로 시작하면 export가 자유롭고, 소문자로 시작하면 private이다.
3. 변수와 상수
변수는 var로 상수는 const로 선언한다. c나 Java처럼 자료형을 선언해 주어야한다.
여타 언어들이 그렇듯 const로 선언한 값을 바꾸는 것은 error을 발생시킨다.
var (var_name) (type) = 의 기본적인 선언 형태를 갖고 있으나
(var_name) := (s)로 생성할 수도 있다 이렇게 하면 s의 타입을 자동으로 유추해 변수를 만든다.
만약 s의 자료형이 string이어서 string변수가 만들어졌다면 s안에 int나 float, boolean 등 다른 종류의 변수를 넣지 못한다.
3. 함수의 선언과 기타등등
4.naked return과 defer
naked return: 반환할 값을 함수의 첫줄에 먼저 적어준다. 함수에서는 그 값에 코드를 할당한다. "생성" 이 아니라 단지 "할당"한다.
defer: 함수가 종료될때 이 문장을 수행한다.
5. 자료형(types)
https://go101.org/article/type-system-overview.html
Go Type System Overview - Go 101: an online Go programming book + knowledge base
This article will introduce all kinds of types in Go and the concepts regarding Go type system. It is hard to have a thorough understanding of Go, without knowing these fundamental concepts. Each of the above mentioned basic and composite types corresponds
go101.org