Join IoT Central | Join our LinkedIn Group | Post on IoT Central


Will Javascript be the Language of IoT?

language.jpg

JavaScript has proven itself worthy for web applications, both client and server side, but does it have potential to be the de-facto language of IoT?  

This is a topic I posed to Patrick Catanzariti, founder of DevDiner.com, a site for developers looking to get involved in emerging tech. Patrick is a regular contributor and curator of developer news and opinion pieces on new technology such as the Internet of Things, virtual/augmented reality and wearables. He is a SitePoint contributing editor, an instructor at SitePoint Premium and O'Reilly, a Meta Pioneer and freelance web developer who loves every opportunity to tinker with something new in a tech demo.

Why does IoT require a de facto language any more than any other system? Wouldn't that stifle future language evolution?

Honestly, I think it's a bit too much to ask for every single IoT device out there to run on JavaScript or any one de facto language. That's unbelievably tough to manage. Getting the entire world of developers to agree on anything is pretty difficult. Whatever solution the world of competing tech giants and startups come to (which is likely to be a rather fragmented one if current trends are anything to go by), the most important thing is that these devices need to be able to communicate effectively with each other and with as little barriers as possible. They need to work together. It's the "Internet of Things". The entire benefit of connecting anything to the Internet is allowing it to speak to other devices at a massive scale. I think we'd be able to achieve this goal even with a variety of languages powering the IoT. So from that standpoint, I think it's totally okay for various devices to run on whichever programming language suits them best.

On the other hand, we need to honestly look at the future of this industry from a developer adoption and consistency perspective. The world of connected devices is going to skyrocket. We aren't talking about a computer in every home, we're talking dozens of interconnected devices in every home. If each one of those devices is from a different company who each decided on a different programming language to use, things are going to get very tough to maintain. Are we going to expect developers to understand all programming languages like C, C++, JavaScript, Java, Go, Python, Swift and more to be able to develop solutions for the IoT? Whilst I'm not saying that's impossible to do and I'm sure there'll be programmers up to the task of that - I worry that will impact the quality of our solutions. Every language comes with its quirks and best practices, it'll be tough to ensure every developer knows how to create best practice software for every language. Managing the IoT ecosystem might become a costly and difficult endeavour if it is that fragmented.

I've no issue with language evolution, however if every company decides to start its own language to better meet the needs of the IoT, we're going to be in a world of trouble too. The industry needs to work together on the difficulties of the IoT, not separately. The efforts of the Open Interconnect Consortium, AllSeen Alliance and IoT Trust Framework are all positive signs towards a better approach.

C, C++ and Java always seem to be foundational languages that are used by all platforms, why do you think JavaScript will be the programming language of IoT?

My position is actually a bit more open than having JavaScript as the sole programming language of the IoT. I don't think that's feasible. JavaScript isn't great as a lower level language for memory management and the complexities of managing a device to that extent. That's okay. We are likely to have a programming language more suited to that purpose, like C or C++, as the de facto standard operational language. That would make perfect sense and has worked for plenty of devices so far. The issues I see are in connecting these devices together nicely and easily.

My ideal world would involve having devices running on C or C++ with the ability to also run JavaScript on top for the areas in which JavaScript is strongest. The ability to send out messages in JSON to other devices and web applications. That ability alone is golden when it comes to parsing messages easily and quickly. The Internet can speak JavaScript already, so for all those times when you need to speak to it, why not speak JavaScript? If you've got overall functionality which you can share between a Node server, front end web application and a dozen connected IoT devices, why not use that ability?

JavaScript works well with the event driven side of things too. When it comes to responding to and emitting events to a range of devices and client web applications at once, JavaScript does this pretty well these days.

JavaScript is also simpler to use, so for a lot of basic functionality like triggering a response on a hardware pin or retrieving data from a sensor, why overcomplicate it? If it's possible to write code that is clear and easy for many developers to understand and use without needing to worry about the lower level side of things - why not? We have a tonne of JavaScript developers out there already building for the web and having them on board to work with joining these devices to their ecosystem of web applications just makes sense.

Basically, I think we're looking at a world where devices run programming languages like C at their core but also can speak JavaScript for the benefits it brings. Very similar to what it looks like IoT.js and JerryScript will bring. I really like the Pebble Smartwatch's approach to this. Their watches run C but their apps use JavaScript for the web connectivity.

When it comes to solutions like IoT.js and JerryScript, they're written initially in C++. However they're providing an entire interface to work with the IoT device via JavaScript. One thing I really like about the IoT.js and JerryScript idea is that I've read that it works with npm - the Node Package Manager. This is a great way of providing access to a range of modules and solutions that already exist for the JavaScript and Node ecosystems. If IoT.js and JerryScript manage memory effectively and can provide a strong foundation for all the low level side of things, then it could be a brilliant way to help make developing for the IoT easier and more consistent with developing for the web with all the benefits I mentioned earlier. It would be especially good if the same functionality was ported to other programming languages too, that would be a fantastic way of getting each IoT device to some level of compatibility and consistency.

I'm hoping to try IoT.js and JerryScript out on a Raspberry Pi 2 soon, I'm intrigued to see how well it runs everything.

What do developers need to consider when building apps for IoT?

Security - If you are building an IoT device which is going to ship out to thousands of people, think security first. Make sure you have a way of updating all of those devices remotely (yet securely) with a security fix if something goes wrong. There will be bugs in your code. Security vulnerabilities will be found in even the most core technologies you are using. You need to be able to issue patches for them!

Battery life - If everyone needs to change your brand of connected light bulbs every two months because they run out of juice - that affects the convenience of the IoT. IoT devices need to last a long time. They need to be out of the way. Battery life is crucial. Avoid coding things in a way which drains battery power unnecessarily.

Compatibility - Work towards matching a standard like the Open Interconnect Consortium or AllSeen Alliance. Have your communication to other devices be simple and open so that your users can benefit from the device working with other IoT devices in new and surprising ways. Don't close it off to your own ecosystem!

What tools do you recommend for developing apps in IoT?

I'm a fan of the simple things. I still use Sublime Text for my coding most of the time as it's simple and out of the way, yet supports code highlighting for a range of languages and situations. It works well!

Having a portable 4G Wi-Fi dongle is also very very valuable for working on the go with IoT devices. It serves as a portable home network and saves a lot of time as you can bring it around as a development Wi-Fi network you turn on whenever you need it.

Heroku is great as a quick free platform to host your own personal IoT prototypes on too while you're testing them out. I often set up Node servers in Heroku to manage my communication between devices and it is the smoothest process I've found out of all of the hosting platforms so far.

For working locally - I've found a service called ngrok is perfect. It creates a tunnel to the web from your localhost, so you can host a server locally but access it online via a publicly accessible URL while testing. I've got a guide on this and other options like it on SitePoint.

Are you seeing an uptick in demand for IoT developers?

I've seen a demand slowly rising for IoT developers but not much of a developer base that is taking the time to get involved. I think partially it is because developers don't know where to start or don't realise how much of their existing knowledge already applies to the IoT space. It's actually one of the reasons I write at SitePoint as a contributing editor - my goal is to try and get more developers thinking about this space. The more developers out there who are getting involved, the higher the chances we hit those breakthrough ideas that can change the world. I really hope that having devices enabled with JavaScript helps spur on a whole community of developers who've spent their lives focused on the value of interconnected devices and shared information get involved in the IoT.

My latest big website endeavour called Dev Diner (http://www.devdiner.com) aims to try and make it easier for developers to get involved with all of this emerging tech too by providing guides on where to look for information, interviews and opinion pieces to get people thinking. The more developers we get into this space, the stronger we will all be as a community! If you are reading this and you're a developer who has an Arduino buried in their drawer or a Raspberry Pi 2 still in their online shopping cart - just do it. Give it a go. Think outside the box and build something. Use JavaScript if that is your strength. If you're stronger at working with C or C++, work to your strength but know that JavaScript might be a good option to help with the communication side of things too.

For more on Patrick’s thoughts on Javascript, read his blog post “Why JavaScript and the Internet of Things?” and catch his O’Reilly seminar here.

David Oro is the Editor at IoT Central

Sponsor