Tuesday, June 29, 2010

C++ and text editing

Recently I saw a post from Linus Torvalds defending the usage of C, as opposed to C++, for the Linux kernel.

Some of his points reminded me of some of my original adversity to C++.. in short, the tendency to be context dependent, which makes browsing and refactoring difficult with a plain text editor.

One of my complaints was that with simple text editors it's hard to find usage of methods.
For example to find and possibly replace Window::Paint() while avoiding Button::Paint().

Using C in an OOP-ish way with a naming convention such as WND_Paint() and BUT_Paint() makes it possible to find (and possibly replace) all usages of that specific method.

I understand that stuff like an OS kernel is probably better left to C, because of the need to be working at a relatively lower level (compared to applications that handle more abstract concepts).
But, at the same time, I think that if the Linux developers weren't stuck with Emacs and VI, they'd probably see things in a different light (disclamier: while I'm no Unix person, I use Vim as my main editor and ViEmu in Visual Studio).

A closer relationship between a text editor and the underlying code project is what makes C++ bearable to me.

In Emacs and VI one has ctags and cscope simplify code navigation.. but they are still mostly meant for C.
The plain "grep" that Linus mentions, is even more limited in that sense... it reminds me of when I'd refactor code using a combination of "Find and Replace in Files" in Visual Studio, or messing a method definition to have the compiler tell me (with an error) where that method was used.. 8)

Nowadays even the plain Visual Studio is more context aware of the more popular multi-purpose text editors. And things are improving constantly in the world of IDEs and refactoring plugins/tools.

When I looked around for refactoring tools for Emacs and Vim, I could only find Xrefactory for Emacs. It costs a whole $400 (-$1) for one license, and it's clearly a less refined and less popular product than Visual Assist X, for example.
..so much for the Open Source world 8P

Linux kernel aside, I'm afraid that developing C++ with the standard Unix-like tools is still not as efficient as on Windows.
And I feel that to be really productive I'm forced to keep in Visual Studio at the center of my development, even when I'm developing for other platforms..

I can see some programmers really wanting to keep things simple as far as the tools go: "A good-old flexible text editor is all one should need".
But I'm afraid that things have been evolving from that, and for more context sensitive languages such as C++, it's only natural that the development environment adapts and evolves into something more than text manipulation.

ole'