Now that I've finished looking at the "definition" section of the udemy course, I'll review it.
I learned while outputting the basic operation on the console.
--Learn Go by watching Introduction to Go taught by active Silicon Valley engineers + Development of Bitcoin Systre Fintech app by application on udemy During ~
--Development environment is VS Code + plugin (Go version is 1.15) --OS is Windows
-You can read the explanation at "document" on the go site or at the command prompt. -Import and use outside the function.
-If the declared variable is not used, a compile error will occur. ・ It is also possible to declare all at once ↓
var (
a int
b float64
c string
d bool
)
-In a function, it can be declared without specifying the type. (The type is automatically determined.) -Variable types can be checked using functions in the fmt library.
x := 1
//You can check the type with Printf
fmt.Printf("%T", x)
-Declare an invariant value with const. Usually written outside the function.
const (
//No type specified in const (interpreted by the compiler but not executed)
Username = "test_user"
Password = "test_pass"
)
-When called from other go files, start the variable name with an uppercase letter.
-The size of the array created by specifying the number of elements cannot be changed. -If you create an array with a slice without specifying the number of elements, you can add elements with append. -There are two ways to declare an array with 0 elements ↓
//Pattern 1 Generate an array with initial values in memory
array1 := make([]int, 0)
//Pattern 2 nil(Null treatment)
var array2 []int
Map -It is saved as a Map type. -The value can be retrieved from the key.
m := map[string]int{"apple": 100, "banana": 200}
//You can retrieve the value from the key
fmt.Println(m["apple"])
//You can specify the key and update the value
m["banana"] = 300
fmt.Println(m)
//New elements can be added
m["new"] = 500
fmt.Println(m)
-Can be set as a return value for each function. -The value in the function is retained. -Since it is difficult to understand the movement of the value, it is better to follow the movement with a debug tool.
func circleArea(pi float64) func(radius float64) float64 {
return func(radius float64) float64 {
return pi * radius * radius
}
}
func main(){
//First set the pi
c1 := circleArea(3.14)
c2 := circleArea(3)
//Execute calculation from the set pi
fmt.Println(c1(2))
fmt.Println(c2(2))
}
For the explanation of closures, I also referred to the here site.
Since I usually use Java, there were some points I was interested in.
-There is no ";" at the end of the line.
-The class does not exist.
-Do not specify public / private.
-Describe in the order of "variable name
Is Go an object-oriented language? 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.
・ Processing is fast. -I felt that the function description method was similar to javaScript. (I'm not sure because I have little knowledge of javaScript ... I will also study JS.) ・ Map is easy to handle. Elements can be extracted without searching with the for statement. ・ Learning at udemy is efficient because you can move your hands while listening to the explanation.
Recommended Posts