The Go programming language (sometimes called Golang) is a modern programming language which aims to “make it easy to build simple, reliable and efficient software”.
Background
As we discussed in the four part series “Thoughts on Programming Languages and Environments – Jetson Dev Kits” (part 1 is here), there is an impedance mismatch between the programming languages of the past and current hardware. In no particular order, here are some major concerns when writing new software today:
- Memory Safety
- Concurrency
- Network/Web Integration
- Integration with Baseline Software
For the purposes of this discussion, we will talk about these in the context of embedded systems. The Jetson Dev Kits in particular.
Memory Safety
Memory Safety is probably the cause of most computer application issues. These issues deal with memory allocation and memory access. The “three major” programming languages on the most popular platforms, C#, Java, and Objective-C all provide good support in this area. As do dynamic languages, such as Python and Ruby. These languages use built-in tools like automatic garbage collection and run-time range checking for memory access.
On Linux based machines (and the underlying kernels of Windows, MacOS/iOS, and Android) the C programming language does not lend much support for this particular issue. There is a much broader ecosystem of languages being used on Linux at the application programming level than most other platforms. While there are “memory safe” languages that run on Linux, there are also some languages that do not have that support built-in to the language. The foremost of which is C/C++.
Concurrency
Concurrency allows programs to be thought of as a collection of components, which can possibly be run in parallel. The seminal paper on concurrency, Communicating Sequential Processes, was written in the 1980s by Tony Hoare.
The paper was written before multi-processor machines were widely available. The paper is a little math-y, but if you are a computer programmer/scientist the paper is considered a must read. If you haven’t read it in awhile, hunt it up and read it again.
With the advent of inexpensive multi-core/multi-processor computers, huge performance gains make a whole new range of applications possible. It is also helps to give perspective about computation on the GPU.
Currently most mainstream implementations of CPU concurrency are rather ad-hoc and not supported at a language level. Concurrency is notoriously difficult to get right in the general case, just mention the word ‘deadlock’ to a programmer and see the pain and fear in their eyes. Most platforms provide concurrency at an OS level, with programming languages calling platform libraries or lightly wrapped version thereof.
Network/Web Integration
As every knows, everything needs integrated network/web access. Just a few short years ago, the cost to talk to a network from an embedded device was prohibitive. Now it is so inexpensive that every device is expected to belong to the Internet of Things (IoT).
Integration with Baseline Software
It is difficult to build entire programming ecosystems from the ground up. Just the need to interface with the operating system means that a new programming language must be able to interface with ‘C’ libraries (C++ would be nice also).
Go
Go (golang.org) is designed to address the above issues head on. The creators of the Go language work at Google. Google has a large group of programmers with various degrees of experience working on world-scale systems. To better help facilitate programming in this type of environment, the authors realized that the programming language must have the above attributes built-in, it must be easy to scale, and people should easily be able to ascertain the intent of the program itself. In other words, programs should be “easy to read”.
Think of this as a “working mans” programming language. While Go may not have all the bells and whistles of some of the other more flexible languages, it does “the right thing” in its intended domain, which is mostly writing servers.
Answers!
For Memory Safety, Go implements an automatic garbage collector and does range checked storage.
For Concurrency, Go implements channels with some of the grammar introduced by Hoare. Having concurrency built into the language itself ensures consistent use by all participants. Concurrency also enables programs to execute in parallel as the environment allows. As an added bonus, there is even a deadlock detector!
Not surprisingly, since Go is used to build servers, Network/Web support is also built into the language. It is trivial to write a simple web server which takes into account all the little nooks and crannies that one has to think about in such pursuits. Why is this important in an embedded device? IoT!! With everything on the web now, web programming needs to be a standardized part of languages.
While Go is built for the server world, it also has very good Integration with Baseline Software. There are tools which help build wrappers around C library calls and such.
Go is industrial programming.
Conclusion
This has been a little bit of the ‘why’ of Go, let’s look at using Go on the Jetson in Part II.
The post Go (Golang) – NVIDIA Jetson Dev Kits appeared first on JetsonHacks.