How to choose your first programming language

480 readers like this.
How university open debates and discussions introduced me to open source

Opensource.com

The reasons for learning to program are as a varied as the people who want to learn. You might have a program you want to make, or maybe you just want to jump in. So, before choosing your first programming language, ask yourself: Where do you want that program to run? What do you want that program to do?

Your reasons for learning to code should inform your choice of a first language.

In this article, I use "code," "program," and "develop" interchangeably as verbs, while "code," "program," "application," and "app" interchangeably as nouns. This is to reflect language usage you may hear.

Know your device

Where your programs will run is a defining factor in your choice of language.

Desktop applications are the traditional software programs that run on a desktop or laptop computer. For these you'll be writing code that only runs on a single computer at a time. Mobile applications, known as apps, run on portable communications devices using iOS, Android, or other operating systems. Web applications are websites that function like applications.

Web development is often broken into two subcategories, based on the web's client-server architecture:

  • Front-end programming, which is writing code that runs in the web browser itself. This is the part that faces the user, or the "front end" of the program. It's sometimes called "client-side" programming, because the web browser is the client half of the web's client-server architecture. The web browser runs on your local computer or device.

  • Back-end programming, which is also known as "server-side" programming, the code written runs on a server, which is a computer you don't have physical access to.

What to create

Programming is a broad discipline and can be used in a variety of fields. Common examples include:

  • data science,
  • web development,
  • game development, and
  • work automation of various types.

Now that we've looked at why and where you want to  program, let's look at two great languages for beginners.

Python

Python is one of the most popular languages for first-time programmers, and that is not by accident. Python is a general-purpose language. This means it can be used for a wide range of programming tasks. There's almost nothing you can't do with Python. This lets a wide range of beginners make practical use of the language. Additionally, Python has two key design features that make it great for new programmers: a clear, English-like syntax and an emphasis on code readability.

A language's syntax is essentially what you type to make the language perform. This can include words, special characters (like ;, $, %, or {}), white space, or any combination. Python uses English for as much of this as possible, unlike other languages, which often use punctuation or special characters. As a result, Python reads much more like a natural, human language. This helps new programmers focus on solving problems, and they spend less time struggling with the specifics of the language itself.

Combined with that clear syntax is a focus on readability. When writing code, you'll create logical "blocks" of code, sections of code that work together for some related purpose. In many languages, those blocks are marked (or delimited) by special characters. They may be enclosed in {} or some other character. The combination of block-delimiting characters and your ability to write your code in almost any fashion can decrease readability. Let's look at an example.

Here's a small function, called "fun," which takes a number, x as its input. If x equals 0, it runs another function called no_fun (which does something that's no fun). That function takes no input. Otherwise, it runs the function big_fun, using the same input, x.

This function defined in the "C" language could be written like this:

void fun(int x)
{
    if (x == 0) {
        no_fun();
    } else {
        big_fun(x);
    }
}

or, like this:

void fun(int x) { if (x == 0) {no_fun(); } else {big_fun(x); }}

Both are functionally equivalent and both will run. The {} and ; tell us where different parts of the block are; however, one is clearly more readable to a human. Contrast that with the same function in Python:

def fun(x):
    if x == 0:
        no_fun()
    else:
        big_fun(x)

In this case, there's only one option. If the code isn't structured this way, it won't work, so if you have code that works, you have code that's readable. Also, notice the difference in syntax. Other than def, the words in the Python code are English and would be clear to a broad audience. In the C language example void and int are less intuitive.

Python also has an excellent ecosystem. This means two things. First, you have a large, active community of people using the language you can turn to when you need help and guidance. Second, it has a large number of preexisiting libraries, which are chunks of code that perform special functions. These range from advanced mathematical processing to graphics to computer vision to almost anything you can imagine.

Python has two drawbacks to it being your first language. The first is that it can sometimes be tricky to install, especially on computers running Windows. (If you have a Mac or a Linux computer, Python is already installed.) Although this issue isn't insurmountable, and the situation is improving all the time, it can be a deterrent for some people. The second drawback is for people who specifically want to build websites. While there are projects written in Python (like Django and Flask) that let you build websites, there aren't many options for writing Python that will run in a web browser. It is primarily a back-end or server-side language.

JavaScript

If you know your primary reason for learning to program is to build websites, JavaScript may be the best choice for you. JavaScript is the language of the web. Besides being the default language of the web, JavaScript has a few advantages as a beginner language.

First, there's nothing to install. You can open any text editor (like Notepad on Windows, but not a word processor like Microsoft Word) and start typing JavaScript. The code will run in your web browser. Most modern web browsers have a JavaScript engine built in, so your code will run on almost any computer and a lot of mobile devices. The fact that you can run your code immediately in a web browser provides a very fast feedback loop, which is good for new coders. You can try something and see the results very quickly.

While JavaScript started life as a front-end language, an environment called Node.js lets you write code that runs in a web browser or on a server. Now JavaScript can be used as a front-end or back-end language. This has led to an increase in its popularity. JavaScript also has a huge number of packages that provide added functionality to the core language, allowing it to be used as a general-purpose language, and not just as the language of web development. Like Python, JavaScript has a vibrant, active ecosystem.

Despite these strengths, JavaScript is not without its drawbacks for new programmers. The syntax of JavaScript is not as clear or English-like as Python. It's much more like the C example above. It also doesn't have readability as a key design principle.

Making a choice

It's hard to go wrong with either Python or JavaScript as your first language. The key factor is what you intend to do. Why are you learning to code? Your answer should influence your decision most heavily. If you're looking to make contributions to open source, you will find a huge number of projects written in both languages. In addition, many projects that aren't primarily written in JavaScript still make use of it for their front-end component. As you're making a choice, don't forget about your local community. Do you have friends or co-workers who use either of these languages? For a new coder, having live support is very important.

Good luck and happy coding.

picture of Kojo Idrissa aka TransitionKojo
I'm a new software developer (1 year) who changed careers from accounting and university teaching. I've been a fan of Open Source software since around the time the term was coined, but I didn't have a NEED to do much coding in my prior careers.

5 Comments

Very rightly said that it's very difficult to make a choice between Python and Javascript. Both of them are very powerful languages. Whatever language one chooses, starting with a great tutorial is one of the most important pre-requisite to hit the ground running. https://hackr.io can be used to find the best online programming tutorials.
All the best. Don't Quit!

There is no mention of the asynchronous nature of javascript (aka ecma-script). Much nice client-side development can be done without concerns as the browser event loop tends to hide this complexity from the programmer. Not so in the node.js environment where asynchrony and callbacks are necessary from the start. Imagine the confusion of writing...

fs.open (file);
console.log("File opened.");
fs.write ("Hello, world");

and receiving...

"File opened." followed by an exception for trying to write to an unopen file.

With respect to the initial questions: Where do you want that program to run? What do you want that program to do?, and staying with the choices presented, I would strongly suggest the neophyte limit use of javascript to the browser and python to the server. Javascript was initially designed for the browser and to apply it on the server side (node.js) adds conceptual complexity to be avoided at the outset.

I would never point a new programmer at Javascript. It's a needlessly inefficient, sloppy language that becomes exponentially more murky the more code you write. It's in all the browsers by fiat, not by merit; no alternative languages are even offered for honest competition.

Even Assembler would be a better choice, at least the student could appreciate first hand what makes the CPU faster or slower.

For a first language I think two things are important: learning good principles and getting positive feedback. There's a balance and I think Python does a nice job with that. There's so little overhead involved with getting started compared with the complex syntax of JavaScript - how do you explain the necessity of all of the braces and semicolons to a noob? Forget about explaining how the source code goes in a web page document that is rendered by a browser... way too much for a first exposure to code.

Plus the resources are copious for beginners in Python whether it's ebooks like www.brainstemschool.com or tutorials and exercises like at code.org or Khan Academy.

There's a lot out there for JavaScript also but I just don't think a beginner has the context to make it meaningful and motivating.

"In this case, there's only one option. If the code isn't structured this way, it won't work"

You are incorrect. Your fun python function can be written in at least 2 other ways.
def fun(x):
no_fun() if x == 0 else big_fun(x)

fun = lambda x: no_fun() if x == 0 else big_fun(x)

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.