Tuesday, November 3, 2015

Python Code Readability

As I mentioned before Python is a simple language with a focus on readability. This focus is expressed in its syntax:

* Lines of code end in newline (Contrast with Java, C++, Objective-C whose lines must end in semi-colon).

* Indentation is enforced in compile-time. For instance:

            This code compiles in Python:

                    if x > 0:
                       print(x)

            This code does not compile in Python:

                    if x > 0:
                    print (x)

The importance of code readability and indentation is very well explained in the Clean Code book by Robert C. Martin.

* No explicit data type specification when declaring variables:

             The following code in Java:
                     
                    int add(int x, int y) {
                         int result  = x + y;
                         return result;
                    }

                 Looks like this in Python:
                  
                    def add(x, y):
                          result = x + y
                          return result

Besides enforcing greater readability in syntax during compile-time, there are guidelines that a programmer should follow in order to write readable code in Python. Always keep in mind that most of your time as a programmer will be spent reading code. Hence, you should become very proficient in producing clean and readable code.

Sunday, November 1, 2015

Python History & Philosophy

Python is a general purpose, multi-paradigm programming language with a strong focus on readability implemented by Guido van Rossum in the late 1980's.

Python has a unique philosophy described in a rather humorous way in the document Zen of Phython. Here are a few points found in that document:

    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
In order to master a programming language a programmer must go beyond its mere syntax, but actually embrace the philosophy and paradigm(s) the language is founded on. I recommend you to read Zen of Python if you haven't done so and think about it as you program with this language.

About me...

I'm a developer passionate for programming languages. I have developed with Java, Javascript, PL/SQL, SQL, Objective-C and Python.
This blog is dedicated to the fun, simple, powerful and Python programming language.