Archive for July, 2009

A programmer’s time

Saturday, July 18th, 2009

A programmer’s time in front of a computer is to a large extent spent manipulating text. While mundane compared to the actual knowledge of implementing systems, it’s the basic trade craft of programming. So we care about text editors. A lot. There’s been feuds among programmers which editor is the best since the beginning of time (that is, 1950’s, or so).

The difference, in my mind, between a good programmer’s editor and a great one is thousands of small little tweaks. In a great editor, you can quickly and easily automate repetitive tasks and there are commands for handling hundreds of things that may not be commands that you do every time – but once you learn enough of them you’ll end up saving a lot of time. This is a lot of the reason why editors like emacs and vim which have been around for decades are still used and loved: They’ve been around long enough so that people have written all these clever shortcuts which makes a programmer’s job easier. Replicating these decades of tweaks is not an easy task.

I discovered Qt Creator a few weeks ago. It definitely holds a lot of promise, especially considering its age – it’s only been out and public for a few months; though obviously the Trolltech people have been working on it internally for longer than that. As an IDE, it’s absolutely fantastic. It has some of the feel of the Java or C# IDE’s that everybody else has been getting jealous over for the last decade. As an editor however, there’s work to be done.

One fairly common task in C++ is that you have a header file, like the one below, and you want to rename the class Foo to something else.

#ifndef FOO_H
#define FOO_H
class Foo {
    void foo();
#endif // FOO_H

Say we want to rename everything from foo to bar. Easily done, just replace foo with bar globally. This is what we’ll get in most editors:

#ifndef bar_H
#define bar_H
class bar {
    void bar();
#endif // bar_H

You’ll see that the editor did exactly what we requested. Replaced foo with bar. Now, unfortunately, that means that some poor schmuch (that is, me) will have to go back and fix the capitalization, because all good programmers care about consistency and code style and not to mention that bar and Bar are two different things in almost all programming languages.

If you do the replace command in emacs however, by default it’ll preserve the case of the replaced text:

#ifndef BAR_H
#define BAR_H
class Bar {
    void bar();
#endif // BAR_H

It saves me maybe 30 seconds of typing each time, but over time it adds up. More importantly, I don’t feel like the editor is interrupting me. I can continue with what I wanted to accomplish, without breaking my flow with trivial details such as the case of a few words.

So, what does this have to do with Qt Creator that I mentioned earlier? I took a look at the source code of it, and found it rather pleasant to fix and hack around in.

So I created a patch which implements this case preserving replace in Qt Creator. There are hundreds of other small tweaks that would make the editor in Creator go from a good to a great editor, hopefully I can continue helping by implementing at least a few more.