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'

6 comments:

  1. What do you think of XCode?

    ReplyDelete
  2. Hi Scott (that Scott ? 8)

    I don't have enough experience with XCode to judge it as a whole.
    Nowadays I mostly use it on a MacBook just to compile and to make minor fixes to the code.

    I never tried the whole GUI-Cocoa side of things, which is probably one place where XCode shines as an IDE.

    I like the ability to Shift+Cmd+D to jump to search for a file and CTRL+double-click to jump to functions.
    I also like the text predictor better than Intellisense and Visual Assist on PC.

    However the debugger kind of turned me off when it couldn't deal with STL containers natively and I personally couldn't find a way to see pointers as arrays.
    I also had some troubles with the compiler (GCC) where it just wouldn't make the symbols for some "static const int" methods (maybe some GCC issue that will go away with LLVM)

    About refactoring.. I think that XCode has some form of refactoring, but it seemed to me like it was only for Objective-C .m files.. so I quickly gave up.

    I also miss being able to move between editor files with CTRL+Tab like I do in VS.
    And, XCode has the tendency to open lots of editor windows, even with the "all in one" setup in some cases.

    More recently, I kind of do most of my editing in Vim, so I could certainly use a Vim mode/plug-in for XCode ..especially on the laptop where some of the motion keys need to be FNed.

    mumble mumble

    ReplyDelete
  3. Hi Davide,

    Good guess! :)
    I haven't used Vim, but I do love Visual Studio.
    Using XCode has been interesting, and I'm definitely in agreement with you.

    BTW, how's your game coming along?

    ReplyDelete
  4. I guess you don't have too much choice over there ;)
    ..but you are probably in the best place to learn to use XCode at its fullest.

    The game is coming along well.. I think I'm about 90% done both with "art" and code.
    I'll send you a preview that can be ran on PC 8)

    wooo

    ReplyDelete
  5. i wonder how people could be proud of their "made with Notepad" label or the like. the development environment is the most important thing, sometime even over the programming language itself. it's lovable to write code with latest VSTO 2010, you feel as it's breathing behind your hands, and it's a pleasure to debug with it: in effect, you tend to leave bugs around to have the opportunity to come back to it. now open one of the hundreds forks of Eclipse. wait. wait. move the cursor: almost nothing happens apart of the cursor has moved. close it.

    ReplyDelete
  6. I guess that the "made with Notepad" thing gives a good feeling in the sense that one feels that he's relying only on basic tools, without the need to bother large dedicate pieces of software.

    Although Notepad still has to run on a rather complex OS on complex hardware and the code needs to be compiled with some compiler.. which is no small peanuts !

    I know people that have nice work environments set up with Emacs or Vim.
    Those editors are more powerful than it may seem. From within Vim one can call up a "make" and Vim will interpret the errors and come up with a panel very much like for Visual Studio.
    Then there are some very powerful scripts that will add IDE-like features, such as having a panel with the project files, etc.

    But when it comes to debugging, then it's really hard to beat VS.
    In fact, the "Emacs" types often will reply "all I need is a printf() !".
    I know people like that.. some of which are great programmers that I truly respect and from which I've learned things... but at the same time, I feel like they are just being stubborn.

    What they really mean is: if it's not GPL/Emacs then it's uncool and I don't want it.
    The of course not everyone is developing under Windows, and on other platforms the debugger might be not as user friendly, or may not exist at all.

    It takes time to adapt, and one has to make compromises.. but simply disregarding VS as a bloated nuisance, is short sighted and it shows stubbornness and unwillingness to adapt and evolve.

    moooo

    ReplyDelete