(After the previous part: Part 0: Introduction)
Summary: Introduction to programming and algorithms, reasons for choosing python.
What is programming?
In simple words, programming is just talking to computers. It is similar to learning a new language in the sense that you learn how to order a computer to do something for you. However, the problem is computer itself is really dumb (no matter how smart things it can do after getting programmed!). So you have to give it painfully clear and explicit instructions to make it do anything.
Before I give a concrete example of programming, imagine you have an assistant who does everything for you. However, the only problem is that he is really dumb (still smarter than a computer). Yesterday you asked him to make simple peanut-butter sandwich for your breakfast and he made a mess! So today you are giving him instructions:
- Get whole-grain breads
- Put peanut-butter on them
- And finally put those breads together
No matter how dumb your assistant is, hopefully after this instruction he will be able to make a sandwich, but if you ask a computer (assume it is a robot with hands!) to do this job, it will still fail because all of the statements are still ambiguous. Let’s go through them again:
- Get whole-grain breads: How many? 1, 2, 100?
- Put peanut-butter on them: Both side single side? How to put peanut-butter? What to use? How much peanutbutter to use?
- And finally put those breads together: How should we put them together?
So let us write another instruction, which is very explicit and clear:
- Get 2 whole-grain breads, 1 peanutbutter jar, 1 butter knife, 1 table spoon
- Take one of the breads and put 1 table spoon on peanutbutter on it.
- Then smooth out the butter with a knife.
- Similarly do the other loaf.
- Finally put two breads so that the faces with peanutbutter on top are facing each other!
Now you understand what I mean by painfully unambiguous and clear! Watch the video from CS 50 to see how things can go wrong if you don’t have a precise algorithm.
The recipe you just made is called “algorithm” in computer programming. Before you solve any problem you need to solve it yourself and give the computer all the ingredients and the recipe (algorithm) to solve it.
Now you may ask, why do we use computer if we need to solve the problem ourselves first. Very good question! The answer is that a computer is very, very fast compared to a human being. Once you teach the computer how to solve 1 class of problems, it can solve any of those problems in future extremely fast. This great advantage of fast automation is what made computers so popular.
If you want to know a bit more about algorithms you should check this nice animated tutorial video by Dr. David Malan, the famous CS50 course instructor from the Harvard University.
You probably thought about a big snake when you heard the name python. Here we are of course talking about the computer programming language Python. Like there are many languages in the world, there are many programming languages to talk to computers. So you may ask, why I chose python and why you should learn python instead of any other languages. In general, people use different languages for different purpose, but python is one of the very few languages that is used for almost everything. So if you learn python you can pretty much do anything!
That is probably the main reason python got so popular in the last few years.
Apart from that here is my laundry-list of reasons for which I love python and you should too:
- Python is smarter. In python you don’t need to tell the computer that you are working with a number when you can clearly see that it is a number.
- As a result, you need to write a lot less code than most other languages for doing the same work, which is great if you are lazy like me!
- As python is very popular people have written a lot of code in it and made many libraries (extra functionalities) that are freely available for your use. So basically no matter what you want to do with python almost always you will find a library. So instead of working hard and coding that functionality, you can work harder on real problem solving and do more with less code!
- Finally according to xkcd, python helps you to fly!
Tarik Adnan Moon
Harvard College, Class of 2015
Previous Part: Part 0: Introduction
Next Part: Part 2: Preparing for the Magic
All parts: Play with Python