What programming language should I start with? A variation of this question appears constantly across the Internet. For the most part, I avoid responding to these questions, because it is an impossible question. It doesn’t matter which language you start with, just choose one and go. I also felt like most responders were biased based on languages they know.
However, over the past weekend I began to rethink my position. My son and I are building a game system using the Raspberry Pico microcontroller. In a previous blog, we demonstrated our Python version of the game system. However, I am trying to transition that game system to C++ for better speed and control of RAM (which is extremely limited on the Raspberry Pico). Despite spending the majority of my life (and majority of my education) working with C/C++, I still faced significant challenges, which caused me to rethink my starting opinion on the best starting programming language.
History of Programming Languages
Before we dive into a language recommendation, let’s take a quick walk through programming language history. When the first “computer” was created in the 1820s, the only way to change the operation of the machine was to change the internal gears.
Although computers advanced from gears to electricity, this general limitation did not change until John Von Neumann invented the “shared program technique.” This established the idea that instead of rewiring for every new program, a simple machine could be driven by complex instructions. This was the change needed to lead to programming languages. The image below is a very small subset of some of the most popular languages (and their parents).
My Own History of Programming Languages
My own journey into programming started with BASIC (technically GW-BASIC). At some point, I transitioned to QBasic. QBasic offered a better IDE, and you no longer needed to put line numbers before every statement. In addition, in BASIC, you really couldn’t have functions (instead you used the GOTO statement to jump around the code). QBasic offered actual subroutines.
I don’t remember much about writing code in QBasic, but I do remember some of the games I created. One game was a state capital trivia game. I am not sure why I chose to make the game, but after making it, I was great with state capitals. I also made a political campaign simulation game. You could use your campaign money to buy posters and buttons (all text based) and it could simulate the final election.
In 6th grade, I started learning C++. I was so confused. There are a number of reasons. First, QBasic is an interpreted language. C++ is a compiled language. This means that you must use a compiler to translate your code into machine code. This increases the complexity of testing your code. To test your code, you must include relevant files and libraries and compile.
Through continued practice and learning, I definitely got better at both C++ as well as compiling. However, this does not mean that every time I compile it is flawless. Part of the reason for writing this blog was based on challenges I had compiling the Raspberry Pico C/C++ SDK. This made me think back to how difficult it was to start with C++. If driven enough, anyone can definitely overcome the challenges, but it may be more difficult than necessary for a first language.
What do you need to learn from your first language?
My advice that I started with is still accurate. Any programming language works. Before we talk about languages, let’s talk about what you need to learn with your first language. Programming involves a few different things: (1) we need the ability to input and output data; (2) store the data in memory; (3) we need to be able to perform some operation on the data (typically math); (4) we need to control the flow of the program to process data in the order that we want.
Input/Output
Computing devices are only valuable because they take in data, they do something with it, and they output the data. The simplest example is probably a calculator. You input numbers and operators (e.g., +, -) and output the result. In computers, the simplest input and output of a program is the command line. It is definitely not user friendly, but it is usually easy to implement in a programming language and to test.
Of course, inputs and outputs can become much more complicated. For example, a program can be a game that takes input signals from a keyboard or game controller and outputs the results, a beautifully drawn landscape to a screen. Input and output can also be to or from a network (e.g., the Internet) or files on the computer hard drive.
Data Storage
The second thing we need to do is to store data in memory. To do this, we use something called variables. You can think about a variable as a bucket that can be used to store different pieces of data. Like a bucket, I can reuse it to store different things at different times. I can also modify the thing held by the bucket (variable) (e.g., I can add food coloring to water stored in a bucket).
A more complicated type of data storage is called a data structure. It is basically a way to put related variables together. Data structures allow us to represent whatever we are trying to process in a more natural way. For example, we may have a data structure that represents our character in the game. It could include number of lives, position, score in one structure.
Data structures can also be used to show relationships. For example, a common structure in programming is a queue. This is used to handle data in a certain order. A queue processes data in the order in which it is stored. When you receive new data, you add it to the end of the queue. It must wait its turn before it is processed.
Data Operations
The third thing an aspiring programmer needs to learn is how to perform operations on the data. In most cases, this is math. For example, in a game, I may have a player sprite position. I need to take the input from the game controller and apply it to the sprite to move it and then output the visualization to the screen. To do this, I just need math. I need to take the value from the input controller. Appropriately scale it (i.e., multiply it by a scaling number) depending on how much influence it should have on the sprite and then add it to the current position.
Another types of data operations could be handling text. Given a string of characters, you can modify the characters. Add or delete characters or move the characters around.
Finally, we can perform operations on the more complicated data structures. For example, if we have a list of data structures, we can sort the list.
Data Flow
Next, a programmer needs to be able to control the flow of the program. The computer thinks in a very linear way. It has a list of commands to execute and it wants to execute in order. However, sometimes we want to rearrange the order of the program depending on the data. For example, in our imaginary game a rocket has been fired at the player. The rocket fired at our player could have two possible outcomes. Either it hit the player and we need to deduct lives, or it missed the player and the game can continue as it was before the rocket was fired.
To control the flow of the program execution, we use a few different types of statements.
- Functions or Subroutines: a subset of code. The program jumps to the start of the function, runs it, and then jumps back to where the function was called.
- Conditionals: choose a path depending on a condition. Examples of statements include: if/else, switch.
- Loops: repeats a block of code a certain numbers of times. Examples include: for, while, do … while.
How do you find your perfect language?
Now that we know what you should learn from your first language, which language should you pick?
Consideration 1: Interpreted Languages
First, let’s start with the reason for this blog post. I think you should start with an interpreted language. While learning a language, there is no reason to also have to learn the ins and outs of compiling. Examples of interpreted languages include: Python, JavaScript, Ruby, PHP, Lua.
Each of these languages allow you to learn faster by creating new code and running it. For example, in Python you can use the REPL (Run, Evaluate, Print, Loop) to type a line of code and see the result immediately.
For younger coders, Scratch and MakeCode are both possibilities. These are interpreted visual coding. They take away the need to learn syntax and focus on learning the basic programming concepts. My children both started with Scratch. However, it can be challenging to transition from Scratch or MakeCode to a written language.
Consideration 2: Coding Goals
For the second consideration, you should consider what you want to do with your developing coding skills. Learning to code can be frustrating. Everything can look correct in the code but give you the wrong result and there is seemingly no way to know why. This is true even if you know the language, but particularly challenging if you are trying to learn programming concepts and a new language at the same time. Therefore, you need something that will keep you interested through the frustrating moments. For me, my interest was building games.
Examples of goals:
- Website Development: JavaScript, PHP, Ruby
- Games: Python, GDScript (Godot), Lua
- Data Science: Python, R
A special note about C# in Unity. Normally, C# is a compiled language. Therefore, it would not meet the first consideration of an interpreted language. However, Unity hides the compilation making it seem like an interpreted language. You can make a code change and then start the game in Unity and your new code will run. Therefore, I would include C# in the list only if you are using it in Unity.
Shouldn’t I Choose a Language that is In Demand for Employment?
I see this question frequently in questions about first languages, and unfortunately, I also see it in responses. The answer is an emphatic “no”. Do not choose a language based purely on popularity or employability. Learning your first language is difficult. However, once you learn your first language, it is exponentially easier to learn your next language, so you don’t have to choose a language that is popular.
Conclusion
Hopefully, this post is helpful to picking your first language. The biggest key is to stick with it. Learning to code can be challenging, but is incredibly rewarding. For me, although I didn’t end up picking a coding career, it is my hobby. It provides an opportunity for me to use both creativity and logic. I also love problem solving, which coding provides plenty of opportunities to do.
Good luck and let me know in the comments what language you chose!