How To Choose the Best Language for IoT
Peter Wayner, Techbeacon 97 Times 65 People

The lack of skilled IT workers is hurting the deployment of emerging technology, according to a new survey from Gartner. In areas from cloud to cybersecurity, this crisis is expected to last for years to come.

 How can we order them around? Which language do they speak?

The simple answer is that "smart" things use many of the same languages as desktops, in part because their similarities with desktop computers continue to grow.

But while the simple answer is that smart things aren't much different from desktops and servers, the complex answer is that there are important differences between all of the things that make up the IoT.

What we mean when we say 'IoT devices'

The IoT architectural environment can be divided into three major sections:

  1. The sensors that create the data,
  2. The hubs or local gateways that organize it, and
  3. The geographically distant, centralized servers that collect the data.

If you're writing for a sensor on bare metal, you're probably using C. The ability to work directly with the RAM makes C one of the first choices of hardware developers.

The hubs may be a smartphone or a small console, but they are just general-purpose machines inside. They usually run a standard operating system and often feel no different from a big machine, at least when communicating via the command line.

Choosing a language for IoT

Here are some of the top choices that are being used to build the foundations of the next generation of things connected to the Internet.

Java

The top choice is Java. Java's advantages are well known. Developers can create and debug code on their desktop and then move it to any chip with a Java Virtual Machine.

That means the code can run not just on places where JVMs are common (servers and smartphones), but also on the smallest machines.

Java ME, or micro edition, has been available on small phone handsets and other embedded devices since the specification was approved in 2000. It saved space with a very limited collection of class libraries and other tools.

Today, most of the focus is on Java SE Embedded, which is much closer in capability to the Standard Edition. Developers can use the latest features of the Java 8 platform and then move their code to a smaller, embedded device.

There are multiple open-source projects, such as Pi4J and BlueJ that show how the embedded version of Java runs well, even on chips that seem limited.

C

The syntax is cluttered with punctuation, and there are a million different little mistakes you can make, but the language is still the first choice for many programmers who write for the lowest layer of software, the one closest to the hardware.

The language hides nothing from you, and that means you can fiddle with every part of the code to squeeze out the best performance from an underpowered device. Every bit can be flipped. Every value on the stack is available. Just don't make a mistake, because there are few safety nets.

More advanced or bigger devices with full operating systems still use plenty of C code but other languages such as Java are starting to be used just as frequently.

Python

It started as a scripting language to glue together real code, but it's increasingly used as the main language by many developers.

Python's syntax is clean and simple, attracting a greater range of programmers. The language is often the first choice for social scientists and biologists, for instance. When they need a smart device in the lab, they're happy to use a language they know, Python.

Python is the language of choice for one of the most popular microcontrollers on the market, the Raspberry Pi. Much of the training literature is written in Python, and many schools use the platform to teach computer programming.

There are versions designed to be even smaller. The MicroPython board and software package is a small microcontroller optimized to run Python on a small board that's only a few square inches.

JavaScript

While many still think of JavaScript as a language for popping up alert boxes on web pages, the language's relatively newfound popularity on the server makes it a surprisingly popular choice for IoT applications.

A full 41.8 percent of the developers in the survey chose JavaScript, and 31.5 percent indicated that they were using Node.js in their projects.

Much of this work is focused on the servers and gateways or hubs that gather the information and then store it. The smaller smart hubs and sensors that run Linux can usually run Node.js.

But even if most of the Node.js code runs on larger machines, there are some efforts designed to bring it to smaller ones. Espruino and Tessel are two examples of microcontrollers that run JavaScript from the beginning.

Tessel, for instance, is built around Node.js, making it easy for web developers to move into the IoT without learning a new language.

Swift

While Swift is still mainly used to build applications for Apple's iOS and macOS devices, the preponderance of these machines means that it's often part of the IoT stack. If you want your things to interact with an iPhone or an iPad, you're probably going to want to build the app in Swift (or perhaps its predecessor, Objective C).

There are other good reasons to work in this space. Apple wants to make its iOS devices the center of the home network of sensors, so it's been creating libraries and infrastructure that handle much of the work.

These libraries are the foundation of its HomeKit platform, which provides support for integrating the data feeds from a network of compatible devices. This means you can concentrate on the details of your task and leave much of the integration overhead to HomeKit.

PHP

This language may be the first choice of bloggers and website prototypers, but it is also surprisingly popular in the IoT. After the big languages and their cousins such as C#, PHP is the one language that is mentioned the most often by developers.

While the code's role on the server to juggle microservices is an obvious application, it is also finding some traction at the lowest level.

A number of Raspberry Pi developers are talking about starting up a full LAMP stack with Apache, MySQL, and PHP running on top of Linux. They are effectively inverting the paradigm and turning the lowliest thing on the Internet into a full web server.

If a Raspberry Pi has enough spare cycles and it often does, then putting a LAMP stack on the chip makes development simpler. All of the server-side code developed over the last 20 years can find a home in a small sensor.

It may seem like a toy next to the full-strength, pointer juggling machismo of C, but if it gets the job done quickly and makes the boss happy, why not use it?



Comments:(0)

Leave a Reply