PYTHON: THE EVIL WITHIN

 is the first of a series of code articles written by our new columnist Acha Bill. Enjoy.

Ask anyone around and they will tell you that Python is the easiest language around. They’ll tell you a lot of good things about the language enough to make you want to be a python developer.

They don’t tell you that reading Python code is like going to hell.

The real problem with Python is not whitespace as most people say often.

It’s the difficulty in reading other people’s code.

 

Consider the code fragment below:

***************************************

import class1, class2, class3, etc..., classN
def evaluate(arg1, arg2):
    result1 = arg1.reaction()
    result2 = arg2.negotiate(arg1)
    return result1.execute(result2)

****************************************

Where do you actually start to understand this?

 

Python’s dynamic type nature makes reading the code so hard.

In the above python code, what tells you that the definition of

arg1.reaction() is in class1 or class2 or anywhere for that matter.

How do you know what result1.execute() actually does? By checking its definition? Where?

arg1 and arg2 can take on ANY type (class1, class2, …, classN) at runtime.

You just can’t figure out how the code works without haven gone through class1, class2, …, classN.

My God!! How do people love Python?

 

Let’s look at the same thing in C#

 

*****************************************

using class1;

using class2;

using class3;

 

int evaluate(class1 arg1, class2 arg2)

{
   class3 result1 = arg1.reaction();
   class2 result2 = arg2.negotiate(arg1);
   return result1.execute(result2);
}

*****************************************

This is a lot easier to study.

-If you are confused on how arg1 performs the reaction method,

go check it out in the definition of class1. At least you know where to find help. (class1)

-A return type of int tells you explicitly that result1.execute() returns an integer.

-etc.

 

How do you study code when you there is no way for you to know what object you are looking at??

Just giving me a name does not help me. Tell me what type that name attaches itself to.

Tell me that the variable ‘x’ is a complex number.

I’ll narrow down the way I see the environment with which ‘x’ associates with.

Giving me a necked ‘x’ is like asking me to compute all permutations for every chess state.

I’m not Kasparov or THE DEEP BLUE.

 

Let me further show you that python is only helpful for the author of the program.

A simple example.

 

******************************

def foo(arg1, arg2):
   return arg1 + arg2

******************************

 

Now python guys, what does this method do?

“It adds two things”.

 

This method makes sense only to the programmer because he alone knows what he achieves by adding arg1 and arg2.

 

You thought “It adds 2 things” is a logical answer but NO!

What if the programmer had overloaded the + operator for the type of arg1 and arg2 to act as a – operator instead?

 

In c++,

*************************

int foo(int a, int b)
{
   return a + b;
}

*************************

foo clearly adds 2 integer numbers. There is no game saying about that! Even a blind man will know this.

 

************************

int foo(X a, X b)
{
   return a + b;
}

************************

Here, foo does not necessarily add 2 Xs. I know this because I can see from the code that X is a custom type.

 

Python programmers on the other hand haven zero notion of data-types at compile time, hence, their code is open for imagination and for you to find your way through the multiverse.

 

If you want to get a feel of sitting in the Abstract Algebra class in MIT,

try reading just 300 lines of Python code you are new to.

Leave a Reply