Somehow, I just couldn’t get myself to love Golang. My question is what did I miss? Maybe I am just stupid and can’t understand how it all ties together?
I love programming languages. I learn new programming languages because they teach me new design patterns, new ways to structure my program, and even new ways to design a solution, new paradigms.
To improve a system programming language, one important way is to employ new design patterns, and new paradigms.
Rust prevents resource leaks using the
Droptrait, following the RAII pattern, similar to C++ smart pointers.
But when I learnt Golang, which is said to be the competition for Rust, I was shocked at the horrible design choices behind this language. Compared to all the new languages like Scala and Rust, Golang does a horrible job at enabling good design patterns.
Golang doesn’t have RAII or
withstatements. Instead, programmers must remember to manually add a deferred function call:
defer cleanup(), which is basically
goto cleanup_label;in C. Hopefully you’ll remember every time.
Golang doesn’t have classes, and must rely on functional programming. Yet it doesn’t provide Generics, which highly limits the ability of functional programming. Golang’s response? Either, explicitly write out multiple copies of the same code, one for each type; Or, use the “empty interface”, which is just another name for the very unsafe
void*pointers in C.
Golang doesn’t have a well thought-out syntax for asynchronous programming, which has proven itself to be very efficient for Web Apps. Although it provides Goroutines, it doesn’t provide a way to flexibly compose Goroutines together. Any modern functional programming language will provide a way to program higher-order functions, to simplify the code and design while allowing for performance benefits. Golang couldn’t, because its type system can’t begin to understand a Generic type (see previous point) that represents a function.
Therefore, I say Golang is nothing more than C with some syntax sugar. I even suspect that it is a sham so that system programmers don’t have to learn new design patterns.
As a zealot programmer with a passion in rooting Android phones and tweaking kernels, I am sad to see the very people who develop these innovations are so unwilling to learn new design patterns. If they truly cared, they would have invested in a language like Rust, Haskell, or at least, C++.