FizzBuzz in Go and Rust
My team and I attended DockerCon earlier this week. We went with the intention of taking time at the hackathon to spend some time digging into what it would be like to operate services running on Docker & CoreOS. Part of the challenge of CoreOS is that there isn’t a package manager, which makes installing any modern programming language difficult. The only way to execute code is to drop a binary on the machine or to run code in a Docker container.
Therefore, it made a lot of sense to take some time to experiment with both Go and Rust. It was also a ton of fun to play with some new ideas. To get a grasp of the basics, I looked to the tried and true FizzBuzz. FizzBuzz is a great exercise because it forces you to loop, use control logic (if/else or case), and understand some basic math operators.
Rust bills itself as a language for systems programming. While I didn’t get far enough to determine if that was true, I did get far enough to determine that Rust is relatively difficult to work with, in that it requires a compilation step & a run step before you can see the outcome of your code.
It was also a bit awkward in that creating an effective code → execute workflow required installing Cargo to manage the very small package I created. Compilation was a bit on the slow side as well, considering I only wrote 25 lines of code.
1 2 3 4 5 6 7 8 9 10 11
Golang is an open source, statically-typed language that’s been designed to make it straight forward to build reliable and efficient software. That’s what it says on the tin, and happily, that was my experience. Go is simple to compile and run.
1 2 3 4 5 6 7 8 9
It was also fast. Almost 3x faster than rust. It wound up being slightly more
code, as Go requires you to name the package, and to import the
just to print to
stdout. However, the experience writing it was quite nice.
Very clear errors appeared at compile time, which was helpful as a n00b.
Overall, it was a good learning experience to dig into the next generation of programming languages. Rust seems promising, should I need to actually do system programming. But Go seems like a great candidate for building fast, portable tools.