Everyday life is like programming, I guess. If you love something you can put beauty into it. -Donald Knuth
When I was in my sixth standard my dad brought me a laptop. It was Sony Vaio. It was very exciting present for me. It was equally surprising for the aunties in the neighborhood seeing someone gifting a laptop to a sixth standard kid. But, for me it was great to have a laptop. As everyone else does I too loved the new gadget. I even missed my school on that day. Then after continuosly using for around 7hours I thought of giving it a break. My dad wasn’t home. I didn’t know to shut it down. I struggled for around an hour then somehow managed to shut it down. Then I thought of exploring the computer that troubled me.
From a kid struggling to shutdown a windows pc I think it is a long journey for me now to be able to create standalone programs. Today for people like me who are interested in learning new stuff I am going to introduce programming. This article is totally for beginners.
“Whoa!! Programming, is a tough job man” is what many people who have not tried will say. It isn’t really that technical. Trust me it is not rocket science and can be learned with a little bit interest.
Programming: what exactly is it?
Programming is simply instructing the computer to do a task. It is similar to that of instructing someone to do a particular work.
“Really!!? Is that that simple. Then why doesn’t this computer listens to me?”. No, it won’t because it is not made to understand your language. It cannot understand words as we do. All it knows is a single language. It is called the Machine Language.
Machine language simply contains of binary and hexadecimal values which are written in a way to instruct the computer to perform a task. Simply saying it is just a combination of zeroes and ones but a million of them.
But!! Do we need to keep on writing zeroes and ones our whole life just to tell the computer to copy a file. Absolutely no! We have a life to live man. So, the burden of writing these zeroes and ones is reduced by creating programming languages. Come on its not that complicated let me explain.!
Programming Languages: Explained
A programming language is a formal language that specifies a set of instructions that can be used to produce various kinds of output. [As in Wikipedia]
There are two types of programming languages:
- Low level programming languages
- High level programming languages
Most of the programming languages that we use today for example C, Pascal, Fortran etc. are higher level programming languages. They are similar to that of the languages we speak. Wait, but didn’t I say that computer can’t understand our language then how do they understand these higher level languages. One fine day God blessed the computer to understand us ;p ! Lol. Sorry I was just kidding.
Every higher level language has. a translator of their own. The translator translates these languages into machine code. These translators are popularly known as Compilers.
These compilers change the code written in higher level languages into machine code. It uses a special process called parsing.
So for the programs written in higher level language to perform the desired action it takes three steps:
- Writing the instructions (the code)
- Changing it into machine code using a compiler (compiling)
- Running the program (Executing)
Doing something is a better learning process than reading something. Let’s make a program and see how it works.
The Hello World: First program
To create or make a program there are a few requirements. We need a text editor to write the code and save it. Then we need a compiler to change it to executable form.
If you have a computer running any of the versions of Ubuntu then you already have a text editor and compiler installed.
But if you have a pc running any of the versions of windows I recommend you to install turboc. A compiler for C.
After opening it copy the code below and paste it in the Notepad.
Now after pasting it in the Notepad. Save it as “Hello.c”, don’t forget to set the file type to “All Files”. Remember the folder where you have saved the file.
Now open then folder where the Hello.c file is located. Congrats we have created a program. But to be able to run it we have to change it into machine code for which we are going to use the compiler.
Open the terminal using ctrl+alt+t. Then change its working directory to the files location. Using “cd [file_location]” where [file_location] is the location of the folder containing “Hello.c”.
Now let’s compile the code to an executable code. Using the GCC compiler.
Run the following command
gcc Hello.c -o Hello_executable
Now if you see the same folder where the Hello.c file is located you can see another file named as “Hello_executable”. Now run the program using the below command.
It will display “Hello! World”. That’s your program.
Congrats now it is ready to be run. It is your very own program in C. Hi-Fi?.
For windows PC the process is same. The only thing that changes is the compiling process. You have to open the compiler and from file menu click “open file”. After opening the file. Click the compile button. There you are you have your executable program ready double click it to run it.
Tips for beginners
I would recommend starting to learn programming in python because of the ease it offers in its syntax and is relatively less complicated. It also allows us to run the code without compiling. Thanks to the python interpreter that interprets the code and runs it for us without the need of compiling. This article was just to show you how fascinating programming is explore more. Self learning is the best learning.
Python tutorials are available in site like Tutorials Point. The link is mentioned in comments.
Comment your opinions in the comment section. I would highly appreciate comments and advices. Have a good day