Coalescing the Abstract into Software

Now that we’ve gotten to the core of what programming languages do, let’s get a little more concrete and see what some of them are and what they look like.

Python

Python is one of the most pervasive languages right now, due in part to its relative closeness to English and therefore low barrier to entry. It may seem cryptic at first, but you’ll see in time that other languages can get worse.

names = ['Ann', 'Bob', 'Catherine', 'Dave']
for name in names:
print('Hello ' + name)

Can you guess what the above will do? First, we create a list of names. We then take each name in the list and “print” it to the screen along with a greeting. It would look something like this:

Hello Ann
Hello Bob
Hello Catherine
Hello Dave

Neat, huh? (Not all that neat, but hey. We’re learning, people.)

JavaScript

JavaScript is another very popular language right now due to its use in web browsers like Chrome or Safari. As more and more people use the web, it’s convenient to use a language that works natively on the tools they use. Let’s see the equivalent of the code above, in JavaScript:

var names = ["Ann", "Bob", "Catherine", "Dave"];
for (name of names) {
console.log("Hello " + name);
}

You’ll notice there are some differences from Python, but ultimately the program reads similarly. We build a list of names, and then “log” them to the “console” with results identical to the above.

Java

Java — not at all related to JavaScript — is a programming language used by uncountable pieces of software. It’s the go-to choice when writing enterprise software because of its maturity and portability among operating systems like Windows, Mac OS X, and Linux. Let’s see our program once more, this time in Java:

public class NamePrinter
{
public static void main(String [] args)
{
String[] names = {“Alice”, “Bob”, “Catherine”, “Dave”};
        for (String name : names)
{
System.out.println(“Hello “ + name);
}
}
}

This example is the most involved and probably the most cryptic as well. It requires a bit of overhead, like the “NamePrinter” and “main” wrappers you see, but then we see our familiar tasks once again. We set up the list, then print a line to the system output for each name in the list. Java can be heavy-handed for small tasks like this, but large projects often benefit from Java’s speed and features that increase its reliability as compared to other languages.

You might wonder why there are different languages at all, if they all do roughly the same thing! Part of the answer is simply that different industries and companies adopted different languages that seemed right for their work at the time. These decisions tend to carry forward for years. Another reason is that not all languages are created equally. While most languages can perform the same tasks as others, some are faster at doing so or make those kinds of tasks easier on the programmer.