I am a developer of c/c++. I started studying golang from today.
Go lang is similar to c/c++ and is simple so I think I will get used to it soon.
After studying for about an hour, there is a difference in syntax than I thought, but I don’t know how to solve it, so the process is slow.
For this reason, I would like to find a grammar that matches exactly c++.
Are there any helpful websites? I meet situations where even the following very simple array, variables, initializations, and repetitive statements are difficult, and they work differently than the intended situation.
like this…
c++
std::vector<std::string> test; // empty container ok
std::vector<std::string> test(2,"test"); // ok
std::vector<std::string> test = {"123","123123"} // ok
==> assignable by constructor and copy assignment through equal operator, so it's possible
go lang
var test []string //ok
var test []string = {"123","345","456"} // not work
test := []string{"123","345","456"} // ok
==> i don't know why its not working or working
The var keyword in Go only declares a identifier of a type . you cannot assing any value at that time.
While the short declaration := operator in Go declares an identifier as well as assigns a value to it.
Apart from language specification, see the Effective Go also.
The best courses that I’ve found are Jon Calhoun’s courses. He has free courses on algorithms and some “gophercises”. He also has a paid web development course which is the best source that I have found on the subject.
The strength of Jon Calhoun is that, unlike many courses on Udemy, he actually explains how to put things together instead of just reading package documentation out loud.
He has a great discount during the pandemic. The best budget option for the web development course it to just get his book without screencasts, ~$40. The full course with screencasts is about $150, and very much worth it.
first:var是一个关键字,用来声明变量使用的
然后看你给的这个例子
var test []string = {“123”,“345”,“456”}
上面这个是语法错误的,为什么呢?
原因,你应该这样去写
var test []string =[]string {“123”,“345”,“456”}
因为你做了一个赋值的操作
再看下面的例子
test := []string{“123”,“345”,“456”}
这个是声明了局部变量,然后,通过自动推导的方式实现的。