Generating Code

There is an excellent article on code generation at Frans Bouma’s blog

One potential disadvantage he mentions is that the generated code is not up to par with the functionality requirements you have.

I have a similar concern. That is, they can get big, complicated and become the centre of attention. This can detract from the application being built. At the end of the day, we are building a system or application for a client. It is those requirements and that application which should have our primary focus.

Finally, for me the ultimate code generator is a powerful scripting language such as Perl, Python or Ruby. Using these, you can build and maintain custom code generators quickly.

Code Completion

Code completion comes in a number of flavours. One way is syntax expansion. Another way is recognizing code symbols (such as procedure and variable names). A third is to match strings in the current file.

Syntax expansion is like providing a template and you fill in the blanks. For example, while coding Perl, if you type if, the editor will recognize if as a keyword and then expand it to if (){ } to suit your favourite brace style.

The second way is by understanding the program code. By recognizing the procedure names as you key them in, the editor can supply parameter information and prompt for parameter values. This is a real boon. But, the real kicker is when it starts recognizing procedure names from other project files or even standard code libraries.

The third category of code completion, works with arbitrary strings. Instead of retyping long strings, you type the first few characters and then get the editor to look for a matching string. Sort of like an incremental search. Except that you have the option of using the string that is found.

For example in Visual Slickedit, as you key in some text, you hit ctrl-shift-< and the editor will search backwards in the file to find the first matching text. If this is not the text you are looking for, hit ctrl-shift-< again to find the next match. Once you have found the right piece of text, you can either hit enter to use it or you can pick up more of the surrounding text by pressing ctrl-spacebar.

All three of these techniques are provided by Visual Slickedit and VIM.

Jump to Definition (and back)

Another feature that I can’t live without in an editor is “Go to Definition”. Basically, if you are examining a variable or procedure and you want to get to the definition, just press a hotkey and the editor will position you at the definition. If the definition is in another file, the editor will open and load the file and position you at the right place. You can get back to the place you came from by pressing another hotkey.

This feature is reasonably common and is found in Visual Slickedit, VIM, the Visual Basic Application editors (Excel, Word and Access) and even the Visual Studio .Net IDE (although this took some digging to find). Again, I haven’t found a way of doing this in BBEdit.

Selective Display (aka folding)

I am a simple guy. I can’t keep reams of detail in my head at one time. I like to see an overview of what is happening and when I need the detail, I want to get to the relevant bit quickly. When finished dealing with the detail, I want to return to the overview.

And I want to do this fast!

Any editor that supports this is a real saviour. Of the editors I currently use, Visual SlickEdit provides Selective Display and VIM provides Folding. Unfortunately I have not discovered this feature in the doyen of Mac editors BBEdit

I use it in a couple of ways. The first is to see the structure of the code i.e. what can be called and what calls it. The second is to place the cursor on word, hit a hotkey and have all occurrences of the word displayed. Hit another hotkey and the entire file is displayed again.

So what you say. A grep or find all occurrences does this already. But the difference is that selective display shows the results in the same window. From a coder’s perspective, it looks as though all lines that don’t contain the word have been hidden and the ones that do remain visible. You can now use normal cursor navigation to get to the line you want. Once there you can edit or even make changes.

To try out selective display in Visual Slickedit, look at the View Menu and bring up the selective display dialog. To learn about folding in VIM take a look at the VIM online documentation.

Starting Again

Finally got around to setting up a blog using movabletype on a Linux hosting service.

Decided on movabletype because it is relatively open, it is done in Perl (with which I am familiar) and it also sits on top of a database. The real clincher was the user interface and the way that it handles mulitple weblogs and authors.

For the hosting services, I settled on mtvhosting to do the hosting as they offer great facilities at a reasonable price.