Basics of Programming

by Gautham Pai

What is a programming language?

Why do we need specialized programming languages (like C, Python or Java) to talk to a computer? Why can't computers understand English the way humans do?

Humans understand human languages

We know that computers are basically bit processors. They take a stream of 0's and 1's, do some processing and generate another stream of 0's and 1's. Computers don't know what that bit processing "means". It is we humans who give a meaning to those bits.

Can't computers speak human languages? Why can't we use a human language to speak to a computer?

Machines don't understand human languages

  1. One reason is that, human languages are ambiguous. We use sarcasm (saying something without meaning it) and computers don't understand this.

As an example, read this sentence first and see what it means to you:

Rob doesn't know that John shot Jim.

Now see how the meaning changes with the stress:

  • Rob doesn't know that John shot Jim (which perhaps means others know, but Rob doesn't)
  • Rob doesn't know that John shot Jim (which perhaps means Rob knows someone shot Jim, but he doesn't know it was John)
  • Rob doesn't know that John shot Jim (which perhaps means Rob knows that John shot someone but he doesn't know it was Jim)

Language Ambiguity

  1. Another reason is that we can have grammatically correct sentences which are absolutely non-sensical. Here is a famous statement composed by Noam Chomsky:

Colorless green ideas sleep furiously

  1. A third reason is that, we as humans, know to speak a language, but we ourselves don't know how it works. We speak grammatically correct English, but we may not necessarily know the grammar of English, isn't it? We perhaps learnt to read and write in English first and then we learnt its grammar (the concept of subject, predicate, object, adjective, noun, pronoun, verb, adverb etc).

So, we now have a problem. Computers can only understand 0's and 1's. We only speak human languages. Can we speak in 0's and 1's?

Humans speaking the computer's language

If our brains were fast enough to understand and work with bits, we would not need anything else (sort of like the hero of The Matrix). But that is not the case. Our brains are not built to process bits. Computers cannot understand human languages and we can't speak in 0's and 1's.

Speaking in binary is not easy

So how do we make a computer execute tasks for us without requiring us to speak in 0's and 1's?

Until we figure out how our human languages work and we can teach a computer to understand human languages, we need something specialized, something that acts as a bridge between what humans want the computers to do and what these computers understand.

Programming Languages to the Rescue!

Programming languages are a way we do this. A programming language forms an intermediary between us (humans) and the computer. The nice thing about a programming language is that it resembles a human language (mostly English, although it doesn't need to be so), so it is easy for us humans to learn them and describe our problems and solutions to those problems. A programming language removes all the issues of human languages (no sarcasm, ambiguity, etc). But the good thing about these programming languages is that they can be easily converted to 0's and 1's, which means we can make a machine understand the instructions that we have expressed in the programming language.

How Programming Languages Work

Trivia about human languages and programming languages

While computers don't understand human language, there is one language that comes close and there are researchers who are trying to figure out if it can be used as a computer language. Do you know what language it is?

It is "Sanskrit"!

The formal way of describing the grammar of a programming language is called the Backus-Naur form or BNF for short. While, engineers were inventing a mechanism to formalize the grammar of programming languages as late as 1900s, a grammarian called Panini had described a similar structure for Sanskrit as far back as 4th century BCE!

To learn more, search for -> sanskrit programming language in Google.

There have been significant advancements in enabling computers to comprehend human language, with virtual assistants like Siri, Google Assistant, and Alexa leading the way. Moreover, the emergence of generative AI models like OpenAI's ChatGPT, Google's Gemini, Meta's Llama etc has marked a substantial leap towards achieving Aritificial General Intelligence (AGI). These cutting-edge technologies can now engage in more sophisticated conversations, generate human-like text, and even create content, bringing us closer to realizing the potential of artificial general intelligence. We are at the cusp of an evolution, where learning programming languages is going to change forever!

What exactly are we doing when we write a program using a programming language?

It boils down to what a computer does. A computer takes a stream of 0's and 1's, processes it and sends back another stream of 0's and 1's. What we do in a programming language is no different.

Computers use binary because they operate on electrical signals, which can easily be represented by two states: off (0) and on (1).

Input -> Process -> Output

We bring some data (in the form of 0's and 1's) into memory, we process it and then we send it out. For example, we may read something from a file, do some processing and write it back to another file. We may read from a database (which is simply, a large store of data in our storage device like hard-disk), do some analysis and send the result out over the network. We may read something that we received over the network, perform some processing and write the output to screen. All the work we do involves some form of input, process, output.

Input Devices -> Process -> Output Devices

The Role of RAM and CPU

How do I learn a programming language?

All of us know at least one human language. Some of us know multiple. How did we learn human languages?

Did we start with the grammar?

Child Learning Grammar

No! Grammar "happened" to us. We didn't consciously learn it. When our moms taught us our mother tongue, she certainly didn't open the grammar book and start teaching us from that!

We perhaps started by learning a few words. Then we learnt to put these words together, we perhaps started with 2 words, then 3 and then started forming longer sentences.

Imagine that we are in a new city and we don't understand the local language. How do we learn to communicate with the local people? We will perhaps learn to greet them, respond to someone when they greet us, learn about various food items and how to order them etc. In other words, we learn some basic, commonly occurring words and how to put them together and communicate.

They say that if we know 20% of a human language (English/French/...), we can use that in 80% of the cases. So the trick in picking up a new language is to not go and buy a dictionary and start mugging up the words, but in finding out what those 20% words are that we can use to have a reasonable conversation.

Programming languages are similar. This 20% is what we can call as the "Basic constructs" and forms the first dimension of learning a programming language.

But this will not help us gain mastery over the language. That is an entirely different exercise. To understand that we need to know about the 3 dimensions of learning and mastering programming languages.

Which programming language should I learn?

How many programming languages are there?

There are hundreds!

New programming languages are emerging as we speak.

Which are the most popular programming languages out there?

Popularity is hard to define. We would like to say that, when starting off on a new project, if a certain language is a preferred choice for a certain job we can consider it popular.

Here are the most popular languages on GitHub as of Quarter 1 of 2021.

So this brings us to the question, if there are so many programming languages, which programming language should we learn?

There is no "best programming language" that fits every task. Each language has its own strengths and weaknesses.

Different languages are better suited for specific types of jobs:

  • Operating Systems: C, C++, and Rust are often used because they provide low-level control and efficiency.
  • Data Analysis: Python and Java are popular due to their simplicity and the powerful libraries available.
  • Client-Side Development: JavaScript is the go-to language for creating interactive websites.
  • Microservices: Golang (Go) is widely used for its performance and scalability.

The best language to use depends on what you're trying to accomplish.

There is a possibility that we will encounter several programming languages during our career. Even the smallest of the software projects use 2-3 different programming languages. Different organizations use different programming languages in different applications.

Imagine you're working on a simple e-commerce website. This project might involve multiple programming languages:

  • JavaScript: This language is used to make the website interactive. For example, when a user clicks "Add to Cart," JavaScript might handle the action that updates the shopping cart without needing to reload the entire page.
  • Python (or another server-side language like Java or PHP): This is used on the server to handle things like processing payments, managing user accounts, and storing product information in a database.

Even this relatively small project involves at least two different languages, each serving a unique purpose. This example shows how different languages work together to build a complete software application. In larger organizations, it's common to encounter even more languages across various parts of a system.

So don't worry about which language is the best. Try to learn as many languages as you can! Get good at learning to learn and master any language!

The trick is to focus on the concepts that are common across all languages and learn those concepts so that we can relate to all languages.

The 3 dimensions of learning and mastering programming languages

How can we learn and master a new programming language quickly? Is there a trick?

Here, we teach you the art of learning "any" programming language.

We have come up with a chart to help beginners understand their approach to learning programming languages. We call this the "3 dimensions to learning a programming language".

Three Dimensions of Learning a Programming Language

Here is a summary of the 3 dimensions:

  1. The first dimension is what we call as "Basic Constructs". This is the 20% of the language with which we can do some reasonable work. Every programming language has these basic constructs - data types, variables, operators, expressions, statements, conditionals, looping, functions and modules.
  2. The second dimension is "Programming Paradigms". Learning the paradigms of a language is what helps us gain mastery over a language. This is what graduates us from just "speakers" of a language to a "poet"! Paradigm mastery takes time initially but once we gain some experience, it is easy to relate to the same paradigms in new languages that we are learning.
  3. The third dimension is "Third party libraries". This is the dimension where we gain mastery over the libraries that help us do our jobs faster. We learn a specific programming language to solve a specific task. For example, we may be learning Python because we want to do some data analysis. We may be learning Golang because we want to build a web service. Now, when doing these specific tasks, we usually don't do everything ourselves and instead rely on several libraries that are written by other open source developers. We don't like to reinvent the wheel. If someone has already done something well and if it is legally okay to reuse it, why not?! This dimension is about discovering, learning and mastering these third-party libraries.

Not All Languages Are Programming Languages

A language which has variables, operators, expressions, statements, conditionals and looping can be called as a "programming language". The technical term for these are "Turing complete languages".

There are many types of languages we come across during software development. Not all of them are programming languages. For example, HTML, CSS, XML are not programming languages because they lack some of these features.

Let us explore these dimensions in subsequent articles.

Test Your Knowledge

No quiz available

Tags