Finally I made it to Python!

Now, there is a great language. What I like about this language is that it maketh sources look really nice. Syntax is clean and simple, mandatory indentation is something awesome, especially to somebody who tired of C/C++ sources with no slightest sign of coding style, like this:

In Python, thou hast to indent thy code properly, because this determineth how it will work. On the other hand, braces become unneeded–less to type, all the better!

What I like not about Python is abscence of private/protected class members. It just looketh not safe! Well, it is a kind of resembleth GLib with its outstanding way of declaring private members. Knowest thou how to do it in C? If not, just take a look:

Now I guess in Python we just need to make similar “implementation” by ourselves, since language giveth us not one. And of course, proper naming conditions will help us too. But that looketh rather adhoc anyway. No ideal language in the world, eh?

Nonetheless, Python is just wonderful. Something as high-level as Perl, with syntax as clean as in Java, but as simple as PHP. Availability of Qt for it maketh it only better.

It took me half a day to learn Python. I quickly made an example using Qt in it, looking like this:

A little bit of black magic is present here. Actually, almost everything is not so black as it seemeth except for pyqtSignature thingy–this is a rather mysterious thing intended to inform PyQt what signal we want our slot to be autoconnected to, in case there are overloaded signals with the same name. Everything else is transparent: __init__ is just a Python’s standard name for constructor, exec_ looketh like this because exec seemeth to be a reserved word in Python, and “self” is just like “this” except that it has to be declared explicitly and can have any name (although “self” is an established convention).

The same example in C++ looketh like this:

That is two files (a separate .h is needed in order for moc to work), not to mention that it should be three if I implemented functions not inline (which I really should have done). Apart from that, it looketh not much more complicated, but Python code is just much more beautiful for some reason. Now I understand why programmers say that they like the way source code in Python looketh.

Leave a Reply