Wednesday, June 12, 2013

Python Programming Tutorial #1

Hello! So, since I have successfully finished my course in Python, and I have learned lots of useful stuff in that language, I've decided that I'll make some tutorials. So, here we go.

Alright, for starters, I think it's better to analyze some basic stuff. Those of you who are reading this and are more familiar with the basic stuff, just skip this. For the rest of you though...

Firstly, what is programming? Programming, according to Wikipedia, is "the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages (such as C++, C#, Java, Python, Smalltalk, etc.). The purpose of programming is to create a set of instructions that computers use to perform specific operations or to exhibit desired behaviors. The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic." A simpler way to put it is to say that programming is the way to give instructions to the computer to do things. We program computers using algorithms. An algorithm is a list of instructions the computer must follow (much like a shopping list, or a recipe). Now, to code or program (it's the same thing), we need four things:

1. A source code editor. The "source code" of a program is the code itself. This is to be seen by any people working on the project; that means that the source code is invisible to the users. A source code editor allows you to write code, and usually has some useful features, like key-coloring some important words, etc. You can basically code with Notepad, that comes with Windows, and just save your file with the proper extension (for example, a file with an extension ".c" would be a source code file written in C), but there are many free good source code editors, with a variety of useful features. An example of a multi-language source code editor is Notepad++

2. A compiler. So, you've written your code, and you're ready to see if it works. Unfortunately, that's beyond a source code editor's capabilities. In order to execute our code (aka run it), we need a program called a compiler. Basically, what this program does is that it "translates" the source code, that is words that we can understand, to binary, code that the computer can understand (of course, the translation procedure is much more complicated, and I won't go into more detail about that, as it will just disorient, discourage and confuse you). I don't think that there are any compilers who do just that; instead I think that there are many programs which include a source code editor, a compiler and debuggers (which we will talk about later) all together.

3. An interface designer (optional). From a certain point of view, we can see that there are programs which do not offer any visual feedback to the user. They are, instead, more practical. For example, let's say that you write a program that fixes an annoying bug in Firefox. Chances are, this program will just execute, kill the bug, and stop, all that in the console. There's no need for such a small program to have an interface. But if you are building a big program (or one of considerable "size"), you probably want this. Many programs/languages, like Visual Basic or Xcode make this easier, by including this to the pack of programs, as I said before (source code editor, compiler, debuggers). Other programs/languages include that in other parts that you need to import, like Python (these are modules, they will be explained later). Either way, an interface designer is essential in order to make your programs more attractive to the user.

4. Debuggers. These are programs that have to do with testing your code; they are pretty much like doctors. Most debuggers just check your code for errors. This is useful, because if you do not debug your program, and you have an error, it will just close without telling you why. Instead, when using a debugger, you can see where the error is, and why is there an error, which is very helpful. Other debuggers feature things like measuring how much CPU-power-expensive is your program, how long does the code run for and things like that. These things aren't, in most cases, necessary.

When talking about debuggers before, I mentioned errors. You must know that in programming, there are two types of errors: Syntax errors, and logical errors. As a proper language, every programming language has its own syntax and grammar. A syntax error is when you mistype something. For example, in the english language, a syntax error would be "I liek apples", or even "like I apples much very". A logical error, though, is when your code runs ok, your syntax and grammar are correct, but the outcome is not what you expected or what you wanted. Syntax errors are more serious, since you can't even run your code if you have them, but as you begin coding you will see this: Syntax errors may be serious, but they are solvable (by searching in Google, forums of the programming language you are using etc). Logical errors are very, very nerve-wracking, because you can't be sure they can be solved. And even if you do solve them, in most cases you will spend from hours to even months to do so.

But let's get back on track. In this first lesson I won't be talking about any actual Python code, I'm just going to tell you how to download and install it. It can be downloaded from here, and it is available for all platforms (I think). If you need any specific instructions on how to download and install Python, just search the website or Google for answers, although it's pretty easy to do it yourself. Also, watch out for this: If you go ahead and download the latest version, you may need to watch out for some things. Since Python 3.0, there have been some changes in the syntax of the language. I am using Python 2.7.4, because it is compatible with most modules (I'll explain what these are on future lessons), but you can download any version you want, and if you get errors, you can always Google them, or even ask any questions here. So, do that: Download a version of Python, and stay tuned for the upcoming tutorials!

No comments:

Post a Comment