Which language for DevOps tasks?

With so many languages to choose from, how do you choose?

Line up: Image by pch.vector on Freepik

Decisions are hard, and on an empty stomach, you are likely to make bad decisions. Programming comes with lots of choice. Great devEx comes with Golden Paths, to reduce the decisions.

In this article I will outline several languages and the tasks they are best suited to/for.

Bash

You cannot get much simpler than BASH. Created in 1989, bash shell is the default shell on most Linux distributions. Shell Scripts are the backbone of many sysOps automated tasks. From creating new users, to applying patches to a server. Essentially a script just runs other command line tools, with a bit of logic thrown in for taking arguments and checks on the system it is running on.

Bash provides Variable, If statements and Functions. You can program some quite elaborate tasks. Calling APIs and processing the results in JQ for instance.

Shell scripts are true batch processing, they mostly just call other tools that exist on the system. You will find them under /bin and /usr/bin

Most useful for running admin tasks on servers. Probably in a cloud-init or Packer configuration.

Python

This high-level interpreted/compiled language was created in 1991. Python is consistently listed as the most popular language and I would urge every to learn it.

It has all the basics of a language, like variables, conditionals, and program control logic. It is a fully featured structured programming language, supporting functional and object oriented paradigms. It has an extensive standard library, and a rich ecosystem of additional libraries via PyPI.

One major distinctive style is the use of indentation rather than curly brackets commonly found in other languages. I must admit to find this quite jarring at first (about 2016) having spent a lot of time in C++, PHP and Ruby, however well indented code makes it much easier to read and is done in other languages anyway. Just watch out for the closing blocks!

Python Powered: By Максим Пе - Own work, CC BY-SA 4.0

It is heavily used in AI Artificial intelligence especially with TensorFlow and Jupyter Notebooks.

As well as writing API backends, particularly in serverless programming like AWS Lambda, it also is used to host websites with frameworks such as Flask and Django.

In the DevOps world it is what Ansible is written with.

Python can be compiled into packages to run command line utilities.

Ruby

Another high level interpreted language, but totally Object orientated. Created in 1995, slightly younger that Python, it’s rival, the creator Matsumoto said that Python wasn’t true object orientated.

Ruby code looks somewhat like C++ and similar to Perl and Python. One of the main differences is that of variable scope. As a Object orientated language, all variables are private to a class. This means you need to program getters and setters to share the variables between classes.

Code can be packaged into command line utilities and is the language that powers Puppet and Chef.

Ruby has a package manager to extend functionality called Gems with over 100,000 Ruby Gems on RubyGems

Ruby can be run within a webserver process. Most common framework is Ruby on Rails.

GoLang

Designed at Google in 2009, Go is a compiled language. This means all the dependencies, libraries and code are compiled into a single executable package. This makes execution easy and fast, but care should be taken as will all compiled code, it will only work on the system for which it was packaged for. This means you can compile it for targets such as x86 Linux, or AMD64 Windows.

It it heavily based on C but contains memory management, garbage collection and typing.

Go is not strictly Object orientated, but uses interfaces vs class inheritance. Along with the strong error handling paradigm, where every function is expected to fail and provide a reason, these are the principles you should grasp first when approaching Go.

Being complied is very useful in DevOps, as it creates an easy to install command that can be used from a BASH script. This lack of external dependencies simplifies the startup of new servers, enabling the configuration of a server.

It can be source to source complied to JavaScript for web development with GopherJS.

C#

Created in 2000, another high level programming language. This one adds component oriented to the mix of functional and object oriented paradigms.

If you are in a windows environment, you can use BASH, or PowerShell to perform scripting. For the command line utilities, instead of GoLang, you could use C Sharp.

Another complied language, it must be compiled and packaged before it can run. If you are using third party libraries these must be installed too. This makes it a little less flexible than GoLang.

In a windows environment though, there is a large library of GUI options via the .NET framework.

Code must have brackets for functions and every line has to have a semi colon to terminate the statement.

I have seen it used for Embedded applications like robots and for games programming in the Unity Engine.

I mention it here as a windows tool and comparison to C.

Want to know more? Come ask me questions. You can find me on Slack.

If you found this useful, subscribe to updates and look out for my YouTube channel content.