Sometimes, it amazes me how elegant Python is. A class system that is almost as powerful as CLOS, yet easy to use and comprehend. It is truly one of the most powerful programming systems in the world, if you show it a bit of love.

I have developed a lot of metaclasss code when designing PISI. It has made the XML processing (which is managed by the autoxml library I wrote) and CLI code exceptionally cool. I was making some cleanup for the next PISI release, and I happened upon a not so pleasant Constants class, which now looks great thanks to metaclasses:

Well, and what did I find particularly elegant? How easy it was to write the constantsingleton metaclass, and how I tested it, almost poetic.

Mind you, python 2.x is still problematic with metaclasses, I think you should be using python 3.x if you want to use them. I just had to deal with a meaningless error that vanished without any reason in 2.7.13, so please use these classes at your own risk! And do not forget to link to the PISI github and mind the license, which is GPL-3.0 for these files. I have written these useful tests for that annoying stability problem, though, so please do not forget to first test it in your unit test environment first.

Happy hacking!

Appreciation of Python’s Elegance: Metaclasses and Design Patterns

examachine

Eray Özkural has obtained his PhD in computer engineering from Bilkent University, Ankara. He has a deep and long-running interest in human-level AI. His name appears in the acknowledgements of Marvin Minsky's The Emotion Machine. He has collaborated briefly with the founder of algorithmic information theory Ray Solomonoff, and in response to a challenge he posed, invented Heuristic Algorithmic Memory, which is a long-term memory design for general-purpose machine learning. Some other researchers have been inspired by HAM and call the approach "Bayesian Program Learning". He has designed a next-generation general-purpose machine learning architecture. He is the recipient of 2015 Kurzweil Best AGI Idea Award for his theoretical contributions to universal induction. He has previously invented an FPGA virtualization scheme for Global Supercomputing, Inc. which was internationally patented. He has also proposed a cryptocurrency called Cypher, and an energy based currency which can drive green energy proliferation. You may find his blog at http://log.examachine.net and some of his free software projects at https://github.com/examachine/.

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »