Luther Johnson <luther.johnson(a)makerlisp.com> wrote:
'Go' is also a pretty C-like advanced C kind
of thing. What do Go
writers think of it vs. C, for safety, reliability, clarity of
expression, etc. ?
I have what to say about the topics in this thread, but I wanted
to answer this. I've been working in Go for about two years
in my current $DAYJOB. I haven't done as much of it as I'd like.
As preface, I've been programming (heavily) in C since 1983 and quite
a fair amount in C++ since 1999 or so, with Python in the mix more
recently.
Overall, I like Go. The freedom from manual memory management
takes some getting used to, but is very liberating once you do.
I do find it too terse in some cases, mostly in the initialization
syntax, and in the use of nested function objects.
I also find Go modules to be totally opaque, I don't understand
them at all.
One thing I'm still getting used to is the scoping with := vs. =.
Here's a nasty bug that I just figured out this week. Consider:
var (
clientSet *kubernetes.Interface
)
func main() {
....
// set the global var (we think)
clientSet, err := cluster.MakeClient() // or whatever
....
}
func otherfunc() {
// use the global var (but not really)
l := clientSet.CoreV1().NetworkPolicyList(ns).Items
}
In main(), I *think* I'm assigning to the global clientSet so that I
can use it later. But because of the 'err' and the :=, I've actually
created a local variable that shadows the global one, and in otherfunc(),
the global clientSet is still nil. Kaboom!
The correct way to write the code is:
var err error
clientSet, err = cluster.MakeClient() // or whatever
"When the light went on, it was blinding."
Of course, the Goland IDE actually warns me that this is the case,
by changing the color of clientSet in the assignment, but it's an
extremely subtle warning, and if you don't hover over it, and you're
not paying a lot of attention to the coloring, you miss it.
So, I like Go, and for a new project that I wouldn't write in Awk
or Python, I would use Go. The time or two I've looked at Rust,
it seemed to be just too difficult to learn, as well as still
evolving too fast. It does look like Rust will eventually replace
C and C++ for new systems level code. We can hope that will be
a good thing.
My two cents,
Arnold