Is Go the C Killer?

I intended to write a post like this long ago as a sort of follow-up in spirit to my old(er) post on C. Unfortunately since I code most of the day my brain is too beat out for writing articles later in the day. I must admit, however, that I am quite lazy when it comes to writing blog posts. Writing a fairly technical blog post takes a lot of effort and research, so it’s not as easy as it may seem. Regardless, I’ve finally got into my blog-post-writing-spirit. πŸ™‚

It seems since my January post there has been a big inflation in Go and Rust users. Some brave souls even call Go a replacement for C when writing more low-level programs. My opinions have certainly changed since my original post on C, and I’ve formed some interesting views on the whole “Go vs C” debate. If you read my original article, you’ll know I claimed C was the best programming language. Although it may have seemed I was trying to prove how C was the absolute best, it was intended to be taken a bit more lightly. I don’t think C is absolutely perfect. It has flaws like every other programming language in existence. Moreover my intention was to say that C was still just as legit as any other language that exists. A lot of people seem to view C as some archaic nightmare used by hackers and code gurus, but it’s not like that. I tried to say that C is still pretty awesome, and stated some reasons for it being awesome. With that off my chest, let’s explore the weird world of the C and Go programming languages!

What is Go?

To say it simply, Go is a language with the low-level capabilities and simplicity of C but with tons of modern programming language features. The language itself was developed inside Google by Robert Griesemer, Rob Pike and Ken Thompson. The people who created Go make it even more interesting. Ken Thompson was the creator of the original B programming langauge, which was a very early compiled language that inspired Dennis Ritchie to create C!

Although Go comes with all the typical features of a modern language (garbage collection, package management, powerful object-oriented features, etc) the syntax resembles that of C and C++. Here is a Hello World program in Go:

package main

import (
    "fmt"
)

func main() {
    fmt.Printf("Hello world, or γ“γ‚“γ«γ‘γ―δΈ–η•Œ!")
}

As you can see, Go has a main function with a Printf function much like C. Unlike C, however, are two of Go’s required statements at the beginning of a program. One is the package statement, which defines what package the program is part of. This is used in Go libraries so you can import each package nicely. The second is the import statement, where a list of packages for the program to use is defined. There are a ton of default Go packages you can import, but Go has unique features like importing packages from GitHub URLs. Go’s Hello World program likes to show off its amazing Unicode support by including a “hello world!” translation in Japanese.

The Go compiler itself compiles code directly to machine code. Unlike languages like Java, Go compiles completely optimized machine code binaries for each platform. Lucky for us, Go supports almost every relevant operating system today. Even operating systems like NetBSD and Plan 9 are supported!

Go’s compiler is itself written in C (I’m guessing Rob Pike, Ken Thompson and co. had a lot of experience writing compilers in C), but the developers are trying to make Go’s compiler self-hosted. A self-hosted compiler is a compiler written in the same language it compiles. In other words, Go’s compiler would be completely written in Go. This is a major step for Go, since it’s the ultimate proof that Go is fast and versatile if it can implement itself.

Will Go Replace C?

It’s hard to tell whether newer low-level languages like Go will replace classic languages like C anytime soon, but I can give a prediction: not anytime in the near future.

Imagine C is a bike and Go is a modern car. Although a car is much more powerful, it completely relies on gasoline. Anyone can power a bike with two working feet. By setting up a full Go environment you can make amazing, easy to read programs, but anyone with a C compiler can create some decent C programs. Even though we have modern cars does that mean we need to stop selling bikes? Of course it doesn’t. Just because we have Go doesn’t mean C is just going to vanish. For goodness sakes, the military is still running on code written in Ada!

That said, we may see a lot more code written in Go. We won’t see stuff like the Linux kernel converted to Go for a long time, so it’s safe to say C isn’t leaving us completely. Whatever happens there’s no need to worry. Sometimes we focus too much on the tools we use to make something rather than what we want to make. Use C or Go, they’re both perfectly relevant languages for the time being.