Sunday, May 22, 2011

Debugging

Before going to explain debugging, I want to discuss, what a program means. As every computer student knows, a program is a sequence of instructions that specifies how to perform a computation. Computation can be mathematical or symbolic. Symbolic computation means computations like searching and replacing text in a document. Usually a program may have instructions to get input, display input, mathematical operations, conditional operations and iterative operations.

There can be chances to occur errors in the programs. Those errors are called as bugs. Tracking and solving those bugs is called as debugging. Debugging is one of the most intellectually rich, challenging, and interesting parts of programming. There is a classification regarding the type of errors.
  • Syntax errors
  • Runtime errors
  • Semantic errors
Syntax error occurs when the programmer violates the syntax of code. Syntax refers to the structure of a program and the rules about that structure. Python displays a message if a syntax error occurs.

Eg : (1+4) is correct but 1+4) is a syntax error.

Runtime errors cannot be seen until program execution starts. It usually indicates that something exceptional has happened. So it is also called as exceptions.

If a Semantic error occurs, the computer will not generate any error messages.  But the program will do something different than it is supposed to do. This error occurs due to the logical mistake of the programmer.

Debugging is also like an experimental science. Once you have an idea about what is going wrong, you modify your program and try again. If your hypothesis was correct, then you can predict the result of the modification, and you take a step closer to a working program. If your hypothesis was wrong, you have to come up with a new one. Programming is the process of gradually debugging a program until it does what you want.

Thanks

AJAY

Saturday, May 21, 2011

Python - Introduction

I have explained you about the history and deployment of Python in my previous post. Now I just started “Think Python” and here posting introduction to Python.

As other languages like C, C++, Java, Pearl and Visual Basic, Python is also a high level language. High level languages are written using easily understandable formal languages. They are easy to write and read. They can be run on different computers with no modifications, which increase its portability.

There are also low level languages which is the only language that a computer can directly execute. They are also called as machine languages or assembly languages. High level languages need to be converted into low level language before execution. This process time makes a disadvantage for high level language.

Two types of programs are used for this purpose.
  • Interpreter 
  • Compiler

Interpreter process a program a little at a time usually line by line. A compiler reads the program and translates it completely before the program starts running. Once a program is compiled, you can execute it repeatedly without further translation. Here the high level language is called as source code and translated code is called as object code.

Python programs are executed by interpreters. There are two modes to use the interpreter.
  • Interactive mode 
  • Script mode

In interactive mode, we can type Python programs and the interpreter prints the result:

>>> 2 + 4
6

Interactive mode

The >>> symbol is the prompt which is used by the interpreter to indicate that it is ready.
Alternatively, you can store code in a file and use the interpreter to execute the contents of the file, which is called a script. Python scripts have extension ‘.py’.
For testing small pieces of code interactive mode is convenient and for larger lines of codes script method is recommended.
More explanations regarding testing and debugging will be posted soon.
Thanks
AJAY

Thursday, May 19, 2011

Python - The Origin

My instructor Pramode.C.E has sent me the links of a text about the Python programming language – “Think Python by Allen B. Downey”. Before I’m going to think Python, I want to introduce this programming language to you.

Guido van Rossum
The implementation of Python was started in December 1989 by Guido van Rossum. Python 2.0 was released on 16 October 2000, with many major new features including a full garbage collector and support for Unicode. Python 3.0 (also known as Python 3000 or py3k), a major, backwards-incompatible release, was released on 3 December 2008 after a long period of testing. I’m proud to inform you that Python has twice been awarded as TIOBE Programming Language of the Year (2007, 2010), which is given to the language with the greatest growth in popularity over the course of the year (as measured by the TIOBE index).

Python is a multi-paradigm programming language. Rather than forcing programmers to adopt a particular style of programming, it permits several styles: object-oriented programming and structured programming are fully supported, and there are a number of language features which support functional programming and aspect-oriented programming (including by metaprogramming and by magic methods). Many other paradigms are supported using extensions, such as pyDBC and Contracts for Python. Python uses dynamic typing and a combination of reference counting and a cycle-detecting garbage collector for memory management. An important feature of Python is dynamic name resolution (late binding), which binds method and variable names during program execution. Python is often used as a scripting language for web applications, e.g. via mod_wsgi for the Apache web server.

Python Logo
For many operating systems, Python is a standard component. A number of Linux distributions use installers written in Python: Ubuntu uses the Ubiquity installer, while Red Hat Linux and Fedora use the Anaconda installer. YouTube and the original BitTorrent client are the popular users of Python. Large organizations that make use of Python include Google, Yahoo!, CERN, NASA, ILM, and ITA. Most of the Sugar software, which is an open source desktop environment designed with the goal of being used by children for learning as a part of  One Laptop per Child is written in Python.

Users and admirers of Python—most especially those considered knowledgeable or experienced—are often referred to as Pythonists, Pythonistas, and Pythoneers. I’m going to be a Pythonist by its true sense and you can expect posts regarding Python on the coming days.

Thanks

AJAY