Navigation: Page 1 | Page 2 | Page 3 | Page 4 | Page 5

July 16, 2003

vxworks, Python, and Extreme Programming

One of the greatest assets of the vxWorks realtime operating system is its shell. The shell contains a dynamic linker which allows you to load new object files as the system is running. Once the new object file is loaded, symbols (which are handles to C or C++ functions) can be accessed and called. The caveat to this is that any existing symbols within the system is overloaded with the new code in the object file. This feature enables the engineer to quickly prototype and test code without having to go through the entire sequence of:


compile -- link -- download to target -- flashing (if required) -- restarting target


involved in embedded development. Having spent so many years in the trenches, I must (embarrisingly) admit that most of the time is in waiting for this sequence to complete. This feature of the shell allows the engineer to test out algorithms or hardware features without spending so much time in the repetitive phase of embedded development.

The Python shell provides the same facility to an even much more refined extent in that you can type code directly into the shell. You don't realize how many times you just want to test out several lines of code without having to go through the compile-link-execute process. I have heard other programmers attest to the usefulness of the shell in bringing up their programs speedily.

These are but two examples of what you want to do when you practice Extreme Programming. Unknowingly, these two tools provide facilities that allow engineers to practice Extreme Programming. And the main tenet in that is to get to the desired result as quickly as possible. If there is a mistake or bug, you also need to know that quickly too.

June 06, 2003

The Dynamic Nature of Python

Python is truly dynamic in the sense that its own executing code is subject to modification even at runtime. This opens up tremendous possibilities of what you can do with the language. Here is a code snippet that I have written which demonstrates the adding of new class methods during runtime.


class DynObj:
    def init(self):
        self.methods = ("a", "b", "c")
        for method in self.methods:
           self. __generateMethod(method)
    def __generateMethod(self, methodName):
        code = "def %s(self):\n\tprint '%s'\n" % (methodName, methodName)
        exec code in globals(), self.__dict__
   
if name == "main":
    x = DynObj()
    print dir(x)
    x.a(x)

Here, the class DynObj generates 3 additional methods (**a(self)**, b(self), and c(self) ) upon instantiation. The private function __generateMethod() makes this possible. For more methods, you can just increase the size of the self.method list. Within the main program, dir(x) will show you that the new methods have been inserted into the DynObj class. There is a peculiarity in that calling on the method that has been inserted during runtime requires that you insert the object instance as the parameter.

Posted by Hoang at 01:22 PM | 2 Comments | Python Programming

March 18, 2003

Useful sites that are Unusable

As a developer using the Python language, I find the ASPN Python Cookbook to be a valuable resource for information about a variety of things that you can do.  The site mainly contain text recipes about how to perform certain tasks using Python.  It is decently designed so that getting around isn't too much of a problem.  Unfortunately, using the site IS very much a struggle.  It is so slow and when using it, I can barely tolerate just a few clicks.  Such a pattern of "difficult to use" sites are becoming common.  Another example is Zope.org , which ranks right up there in terms of containing useful information.


I wonder what could be the culprit for the sites being slow?  Is it because the application servers being used are too resource intensive that it takes longer to respond to a page request?  Is it because the servers being run are too under-powered because the owners cannot afford a better server?  Whatever the reason, it is a shame because there are enough users that patronize these two sites that make it worth while to give them a better option.  Has anyone thought about mirroring these sites?  This is a useful (relatively low-tech) pattern that is increasingly being used on the internet.  It is one of the many ways which edge networks can be implemented in a low-cost manner.

March 14, 2003

More class browsing

As Kevin mentioned in the comment for "Class Browser" article, CTAGS would be nice. However, the last I came across CTAGS was 10 years ago when I was still using VI. Call me lazy but I have grown used to the full featured scrolling mouse text editor with syntax highlighting and a little code-completion. There is just enough memory of VI for me to do simple editing when I log into my Linux Host. Well, the more I talk about it, the more I do appreciate the completeness of Visual Studio.

Continuing in the same thought process, I have just completed reading Patrick O'Brien's article on introspection. Really interesting stuff and really impossible (or at the very least, extremely difficult) to do in C++. This is the type of information required to start building a class-browser. Hum.... Additionally, there is the pyclbr module which provides the basic mechanisms for implementing your own class-browser.

What was that saying? Necessity is the mother of invention.....?

March 13, 2003

Python class browsers

After getting some pointers from folks in the comp.lang.python newsgroup, I decided to do some investigation on the various editor/developer tools for Python programming.  The original request and replies are here.  I concentrate on the suggested tools first and will only mention the class browsing aspect.



  • IDLE - this is the tkinter based tool that comes with Python.  You can browse the python path for the classes that you are interested in.  Upon drilling into a specific method, a new instance is created allowing you to edit the source code of that class.  This is very nice and the tool is lightweight enough to be very quick.  However, the editor does not have code-folding.  Additionally, you can quickly end up with many windows on your desktop.

  • ERIC3 - I never got this to run because it was based on PyQT.  I downloaded it, it required me to install QT.  I got QT and it was an evaluation and I don't know how long it will last.  It is questionable to me whether QT has enough of a following for me to try out a tool that is 2 dependencies away.  In short, I gave up trying to get it to run.

  • pyCrust - This tool allows me to inspect modules/classes loaded at realtime in the shell.  As you import more modules, it is automatically added to the Ingredients pane and ready to be inspected.  However, pyCrust is an exploratory tool and does not launch an editor upon choosing a method or attribute to drill into.

  • pythonwin - this is Mark Hammond's integrated editor and shell.  The editor is a notepad with code-folding.  It has a COM browser, file browser, and a realtime object browser like pyCrust.  There are lots of details revealled in the introspection, but it doesn't jump to your code upon drilling down.

  • Boa - this class browser maps out wxPython's class hierarchies but doesn't map to code.

  • Komodo - promises that it will be in a future release.  When will it be and what will be in it?  only the shadow knows.

There are at least twice as many more tools that allow for editing and various other levels of introspection.  However, my original question remains and the pattern of doing development goes unanswered in Python.  Sniff++ was the first tool that allows me to use that pattern to read/understand/write large bodies of code.  Visual Studio provided the mechanism to make MFC's large class library understandable.  They make large projects manageable.  The way each of these tools did it was that they abstracted out the File concept.  It didn't matter what File, the attribute or method was in, the tool would take me to it.  


The pattern works very well.... now if only I can find a Python tool that implements it.

Posted by Hoang at 03:34 PM | 4 Comments | Python Programming

Software tools

These are some good tools I have recently come across:



I have been looking for a Python Class Browser for some time but have not come across a decent one.  Despite all the bashing of Microsoft technologies, it must be admitted that Visual Studio is the premier tool of choice for developers.  I find myself entirely dependent and hooked on its integration of a class browser when doing development with MFC.  Why is a class browser such a powerful tool?  Well, it allows the developer to abstract his thinking beyond the line-by-line code.  In an object oriented world, we will assume the lower dependencies work.  Just like we assume a nail and hammer works when we are trying to put together a cabinet or something even bigger (a house).



So once it is understood that our dependencies work, we just put it aside and concentrate on the problem we are concerned with.  The class browser allows us to collapse the class and work with those classes which we are concerned with.  Additionally, the class list display is not constrained by only displaying classes within one file.  It displays the entire class hierarchy of a particular project.  I know, some of you may say "what's the big deal about manually openning up a different file".  Not much, actually.  But it is an impediment in the thought process.  If you do it enough time, all those little impediments add up to be a big stumbling block of creating your solution.


If anyone has been using such a tool for Python, please drop me a tip.

Navigation: Page 1 | Page 2 | Page 3 | Page 4 | Page 5