Coder's Cat

How to learn all programming languages, YES! ALL!

2019-09-29

“Which programming language should I start with?”

Many beginners will ask this question when they start to learn coding.

“Which is the best programming language?”

Developers will come with this question after they have got real development experiences.

This kind of question about programming language probably will raise endless arguments, and you will never get the right answer.

Instead, the more important thing I want to share is: How to master the skills of learning a new programming language.

Learning new programming should be easy for skilled programmers. It’s normal for them to write code in a new programming language after a weekend study, or even several hours. The more skilled programmer just have a glance at the manual, and learn the language by finishing the tasks at hand.

Master the skills of learning “all languages” does not need talent; it requires the core knowledge of programming language and practices.

Of course, we do not need to learn all kinds of languages, but learn more programming languages will help us choose appropriate tools for any given task.

If Programming languages were cars …

There are thousands of programming languages in the world, only about 20 of them are widely used in the IT industry.

If we dig up a little bit, we will discover the truth that all languages share a few features.

file:img/2019_09_25_learn-pl.org_20191115_180212.png

Let take car for example, there are different cars in the world. Some cars are compact and powerful, and some are slow and bulky. Different brands of cars stand for different kinds of driving experiences.

If someone knows how to drive one car, he will know how to drive most other cars; even the new car is a different brand.

Why? Because different cars share many common things, they are fundamentally built with engines and tires. Cars were designed for the same purpose: driving you to the target.

[bctt tweet=”Programming languages are designed for the purpose: express programmer’s ideas.”]

Why are there so many programming languages

In the computing world, programming languages are serving two roles:

  • Programmers using them to give commands to machines, tell them what we need, and get what we want.

  • Convey ideas to other programmers, share our experience and vision.

    So code is “message” for programmers, and also for the machines. This involves the trade-off in programming language design and implementation.

The main reasons for so many programming languages should be:

  • The hardware and computing theory are evolving. Generally speaking, programming languages are designed easier to use and with more expressive power.

  • Computers are applied to so many areas; corresponding domain languages were invented.

  • Different Programmers have various design methodology and philosophy

    Languages have different kinds of syntax or features, but fundamentally they are the same in a formal mathematical end, they are all Turing complete. This means in plain words: all languages can be used to implement arbitrary algorithms.

The basics of programming languages

Almost every programming language contains these categories of elements, they are all about “abstraction” actually:

  • Data types and data abstraction

  • Control flow and control abstraction

  • Abstractions on low level

  • Supplement and abstraction for the specific domain

    The reason why we can master all programming languages is: The language concepts are limited, less than 15 of them are commonly used.

    Procedural
    Object-oriented
    Pointer
    Recursive
    Exception
    Static type
    Dynamic type
    Type inference
    Lambda function
    Garbage collection
    Continuation
    Macro and Metaprogramming

    Programming language concepts tend to be constant, like design principles.

    The language designers borrow ideas or concepts from each other, use them with a different implementation. So sometimes we may say PL_C is the son of PL_A and PL_B, and PL family tree would be like this:

    Understanding these concepts will not just help us learn a language quicker, also helps a lot to write better code. For instance, functional programming languages have different coding styles and paradigms with object-oriented programming languages. If you didn’t understand the differences between them, bad smell of code will be unavoided in practice.

Focus on language concepts, not syntax

So we want to learn language concepts, but how to learn them?

To fully understand a programming language concept, we need to answer these questions about it. Why the language concept is invented; what is the target issue that needs to be solved; what are the benefits and drawbacks; and even how is it implemented.

Let’s take GC for example. The first question should be, what’s GC?

A quick search on Google, we will redirect to the Wikipedia GC page. We invented GC to solve the problem of memory management; it will reduce memory errors in a program, writing code with GC will be easier since we don’t need to manage memory manually.

The cost is performance since there will be extra code to allocate and free memory. When you are using a programming language with GC, pay attention to how GC affects your performance.

After some practices, we need to know how GC works, what algorithms are used? There are many kinds of GC implementations, with its own pros and cons.

It’s a good opportunity for you to learn new language concepts when you learn a new language.

For instance, if Ruby is your first OO language, then it is a good chance for studying the pros and cons of OO seriously. A good understanding of OO will help a lot when you learn another OO language.

Implement or create a programming language

Don’t be afraid; interpreter and compilers are just a specific kind of program. Their input is your code, and its output is running your code or compiling code into byte-code or binary-code.

Implement or create a programming language could help you to conquer the deepest fear of programming languages. This is another secret for learning all programming languages.

file:img/2019_09_25_learn-pl.org_20190929_190908.png

Implementing a language does not need too much work if your language’s syntax is not complicated. Have a check at this project: Make a Lisp. Any language can be used to implement a Lisp. Lisp/Scheme has a clean syntax, which is easy to parse and widely adopted for programming language education.

8cc is a compiler for C programming language, it’s a useful reference if you want to write a compiler.

Good books about the implementation of programming languages are also useful for your learning:

The steps of learning a new programming language

With the target of “learn programming language concepts”, if you follow these steps, you will learn efficiently:

/#1 Understand this language’s design philosophy and general language features/

For example, if you begin to learn Ruby, let’s find what’s special for Ruby firstly.

file:img/2019_09_25_learn-pl.org_20190929_120327.png

Hmm, let’s dig deeper: http://www.ruby-lang.org/en/about/

Try to summarize the main features you need to understand before you start to learn it:

  • Focus on simplicity and productivity; code is easy to read

  • With an interpreter. So you have GC, which means performance may be a problem for some tasks.

  • Everything is an Object, it’s a language with OOP, and even “pure OOP”.

  • Flexibility. We also can redefine many parts of the language.

    Knowing the most important features of the language, including its benefits and drawbacks. This will help you much when you start coding in this new language, and it serves as a road-map for you.

/#2 Learn syntax and practices with tutorials or books/

You need to master the fundamental parts of a language, including the syntax, basic IO, the debugging tools, the unit test tools, etc.

If you are a newbie, try to find authoritative books about it. Like the books written by the language creators, or search on Amazon with language names to find the books with great review ratings.

Remember, you’d better write code by yourself when you are not a guru, don’t just copy code. Practice the new language with exercism.io, and there are mentors to review your code and give you suggestions for free, it’s amazing.

If you are a language guru, just find some simple guides for this language or even some sample code in this language. Take a look at learnxinyminutes.com.

/#3 Read and write more code with the new language/

It’s time to start a project with the new language, with the knowledge of related ecosystems, tools, or libraries. You could start with a simple one, like a game of guessing the number or a simple book store or to-do apps. There will be many similar projects for starters on Github.

#4 Understand more details of language implementation

This is not necessary for every language. As I said in To Be a Programmer, an aspiring programmer will be interested in the details and implementation of their languages. And sometimes, bug even comes out because we don’t have good knowledge of language implementation.

How to choose your first programming language?

Choose your first programming languages according to goals and surrounding conditions:

1: Do you have a specific language mentor or do you need to learn a programming language in school?

If the teacher told you to learn C programming language for exercises. It’s an excellent chance to start with C because you have a mentor(your teacher) and classmates, it’s easier to get started with this help.

2: What is your goal?

If you want to build a Web application, it’s OK to learn Javascript/Python/Ruby. If you’re going to develop games, a suitable choice is C++. If your goal is processing data, a good alternative is Python/R. If you want to create an Android App, Java/Kotlin is your choice.

Just pick the language mostly used in your chosen domain. If you don’t know, ask for help with the experienced developers.

3: Do you want to apply for a job that requires a specific language?

Emm, you should just follow the job description, learn the listed programming language.

Don’t spend too much time choosing the first programming language. Get on the board quickly, after you have more experiences, it is not hard to transfer to another one if you don’t like it or your problem domain changes.

Which programming language is the best?

file:img/family-crisis.png

This also depends on your domain. Every programming language has its pros and cons. There is no such programming language suitable for every task. If it exists, we just need to learn this one, right? Remember No Silver Bullet.

Almost every programmer has his favorite programming language because of different tastes. Some people claim their preferred language is the best. Don’t be fooled by them; their favorite does not mean best.

For personal taste, my favorite languages include C/Ruby/Lua/OCaml. I am productive with them. It’s maybe not your taste; you should try different languages and find a favorite of yours.

Someone said don’t consider yourself a serious programmer until you know at least 5 programming languages.

file:img/2019_09_25_learn-pl.org_20190929_180550.png

As I elaborated above, you should not focus on learning more and more languages. You should try to learn more language concepts and design principles.

If you are using a procedural programming language in daily work, why not learn an object-oriented one, if you are using a language with dynamic types, why not learn a new one with static types.

These are my tips for choosing the next programming language.