Friday, December 19, 2008

FilePick

A couple days ago one wise guy said me that software cannot be perfect, so it is never too early to share it. That's a good point, really.

I decided to start sharing my stuff I wrote for myself and by myself even though I'm not quite satisfied with its quality or the style or whatever else.

The first piece is a standalone File Open dialog. It's not quite my idea--I saw something similar on somebody's Mac. I can't even describe how much time this little thing saves me on such a routine operation as opening a file in the text editor. Definitely more than I spent writing it.

I'm a Komodo IDE user and I'm pretty happy with it, except the File Open dialog, which sucks. So I wrote a macro adding FilePick to Komodo IDE. I could do the same for Vim if I used it more or even (God forbid!) to Eclipse, but only if I was forced to use it.

The program is actually a tiny Python/Tkinter script. It has no dependencies except Python, of course.

It looks like this:


Initially it show the whole list of files in the directory specified by the command line parameter. Then you type in few letters and it makes the list shorter. Then you select the file, click Enter and that's it. It rarely takes more than 10 letters to locate a file in the project I'm working on (about 5000 files).

Grab FilePick here:
http://www.bitbucket.org/mikeivanov/filepick/src/

P.S. Bitbucket is just GREAT!

Wednesday, December 17, 2008

Just get rid of threads

I just couldn't resist the urge citing this:
...
Python could be better off doing what tcl does. Allow each process to embed multiple interpreters; run each interpreter in its own thread. Implement a fast message-passing system between the interpreters (e.g. copy-on-write by making communicated objects immutable), and Python would be closer to Erlang than Java.


I thus think the main offender is the thread and threading modules - not the GIL. Without thread support in the interpreter, there would be no threads. Without threads, there would be no need for a GIL. Both sources of evil can be removed by just removing thread support from the Python interpreter. In addition, it would make Python faster at executing linear code. Just copy the concurrency model of Erlang instead of Java and get rid of those nasty threads. In the meanwhile, I'll continue to experiment with multiprocessing.
...

http://mail.python.org/pipermail/python-dev/2008-December/084265.html

I can't agree more.

Why Tk matters

Tk probably is one of the most underlooked GUI toolkits. It is a nice small toolkit which is really, I mean REALLY simple to use.

Tk by the way, has something common with Vi. Oh no, it's not that it beeps all the time as possessed; I meant it works everywhere. I bet you can find Tk ported to any single platform having a GUI and it will work consistently on all of them.

Tk is ubiquitous. Guess what? Almost certainly you have Tk already installed on your computer. Got Python? Go look into /usr/lib/python2.5/lib-tk, it's right there!

How to use it? It's very easy. Look, here is a 'Hello, world' program in Python (using a Tk binding called Tkinter):
from Tkinter import *
Label(text='Hi there').pack()
The program apparently pops up a window with some text inside. Yes, it's that trivial. And this is the area where Tk shines: quick, small GUI tools.

Yet Tk is very powerful. People create big sophisticated systems using just this toolkit. The most prominent example is definitely AC3D, a 3D modeling program.

Tk, however, has some issues. I think nobody will argue that Tk looks ugly on the Linux platform. While the Windows and Mac versions have native look, the Linux port looks shokingly disgusting. Some work is being done in this department but it's not quite completed.

Somebody might ask why use Tk if there is wxPython. Well, for the same reason why there are bicycles and airplanes. They are good for different purposes. Tk is way more lightweight and much easier to learn and use than wxPython.

Tk is very well documented. Here is the official Tkinter documentation with links to tutorials and such:
If you're going to learn Tk, it's worth to mention that Tk is actually a part of something called Tcl/Tk. Tcl stands for Tool Command Language, a Shell-like scripting language easy to learn and fun to use. Even though all you want might be just Tkinter, some knowledge of Tcl will be rewarding.

Tuesday, December 16, 2008

How to minimize the street garbage?

The ultimate answer is here: http://semorfe.com/jw/.

This is a really simple game I wrote just to prove the browser platform is good enough for action games. It won't run Crysis though, but for simple 2d toys it's just perfect.

From the technical point of view it is a 100% pure DHTML, no Flash, no Canvas. It works in IE6/7. I used Prototype library because it really makes JavaScript a little bit more pleasant language.

Well, that's about it.

Enjoy the game.