cyborgzombieninjapirate


The eternal battle between code blocks vs. whitespace indents.

Posted on 08.06.2011 03:58 pm

A warning, this post is a personal opinion on programming languages, so you most likely have a different opinion.

I don't like Python.

I've tried to figure out why over the course of a few years and I think I know why. It is a strange reason but it is a personal reason, there are logical points to it though.

At first I thought it was the interpreted nature of the language, but no, there are interpreted languages that I like (PHP, Scheme, Ruby) so most likely that is not the culprit.

Then I thought it was the duck typing or typing in general, but again no. I have a different issue with duck typing that was not bothering me (which I will leave for a later post)

What could it be? Then when working on a "hack week" project with a few friends it slowly dawned upon me.

It feels like I'm working with an unreadable house of cards, and it has to do with whitespace indentation.

I'm partially dyslexic. I have a hard time reading a big block of text and while programming I separate my code into blocks that I can read. I'm particularly anal about code readability, and not necessarily readability in the sense of what each line does but separation of code that does different tasks.

So because of that I love code blocks. I find this 100x more readable than the python version.

int sum(int num)
{
    int total = 0;

    for(int i = 0; i < num; i++)
    {
        total = total + i;
    }

    return total;
}

def sum(num):

    total = 0

    for i in xrange(0, num):
        total = total + i

    return total;

I don't feel that there is a complete whole, that the function is just falling apart and has no logical structure.

In the block version, can I be sure where the function ends? Yes. Can I be sure what is within the for loop? Yes. Can there be any ambiguity in what is within the loop? No. As long as there are blocks around the code, I can very quickly determine what is within what.

And that is something I find deeply satisfying. I can look at my code and within seconds I know what is where and within what.

Since we use code blocks, the editor can reformat the whole document with a single click and there are no parts left ambiguous. If a file loses indentation due to some mistake, then fixing that is not a problem, but can be a problem in Python.

Of course with improper programming, the same issues creep up in block languages. But even with my anal retentive formatting, python never became more readable.

Python focuses on readability, but I think in the wrong way. It makes itself look like text, and there are deep problems with looking like normal text that a programming language does not need attached to it.

Perhaps we should not talk about this as a readability issue, perhaps this is a code division problem, and language designers need to consider those problems as well.

I might be wrong on some points but as stated above, the issue is something I find wrong on a personal level and I know for those who started using Python are perhaps the other way around.

1 3    Like it or hate it?  -  Comment (1)


Sticky

0 0  / Posted on 20.09.2011 12:52 pm

Ariltecs like this are an example of quick, helpful answers.

(Used for gravatar only, never displayed)

What is 6 + 4


Memory allocated for your request: 655.02 Kb
Process time: 0.0049670000000001 seconds