Ayao "Alqualos" Kuroyuki (ayao) wrote,
Ayao "Alqualos" Kuroyuki


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:
for(int i=0;i<10;i++) {do_something();
  if(somecondition) {do_something_else();do_some_another_thing();}}
  now_do_some_more_work();//note that double '}}' on the previous line
  //it meaneth that we are out of "for" loop already
  //what the hell with this indentation???

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:
struct MyClass {
  /* these fields are private! */
  int x, y;
  /* ... */

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:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Vasiok module!

import sys
from PyQt4 import QtCore, QtGui
from ui_vasia import Ui_Vasia

class Vasia(QtGui.QWidget, Ui_Vasia):

  def __init__(self):

  def on_pbVasia_clicked(self):

a = QtGui.QApplication(sys.argv)
w = Vasia()

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:
#ifndef VASIA_H
#define VASIA_H


#include "ui_vasia.h"

class Vasia: public QWidget, private Ui::Vasia {
  private slots:
  void on_pbVasia_clicked()

#include "vasia.h"

int main(int argc, char **argv)
  QApplication a(argc, argv);
  Vasia w;
  return a.exec();

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.
Tags: devel, it
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded