Codebreaker 2bc08752a0894eb2c7afb345286e391d

11Jun/100

Coding, Programming, and Software Development

This is entirely my personal opinion, but I don't think it's not much different from the formal definition, if there is any.

  • Coding = an action of writing code
  • Programming = coding + problem solving
  • Software development = programming + re-usable and maintainable software design + final product quality assurance + schedule and budget management (+ a bunch of meetings)

So if you call me a coder, that's an insult. Under-evaluation of my abilities and skills.

Filed under: development No Comments
30Apr/100

Running wxPython on Mac OS X

If you try to run a wxPython application on a 64-bit Mac, you will get a similar message as following.

ImportError: /usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core_.so: no appropriate 64-bit architecture (see "man python" for running in 32-bit mode)

The reason is that wxPython currently relies on Carbon, and thus 64-bit APIs are not available. As far as I know, there are two workarounds.

If you want a temporary solution, you can run the following command in Terminal. Then you will be able to run a Python script in a 32-bit mode.

export VERSIONER_PYTHON_PREFER_32_BIT=yes

If you want to make Python to run in a 32-bit mode all time, you can run the following command.

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
1Mar/100

Python Ternary Operator

I've been using a tuple as a substitution of a ternary operator in Python. Even though it is not exactly a ternary operator and has some drawbacks, but it works fine in most cases.

w = (u, v)[x < y]

When x < y is true, the whole expression of the tuple, (u, v)[x < y], will be evaluated as v because true means 1 here. Likewise, false will cause the tuple expression to be evaluated as u.

I had another trick to use with lambda functions.

lambda w: x < y and v or u

This might be a little less obvious to see what's going on. When x < y is false, the following part, and v, will not be evaluated due to short-circuit evaluation, and it will jump to the next part, or u. Thus, this whole expression is to be evaluated as u. Similarly, when x < y is true, and v part has to be evaluated so it the whole expression will be evaluated as v.

However, as acute readers might already noticed, this trick has a major drawback. When v is a falsy value such as 0, False or None, the whole expression will be evaluated as u regardless of the result of x < y. So, one should refrain from using this trick unless it is impossible for v to be a falsy value.

Last Saturday, Cody told me that there is a ternary operator equivalent in Python.

w = v if x < y else u

Strictly speaking, it is not a ternary operator, rather an expression. But, in my opinion, it is more intuitive thus it makes it easier to maintain the code.

Tagged as: No Comments