Monday, 30 April 2007

Developing on Windows - Replacing the basic tools.

As anyone who has to work with Windows as their development environment knows, the tools Windows comes with are crap. Notepad, Windows Explorer and the Command prompt to name a few. Tools such as these are vital to programming productivity, and are simply substandard in all current versions of Windows. As far as it goes, Explorer is fine for the average Windows user, but is awkward if you need to keep track of different folders, and transfer files between them. In addition, there is no easy way of customising Explorer without hacking the registry. Notepad isn't fit even for the average user - particularly since it is the default text editor. It can't handle anything other than ASCII, and won't even automatically convert between different line endings. The Command prompt is pretty inexcusable. A tool only used by programmers and sys admins, you would have thought that the console program in Windows might have been a little more developed by now, but seems stuck in the dark ages, and years behind the unix console.

Luckily there are some free, or at least very cheap alternatives for all of the above tools.

Xplorer2 - Explorer on steroids.

An Explorer replacement that I've been using for years, and remains one of the few development tools I've paid money for (there being no free or open source equivalent with the same sort of power) is [Xplorer2] []. This tool is superb - featuring tabs, dual pane, scrap folders, user defined commands, user defined toolbars, a very powerful search facility etc etc.

The tabs are great - you can keep a tab open for each of your most visited folders. And they are nested within dual panes if you wish, so you can keep different sets of tabs open for each pane.

Dual panes not only make moving files about much quicker and easier than the traditional Explorer tree view, but they have a Mirror browsing mode for comparing trees of folders with different roots. For example, you have trunk and a branch checked out from your source repository. If you have trunk open in the left view, and the branch in the right, with Mirror browsing switched on, moving through the source tree in one pane will be mirrored in the other. With the built in folder sync tool, you can check for differences between the folders based on a flexible selection of parameters (date, content etc)

Scrap panes can be used to collect together files from various folders into a virtual folder. For example the 'Browse Flat' menu item puts all files in a folder subtree into one virtual folder. These files can be operated on as if this were an actual folder, compared via a dual pane view. Useful for many purposes, including keeping sets of disparate but related files together, as extended bookmarks etc.

User defined functions can be used to great effect. One of my favorites is integrating WinMerge into Xplorer2, by defining a pair of commands, the first of which calls WinMerge on the currently open directories in left and right panes; the second calls WinMerge on the currently selected left and right files. So, using mirror browse on my trunk and branch, I select the file in trunk I want to compare (the branch file if automatically selected correspondingly), hit CTRL-1 and WinMerge opens comparing those two files.

Not free, but well worth the $30 fee for the professional version (especially in the UK with the pound as strong as it is at the moment!). There's also a lite version for home and academic use.

GVim, Cream

Actually, just about any open source editor is better than Notepad. For programming though, certain things are indispensable: syntax highlighting; correct handling of line endings; smart indentation handling etc. I prefer [GVim] [] these days - several years editing stuff on unix servers has taught me the power of vim (through a painful and long induction...). Not an editor for novices, it requires a lot of practice and a different way of thinking than your usual text editor, but is very powerful, especially since it can be programmed with my language de jour, Python.

For the more faint of heart, [Cream] [] is GVim, but configured for ease of use. By default it works like a normal text editor, but has all of the power of vim working in the background and available for use in advanced mode.

Apart from the features already described, I use the following Vim features (in no particular order) on a regular basis:

1) Auto-complete 2) Marks - mark lines with a letter, and jump between these. 3) Macros - record macros to perform repetitive tasks. 4) Block select - one of my favorites, this lets you for example insert the same text in the middle of a block of 7 lines. I use this frequently for tasks such as editing repetitive code and property file editing. 5) Python scripting - for example sort the lines in the file into alphabetical order: :py lines = vim.current.buffer[:]; lines.sort(); vim.current.buffer[:] = lines 6) Spelling checker 7) Global command - match lines using a combination of a line range and pattern, and then do stuff to those lines. :2,6g/^#/dd deletes all lines between 2 and 6 that start with a # 8) Folding - hide blocks of code from view. Useful to get a higher level view of source code.

There are other editors than Vim with features like these, Emacs and JEdit come to mind, but for me Vim is the winner since it is small, powerful and ubiquitous on unix/linux based machines where I spend quite a bit of time.

Console and Cygwin - a better Command shell.

I've just discovered the delights of [Console] []. It's a tabbed console for windows which allows you to pre-define tab definitions to open up specific configurations. For example, I have tabs set up for bash, Python, Jython, Beanshell etc. Very nice, and in addition circumvents the problems the standard Windows command interface has with selection and the fact that starting a selection pauses the process currently running (I find this incredibly irritating - though I know others find it a feature. You can get the same behaviour in Console, or in Windows command console using the pause key on the keyboard.) In addition, for those into such frivolities, there are lots of special effect to make your tabs transparent, have wallpaper etc.

It brings to windows some of the convenience of programs such as Konsole on Linux, and in combination with [Cygwin] [][1], you can even use the bash shell and gnu tools with all of their power. Actually things may have improved with the introduction of [PowerShell] [], but I haven't had the time to experiment with it yet.

1 comment:

Steve said...

Without wishing to detract from the force of your argument (I too am a Cygwin user), you should note that the "Save" dialog in Notepad offers you a choice of ANSI, Unicode, Unicode big-endian or UTF-8 from the Encoding drop-down, so I am afraid it's just a little bit less dire than you make out.