DEV Community

Robertino
Robertino

Posted on

💻 TinyGo: Good Things Come in Small Packages

📚 TinyGo is Golang’s baby brother. Read more about it on a beginner's guide into the world of IoT with TinyGo.


TL;DR: The concept of coding for IoT devices, CLIs and WebAssembly is not a new concept. However, what if I told you that it is possible to use Golang for all three. TinyGo is a specialized project specifically designed and used for development in small places. This article explains the benefits of TinyGo, what it is, and how you can use it. It also provides you with a Golang IoT code example for you to see TinyGo in action.

What Is TinyGo?

TinyGo is Golang's baby brother. It is a compiler that allows a user to write the Golang code they are familiar with and run it in places people wouldn't have thought were possible. What this means is that the barriers to entry into some tech spaces are being gradually lowered. I say this because I am writing through experience.

How Is TinyGo Different from Golang?

Out of the box, Golang is a feature-rich, highly-performant, compiled language, which means that Golang is compiled to machine-readable code (those funky 1 's and 0 's everyone talks about).

In turn, being compiled to machine code allows it to run directly on the hardware — all that CPU/RAM power! Another really cool feature of Golang is that when building a binary of the written program, it includes extensive cross-compatibility for a wide from of different system architectures.

Once a binary has been built, it can be run on any compatible distribution/architecture, providing it has been specified during the build process. To find the list of supported architectures (after installing Go on your machine), run this command into your terminal: go tool dist list.

The output will look something like this:

aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
...
Enter fullscreen mode Exit fullscreen mode

So, how is TinyGo different? Well, it's the same Golang you know and love, but TinyGo is a smaller compiler based on LLVM technologies. It has essentially cherry-picked a number of important and available libraries and trimmed a lot of the fat from the core language.

By doing that, TinyGo becomes an even more powerful and efficient language that you can run in unexpected places. As an example of fat that's been trimmed, the library html/template cannot be imported by TinyGo as it relies upon other dependencies, which in turn are not able to be imported.

To read up on the packages supported by TinyGo, visit the documentation pages.

Read more...

Top comments (0)