Programming for newbies, Part 1: Python

Hi all, this is my first post here at dotTech. There have been many common question when one decides to dive into “world of programming”. These questions includes but not limited to “which language should I learn?” or for those who want a lot of fun, will ask “which language should I learn first?”.

I cannot guarantee you that the answer I’ll provide here is the only and absolute answer, but you if you are going to treat it as starter, then congratulate yourself, you got it right. :)

I came to programming world wondering where I should start. I was having dim knowledge in HTML and almost nothing of CSS. I didn’t know loops except in Microcontrollers/Microelectronics programming which is very low level (and isn’t fun!). So I decided to search for a path.

My first hit was Visual Basic 6. It was such an easy work to make interface (few minutes to be precise) but what useless task it was! GUI without events is really useless! On the VB way, I found a book, but then I didn’t had any VB interpreter/IDE. Buying it from such country as mine, was a tedious job I could not afford, so I dropped it. :(

Not far from there I tried C using the book by the writers of C language itself (Kernighan and Ritchie). To such a newbie as I was, it was convoluted book you don’t want to read! But it did some good stuffs in my brain. It introduced me to loops and like stuffs. After there I dropped whole “dev – geekish” things and dedicated to electronics stuffs (believe me biasing single transistor isn’t fun!). Few years after that I wanted to go back to Dev game seriously. The result of my search will save you some pain of starting from scratch.

WHICH LANGUAGE SHOULD I LEARN?

That depends on what you plan to do with language. If you plan to talk to an English man, you will be sane if you’ll learn English. Same is valid for world of computers. I will do quick review of some languages I have tried. Note that, there are many languages out there; no one language is “the best one”. Rule of thumb is use the “right tool for the right job!”

WANT FUN? PYTHON DOESN’T BITE!

The first language I recommend for beginners is Python. As I quote from their official website:

“Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.”

The key to programming, in any language, is discipline and technique. By forcing you to write code in an organized manner via indentations, Python teaches beginners discipline and technique in one go. You work more quickly and create easy-to-read code that is easy to maintain even if you have thousands of lines of code. Although the reasoning behind using Python first may sound like a “baby step”, remember you need to learn how to crawl before you can walk. You will appreciate the discipline and technique Python teaches you when (if) you decide to move onto other languages.

Don’t forget Python interpreter is open source and platform independent so you will find Python on Windows, Mac OS X, and Linux alike. Also Python is self contained in that it comes packaged with its interpreter, Integrated Development Enviroment (IDE) called IDLE, and many standard libraries including ctypes (for accessing C/C++ DLLs), and Tkinter (for creating GUIs).

If you need to add more functionality to your Python, just download and install the third part modules like wxPython for wxWidgets users, pyQT for QT users and so forth.

In most Linux systems, it comes bundled while in Windows (not sure about Mac) you have to manually download and install it. After you get Python, it is very easy to use. To just test its feel, add the Python path to Windows path (I assume you are in Windows). Then at commandline, type “python” without quotes. It will display something like this:

To do a test “hello world” program, just type:

print ‘Hello world!’

(Note this is for 2.x not 3.x; it is different in3.x).

Below is the output you should see:

Simple, isn’t it? For writing something more useful, open IDLE, or any editor of your choice (NO MS NOTEPAD!), write your code and save it in .py extension. To run and see results, just open command line and move to the directory and type the following:

the_name_you_gave_the_code_file.py

Although not guaranteed, double clicking the file works also; but the method above is more reliable. If you dont like this long path, grab a different IDE of your choice and start coding! Every IDE offers a something little different than another IDE. For more on Python…continue reading!

Note: Current version of Python (3.x) is NOT backward compatible with previous version (2.x). I recommend use of ver 2.5.4 for those who need very stable version. Version 2.6 is the best choice and is being improved. Version 3.x isn’t very fun due to lack of modules. But keep learning 3.x too because modules are coming out!

>>>Stay tuned for more articles on “Programming for newbies”.

[This article has been contributed to dotTech [.org] by M.D. Stephen with minor edits from Ashraf.]

Subscribe to dotTech to never miss an article again!

Share this post

About Stephen

You probably know that Stephen means crowned with glory eh! Yes, that is all I am. I'm a Electronics and Telecommunication Engineer, as well as an ICT guy. If you want to know me more, I'm a Christian Minister too. You'll not find me posting things of faith here because you read the URL right, a tech site....I love dotTech.org what about you??

11 comments

Stefano

@J.L.:
JL,
because Python syntax requires indentation which is very hard to attain with notepad. You can use any editor that supports Python Syntax. In Linux there are gedit, kate, geany, et al
BTW I have been a little busy, God willing I might come back with more programming tips!

Samuel

@john:
You make some valid points and yes C++ is very dangerous but that’s because (sorry, the line is too good) “with great power comes great responsibility”. C++ is one of the most powerful languages most people learn. You can do many things with C++ that is either a pain or impossible to do with other common languages like Java, Python, C#, and VB. But along with that power comes the ability to really mess up a computer. So yes, it’s dangerous but like when you tame a wild dog, the results can be pretty sweet.
Also i think they mean that they are simular in syntax.

john

@Ashraf: I don’t know about that… c++ has no garbage collection and this is a major difference. Also, c++ classes do not inherent from a super class (System.Object). Finally, you do not need to even use classes in c++. c++ is also in my opinion a far more dangerous language to code in.

Bill Gates II

You gave up on VB? well I do supose that before .NET is was limited, and with out a good IDE you in a bit of a pickle. My first and favorite language is VB.NET (ver 9 waiting for 10). I admit that one reason I use .NET in that i have more MS connections than I can count (my name give any hints about that?) I did give python a go a while back. It was interesting but I had no compelling reason to learning short of passing intrest. I think I still have the installer for it some where…