Technical Posts

VisiMatik will occasionally publish here articles of scientific or technological interest. These may include software development discussions (e.g. life cycle management, configuration management, programming languages, C++, C#, python, Java, R) as well as articles relating to application areas (e.g. Life Sciences, bioinformatics, large datasets, algorithm complexity).

Generators and Code Inspection

Frequently, programming languages are seen as incarnations of programming metaphores. Java is object-oriented programming, Pascal is structured programming and LISP is functional programming. Naturally, this is most certainly not the right way to look at it. But the point I want to make is that one cannot look this way at Python or at C++. They are eclectic. Python is an imperative language equipped with all essential elements of functional language. Importantly, it permits, nay, encourages combining these two paradigms. This article discusses the concept of generators, partly as a convenient bridge between the two paradigms. The example also continues the exploration of Python as a dynamic language - this time in a very literal way. Module inspect is used to extract useful information from the source code of a running program.
[more...] [source code]

Python, Pytables and meta-classes

I like to think that programming languages are means of expression of though. Thus, it is difficult for a programmer not to develop a preference for one language or another. At the same time, since the choice will depend chiefly on what needs to be said (and I want to say a great many things), I can't really have a favorite for all seasons. But I found that the language I like most consistently is Python. It is highly expressive and well structured at the same time. It encourages elegance and clarity. It is modern. A good example of what I mean is reflection: reflection is available in several modern languages and it is served there well. But where Python stands out, in my opinion, is the natural way of representing the access to the execution model into the language itself. This article gives an example of use of reflection and Python's metaclass idiom. The presented code is a minor extension to PyTables, a package for managing hierarchical datasets from Python. PyTables itself and builds upon other well-know libraries: HDF5 and numarray. HDF5 is a library and a binary data format very well suited for organizing large volumes of numerical data and is chiefly intended for scientific applications. What PyTables lacked from my perspective, was a sufficient data definition layer. Something similar in spirit to the DDL (Data Definition Language) of SQL. I show how an appropriate mechanism can be easily devised through a proper application of reflection and the metaclasses. While the example is quite specific to the toolset I use, I believe it to be quite educational and thus applicable in other contexts.
[more...] [source code]