Golang for Raspberry pi?

Hi, I am a beginner in the field of software programming. Previously I worked in the hardware field, known Golang with advantages such as parallel computation or compiling directly to binary via gcc. As for raspberry pi programming, is golang really optimal or superior to python, C and Java languages? Hope everyone gives me an opinion, thank you!

An opinion (facts?) is that C is faster than Python or Java. And Go is almost as fast as C. We use Go on Debian (relative to Raspian) and it works fast and reliable. I guess that both Go and C have a small footprint, but as Java and Python needs extra interpreter, I guess that they have bigger footprint.

1 Like

One potential issue using Go with a Raspberry Pi is the size of the binary. Go binaries are standalone, requiring no VM or interpretter, which means the compiled binary is substantially larger. A basic “hello, world” binary is ~1.7Mb in Go whereas it’s only kb in other languages.

TinyGo is a third-party compiler only compiles code absolutely needed to run the binary. So, the binary is substantially larger. TinyGo is specifically designed for things like Raspberry Pi.

2 Likes

Thank you very much for being a great mentor for helping me so thoroughly, thank you. Like the pros and cons of golang you mentioned above, then can I ask more is that if you can ignore the size of the binary file compared to C when compiled, go is really better than C in embedded programming or IOT. Next is about Goroutines which is a special feature of Golang if it is possible in embedded programming and IOT it is good or not and if it is good then it will be somewhat and if not good then the reason. And finally let me ask if writing firmware for electronic devices is really good or not. Thank you very much.

“Better” is hard (or perhaps impossible) to answer:

An expert C programmer can probably implement some functionality for an embedded device that runs twice as fast with less memory. If you include modern C++ as “C,” then the language is much more complicated, but if you learn how to use it right (including the C or C++ memory model, build systems, compiler optimization flags, address sanitizer flags, etc.), you can get the best performance possible short of expert assembly language programming.

Go is still “better” to *me* because I don’t care about the shortest execution times possible. I want the code to be plain (perhaps even boring) to read as possible. No manual memory management, ownership or reference semantics, etc… Go is meant to be a simple language to read so that as your project grows and you can no longer “fit” your mental model of the project in your head at one time, it’s easy to re-read through it and “restore” your understanding of pieces you forgot about. Garbage collection technically has a higher runtime cost than manual memory management, but with GC, you don’t have to burden yourself with tracking memory and can concentrate on the more important parts.

I don’t know if TinyGo supports goroutines, but the version of Go released on golang.org supports goroutines on any listed architecture, as far as I know. I think Raspberry Pis use some ARM CPU, so that will work.

“Good or not,” again, depends. You should not use goroutines to sort a 4-element slice. Maybe you should use goroutines to concurrently handle I/O requests on the embedded device. You’ll need to ask specific questions to get specific answers/suggestions.

Embedding a Go runtime into firmware sounds like overkill to me. My understanding of firmware is that it should be small and minimalistic like what C/C++ or assembly gets you. Though maybe that sentiment is obsolete now! Again, I’d suggest a more specific question(s) to get better answers.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.