You’ve decided to learn to code. Excited and anxious, you open Google and enter a search “how to learn programming.” Suddenly, you are faced with a myriad of possibilities: from coding classes to bootcamps, from books to blogs.
How do you choose the best way to learn coding fast?
First, don’t panic: there are lots of ways to enter the wonderful digital world, and there is no right or wrong way to start. Second, allocate some time to research what your goals are and what the best way to get there is. And third, enjoy – you are about to change your life!
The WHAT
Certainly, the first thing to decide is what programming language you want to start with. There are about 700 languages to choose from, so choose wisely.
Just like some kids are popular in high school, some languages are currently riding the popularity wave, but that does not necessarily mean that they are the best choices for a beginner. The top languages right now are:
1. Python
2. JavaScript
3. Java
4. C#
5. C
6. C++
7. Go
8. R
9. Swift
10. PHP
Programming languages have lots of subdivisions, but take a look at the major categories.
1. Scripting languages: this includes Python, JavaScript, Ruby, PHP, etc.
These are easier to learn and more forgiving in terms of syntax errors, so it’s a common choice for beginners. In fact, Python was designed to be more readable and understandable than other languages, still it is widely used in AI applications and machine learning.
JavaScript is also a popular choice since it is intuitive and it runs through your browser, so there is nothing to install. JavaScript is used for developing web pages and if your goal is to add some pizzazz to your website, then this is definitely the way to go. From interactive maps to animation, JavaScript produces some of the most visually appealing user interfaces.
Here is an example of JavaScript that creates an interactive button named “Try it.” Once the user clicks this button, a dialog box comes up prompting the user to enter their name, and when the user does that, the script greets the user by name.
<button onclick="buttonClicked()">Try it</button>
<script>
function buttonClicked () {
var name = prompt("Enter your name : ");
document.write("Hello, " + name); }
</script>
2. High level programming languages: Java, C, C++, C#, etc.
High level programming languages have more of a learning curve than scripting languages, but once you know one of them, it is much easier to learn other high level programming languages, as well as scripting languages.
Beginners often find the syntax requirements frustrating: it takes getting used to, and it can be discouraging when you see a 20-line program compile with 40 errors. But fear not: once you persevere and learn the syntax, you will forget your previous frustrations. You will soon find that once you fix the first syntax error, the others magically go away without your interference.
High level programming languages are compiled languages, and the compiler acts as the first line of defense against a programmer’s mistakes. Even though scripting languages are easier on you in terms of syntax, finding errors may take longer. Imagine you create a variable that is supposed to hold an integer, and by mistake you put text in it. If you then try to add it to another integer, then you will find that your result will be NaN (not a number), and you will wonder why. If you’re in a high level programming language and try the same thing, the compiler will complain and not let you do it. It’s like you’re back in your teenage years and the compiler acts like a strict parent that will not let you go out with your friends because it knows what can happen.
Also, choose wisely within high level programming languages: they are not created equal. The easiest ones to learn are Java and C# because they free the programmers from having to allocate memory themselves. That saves a lot of frustration for a new programmer because a memory error can manifest itself in many ways, and often times it is hard to reproduce and debug.
The notorious malloc, calloc, and alloc are the three-headed dragon that deals with memory allocation and acts as a constant source of headaches for even seasoned C and C++ programmers.
Let’s say you chose Java, which is a reasonably easy high level, object-oriented language. The question then becomes: do you learn the object-oriented part (that has to do with classes, objects, and inheritance) first, or the procedural (that is focused on methods, conditionals and iteration) part?
The answer is: start with the computer programming basics. Do not get overly concerned with classes and objects, and forget inheritance altogether until you are comfortable with the other material. Sure, you will have to put your methods in a class, but beyond that you will write your methods just like in a non-object-oriented language.
Here is an example that prints out all odd integers from 1 to 100 in three different high level languages:
Java
for (int i = 1; i <= 100; i += 2) {
System.out.println(i);
}
C#
for (int i = 1; i <= 100; i += 2) {
Console.WriteLine(i);
}
C++
for (int i = 1; i <= 100; i += 2) {
cout << i;
}
C
for (int i = 1; i <= 100; i += 2) {
printf(i);
}
As you can see, the syntax is somewhat different when invoking a function to print to console, but overall the loop is the same. Learning one high level programming language will not only allow you to learn how to code, but also to learn other programming languages more easily.
Think of learning Spanish: after you know enough, it will be easy to learn a similar language such as Italian or French.
3. Specialty programming languages
If you have a specific goal that requires a more specific language, then the use dictates the type of language to learn. For example, to create static web pages, you can use HTML, which is not really a programming language, but a markup language to display information. Using many different tags you can make the font, color, or arrangement of information different. HTML is the easiest to learn and use.
If you need to analyze data or statistical packages, you will need to learn the R programming language. It provides various methods for data analysis, like linear and nonlinear regressions, time-series analysis, clustering, etc.
If you are working on a database, then SQL is the language that you will tackle. SQL is a structured query language that allows to get data with specific characteristics from the database. To select students with a GPA of more than 3.4 for Dean’s List from a table with student information you will use a query that looks something like this:
SELECT ID, FirstName, LastName
FROM Student
WHERE GPA > 3.4
Again, your needs will dictate the choice of language. However, if you just want to learn programming in general, avoid specialty languages or more obscure languages: they are the odd ones out, and learning them will not necessarily help you when learning others.
Lisp, for example, is a recursive language that was the second programming language to be created and is still used in AI applications. However, the syntax is convoluted and is not easily understood. Here is a function that calculates Fibonacci numbers, as an example:
(+ (fibonacci (- N 1)) (fibonacci (- N 2)))))
All of these parentheses combined with prefix notation can make a new programmer’s head spin.
The HOW
Once you’ve zeroed in on your language of choice, it’s time to think how you will learn it. The abundance of choice is a good thing in that one can find tutorials for all levels and all needs on the internet. But it’s also a not-so-good thing, because finding the right tutorial for you might be a monumental task.
The best way of learning is working with an experienced programming tutor. The tutor will be able to cater to your specific needs in terms of the language, the level, and the learning speed and style. But if you are diligent enough and don’t mind some frustration that comes with learning coding on your own, then here is a plan of action.
First learn computer programming basics. The suggested order is:
1. Identifiers (variable names) and primitive types (integers, doubles, characters, and booleans)
2. Operators and output to the screen
3. Methods
4. Conditional (if) statements
5. Iteration – for and while loops
6. Basic data structures – Arrays
These constructs appear in most programming languages, and knowing them will allow you to later switch to another programming language and learn to code in it with ease.
Next, add on the language specific concepts, like the object-oriented paradigm for object-oriented programming languages, memory allocation for C or C++, etc.
Download a programming environment for your language. This environment, called an IDE (integrated development environment) helps by compiling the program as it is typed, and provides suggestions how to fix the mistakes. Examples of an IDE are Visual Studio for C#, C++, Visual Basic, and other Microsoft languages, or NetBeans or Eclipse for Java. As you read, try coding in parallel with understanding the material, so that you can see live what happens. This is the most important step – you have to practice and learn by doing.
Common pitfalls, and what NOT to do when you’re learning to code
If you are learning a language by yourself, it is easy to skip the boring part that deals with proper coding etiquette. Resist the urge to skip this step, and do read up on the best programming practices.
1. Preparation
Name your variables short and meaningful names, so that it is easy for others to understand your code, and it is easy for you to understand your code when you look at it a month later.
Avoid long names like allStudentsWhoGotAGPAGreaterThan3, or non-descriptive names like x.
2. Learn the correct casing for your language
For variables, some languages use camel case with the first letter capitalized or not capitalized (numStudents or NumStudents), some prefer snake case (num_students). For methods, some capitalize the first letter, and some don’t, etc. Of course, it’s not wrong to name your variable as you wish, but it’s more polite if you follow the language guidelines.
3. Spend some time to learn about code quality
In programming, any algorithm can be done in multiple ways, and while there may be more than one elegant solution, there definitely will be many solutions that include unnecessary cases or do an obvious task in a way that is very convoluted. It comes with experience, but try to write the code and then see if you can make it simpler and more elegant. However, avoid the urge to condense the code to the point where it is unreadable. There is a fine line between succinct and illegible.
4. Don’t panic
It is easy to get frustrated when your program does not compile, or produces an error or an unexpected result. If you persevere, you will be rewarded at the end with code that works and looks good. Programming is just like detective work: few can write a perfect program on their first try, so you can expect some errors in the beginning, and that’s OK: you will learn to fix them and produce a working result. Of course, using an IDE will make learning syntax easier by giving hints.
5. If you are writing a complicated program, don’t do it all at once and then try to figure out why it’s not working
Take an iterative approach and do a small chunk first, test it, and then proceed to the next chunk, etc. For example, if you are working on a 2D array, try to perform an operation on only one row, and then surround that code with a loop to go through all of the rows in the array.
6. Ask for help
There is a world of information on the internet: you can ask on discussion boards, or seek help of a coding tutor. Recognizing when you are stuck and need help will yield better results and will help you learn coding fast.
In conclusion, congratulations: you are about to enter the wonderful world of programming that you will conquer one step at a time. All of current programmers started as beginners, and learning programming is a challenging but exciting task. So, the most important thing is ENJOY!