Friday, September 29, 2006

wxPython note: about callbacks

Be careful about callbacks, for they sometimes bring unexpected logics. The process is not written explicitly in the code, and therefore may cause traps, just like aspect oriented programming. For example, I just wrote a callback from notebook page change. Then I used some manual calls to change the notebook pages. I did not notice that those manual calls also brought up callbacks, and therefore messing the logic. This problem is fixed by introducing a boolean variable bManual to indicate whether a page switch is done by pressing manually or by a function call. Whenever the notebook page is switched by function calls, it is marked with the variable.

Thinking of aspect oriented programming, sometimes a program is added with new functionalities and thus become larger all the time. Apart from using SVN to monitor the changes, it is also possible to use some special end of line comments to clarify. For example, some functionalities can be marked with # [-functionality-]. Then in further editing, we simply check the tags to find which code does the job. However, this approach should be used carefully so that all code and comments are consistent.

No comments: