h1

About python indentation

April 20, 2008

One of my friends asked me yesterday about why python does not use brackets or keywords for the syntax. I didn’t know the answer. I just told him that it was to keep simple the language, but that I would search about it. As many times Google gave me an answer. This is a great article and here are a few quotes:

A logic reason for use indentation instead of brakes or keywords.

Python does not allow to obfuscate the structure of a program by using bogus indentations

Tabs or Spaces?

It can be a good idea to avoid tabs altogether, because the semantics of tabs are not very well-defined in the computer world, and they can be displayed completely differently on different types of systems and editors.

This is a difference between Java and python; and just for finish my post, I’d like to share one problem that I had a few time ago. I started reading some Java code from someone who left the place where I was working and I found something like this:

if(x==3)
  x++;
  {
  System.out.println(x);
  }

The first time I read the code, I din’t get why always the x variable was being print. That is why I now I use checkstyle libraries for my java IDEs. Anyway, I really like programming in python and it’s nice to have more reasons for using the right indentation.

2 comments

  1. Try this:

    http://www.secnetix.de/~olli/Python/block_indentation.hawk

    - Paddy.


  2. @paddy3118 Thanks. You’re right that is the link that I put on my post “As many times Google gave me an answer.” The word answer has the link. Maybe I should have been more explicit! I’m starting to read your blog!



Leave a Comment