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.

Thursday, September 28, 2006

Python note: module subprocess provides functionalities to open arbitrary file

To open an email attachment in some email client, the client needs to make new processes which opens the corresponding file. This can be done by using the subprocess module, which spawns new process and opens the file.

import subprocess
subprocess.Popen(filename, shell=True)

Sunday, September 03, 2006

C++ note: about strings

length - s.length() / s.size()
index - s[1] = 'x' / s[2]
slice - s.substr(1,4) means starting from 1, length 4.
append - s.append(t)
replace - s.replace(1,3, 'x') replaces slice (1,3)
erase - s.erase(1,2) same meaning
find - s.find("abc",2) find from index 2
reverse - reverse(s.begin(), s.end()) modifies strs.

It's alright concatenating strings with +
The constructor can also be s = string(t, start, length).