DEV Community

Cover image for Best Programming Languages for DevOps in 2024
Eduardo Messuti for StatusPal

Posted on • Originally published at statuspal.io

Best Programming Languages for DevOps in 2024

We're StatusPal. We help DevOps and SRE engineers effectively communicate to customers and stakeholders during incidents and maintenance with a super-charged hosted status page. Check us out—your status page can be up and running in minutes.

As the DevOps and Site Reliability Engineering (SRE) fields continue to mature in 2024, the choice of programming languages has become more critical than ever. What language or languages should you focus on next in order to stay competitive in the marketplace and be productive while automating your way to success?

This blog post explores the preferred programming languages for DevOps and SRE practitioners in 2024, examining their strengths and applications in critical areas such as CI/CD, infrastructure provisioning, and configuration management.

Content Index

Why you Need Programming Skills as a DevOps/SRE

Programming languages in DevOps and SRE serve many purposes, each aligning with specific operational needs. They are pivotal in:

  • Monitoring & Alerting: While existing tools meet most monitoring and alerting needs, there are many situations where programming will come in handy, like configuring custom monitoring scripts, creating integrations with monitoring tools, and scripting automated alert responses.
  • Cloud Automation: Essential in addressing various needs, such as automating the provisioning and management of cloud resources, orchestrating complex deployment workflows, implementing auto-scaling strategies, and managing infrastructure as code (IaC).
  • DevOps Platform Tooling: Platform engineering teams often program in-house tools and integrations in programming and scripting languages like Python, Go, and Bash.
  • CI/CD, Infrastructure Provisioning & Configuration Management: Integral for developing custom plugins, scripts, or extensions to improve existing tools or integrate disparate systems. For example, a DevOps engineer might use Python or Ruby to script integrations between project management software and continuous integration/continuous deployment (CI/CD) pipelines, enabling automated updates and tracking of development progress.

Preferred Programming Languages and Their Advantages

Each of the following languages offers unique benefits in the realm of DevOps and SRE:

Python

  • Overview: A versatile, high-level language known for its readability and broad community support.
  • Strength: Python shines in building great Command Line Interfaces (CLIs), as exemplified by frameworks like Typer, which make it extremely easy to build outstanding and user-intuitive CLI tools that you can use to make your life and your teams' life easier.
  • Use Cases: Ideal for scripting, automation, data analysis, and creating utilities for DevOps tasks.

Example of Python script using Typer

import typer

app = typer.Typer()


@app.command()
def hello(name: str):
    print(f"Hello {name}")


@app.command()
def goodbye(name: str, formal: bool = False):
    if formal:
        print(f"Goodbye Ms. {name}. Have a good day.")
    else:
        print(f"Bye {name}!")


if __name__ == "__main__":
    app()
Enter fullscreen mode Exit fullscreen mode

Bash

  • Overview: A Unix shell and command language.
  • Strength: Requires no APIs, types, and is ubiquitous in Linux environments, making it a go-to for quick scripting solutions.
  • Use Cases: Scripting routine tasks, automating simple operations, and environment setup. Personally, I'll use bash for any small script of 100 or less LoC, but some engineers will go further and write much more complex ones.

Example Bash script

A script to check the health of a server by monitoring CPU, memory, and disk usage.

#!/bin/bash
echo "Checking CPU usage..."
uptime

echo "Checking Memory usage..."
free -m

echo "Checking Disk usage..."
df -h
Enter fullscreen mode Exit fullscreen mode

Powershell

  • Overview: A task automation and configuration management framework from Microsoft.
  • Strength: Particularly effective in Windows or Azure environments, providing powerful scripting capabilities.
  • Use Cases: Managing Windows-based environments, Azure cloud services, and automating Windows-specific tasks.

Powershell script example

A script that gets the list of all the projects in an Azure organization and saves them to a .csv file.

[CmdletBinding()]
param (
    $OrganizationUrl,
    $PAT,
    $OrganizationName
)

$orgUrl = $OrganizationUrl
$pat = $PAT

# Create header with PAT
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($pat)"))
$header = @{authorization = "Basic $token"}


# Get the list of all projects in the organization
$projectsUrl = "$OrganizationUrl/_apis/projects?api-version=5.1"
$projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -ContentType "application/json" -Headers $header
$projects.value | ForEach-Object {
   Write-Host $_.id $_.name
   $user =[pscustomobject]@{
        'id' = $_.id
        'name' = $_.name
    }
    $user | Export-CSV -Path allprojnameid.csv -Append -NoTypeInformation -Force
}
Enter fullscreen mode Exit fullscreen mode

Go

  • Overview: A statically typed, compiled language designed for simplicity and efficiency.
  • Strength: Known for its ability to be easily packaged into a single binary, quick compilation time, and extensive standard library, making it ideal for creating lightweight, standalone applications that you can easily share with your team.
  • Use Cases: Building high-performance tools and services, microservices, and networked applications.

Go example code snipped

Go can be used to parse and analyze log files, often a key part of monitoring and alerting in DevOps/SRE.

package main

import (
    "bufio"
    "fmt"
    "os"
    "strings"
)

func main() {
    file, err := os.Open("logfile.log")
    if err != nil {
        fmt.Println("Error opening file:", err)
        return
    }
    defer file.Close()

    scanner := bufio.NewScanner(file)
    for scanner.Scan() {
        line := scanner.Text()

        // Check if the line contains the word "ERROR"
        if strings.Contains(line, "ERROR") {
            fmt.Println("Error found:", line)
            // Additional processing can be done here, such as aggregating statistics or alerting
        }
    }

    if err := scanner.Err(); err != nil {
        fmt.Println("Error reading from file:", err)
    }
}
Enter fullscreen mode Exit fullscreen mode

Rust

  • Overview: Rust is a systems programming language known for its safety and performance. Its design prevents common bugs found in other languages, making it ideal for writing reliable and efficient software, which is a critical aspect for DevOps and SRE engineers.
  • Strength: The primary strength of Rust in a DevOps/SRE context lies in its emphasis on safety and concurrency without sacrificing speed. This makes it a strong candidate for building high-performance, robust, secure tools and applications in a DevOps environment.
  • Use Cases: Rust is well-suited for creating DevOps tools, especially those that require direct system interaction or performance-intensive operations. Examples include network services, system daemons, file system manipulation tools, and automation scripts. Rust's cross-platform support also makes it valuable for developing tools that operate across various operating systems.

Rust Example code snipped

Rust is increasingly being used to create tools for container orchestration and management, thanks to its performance and safety features.

use shiplift::Docker;
use std::env;

fn main() {
    let docker = Docker::new();
    let images = docker.images();

    let future = images.list(&Default::default());
    let image_list = tokio::runtime::Runtime::new().unwrap().block_on(future).unwrap();

    for image in image_list {
        println!("{:?}", image.repo_tags);
    }
}
Enter fullscreen mode Exit fullscreen mode

CUE

While Cue is not a programming language per se, we think it's worth an honorable mention, as it can be quite useful for DevOps and SRE engineers.

CUE is an open-source data validation language. It streamlines data validation, configuration, code generation, and more, as illustrated in cue_for_devops.md.

How can CUE help with DevOps?

  • CUE can parse YAML and JSON files and also output data in these formats
  • Templates are a CUE feature that provide a much more manageable alternative to distributing boilerplate code
  • The CUE runtime allows the aggregation of many data sources in a predictable and repeatable way; CUE will not let disagreements or conflicts in the data pass through silently
  • CUE provides support for writing CLIs which can be used to interface with DevOps tools
package cuefordevops

terraformConfig: [string]: {}

#terraformConfig: {
    moduleAwsPublicSubnet: "../../terraform_modules/aws/subnet_public"
    availabilityZone:      "\(#AwsRegion)a"
    awsProfile:            #AwsProfile
    awsRegion:             #AwsRegion
    cidrBlock:             string
    instanceType:          string
    name:                  string
    tagAmiName:            string
    tagAwsVpc:             "servers"

    terraform: [
        {
            "terraform": {
                "required_providers": {
                    "aws": {
                        "source":  "hashicorp/aws"
                        "version": ">= 4.17.1"
                    }
                }
                "required_version": ">= 1.2.2"
            }
        },
        {
            "provider": {
                "aws": {
                    "profile": "\(awsProfile)"
                    "region":  "\(awsRegion)"
                }
            }
        },
        {
            "data": {
                "aws_vpc": {
                    "this": {
                        "filter": {
                            "name": "tag:EnvironmentGroup"
                            "values": ["\(tagAwsVpc)"]
                        }
                    }
                }
            }
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

In conclusion, the landscape of programming languages in the DevOps and SRE domains is diverse and continually evolving. Each language brings unique strengths to the table, catering to specific needs within the DevOps/SRE toolkit.

Whether Python's versatility, Bash's simplicity, Powershell's Windows integration, Go's efficiency, CUE's configuration management, or Rust's performance and safety, there's a language for every aspect of DevOps and SRE tasks in 2024. As the field grows, so does the importance of choosing the right tool for the job.

Further reading

Learn more about programming languages for DevOps by following these links:

Top comments (0)