Next big thing

I have something of a prediction. If not a prediction then a wish. A wish for a feature that should become part of IDEs everywhere, in much the same way that IntelliSense-esque tools and refactoring tools have.

To explain the feature, first let me explain the problem it solves. Supposing I have a number of similar lines of code:

Item1.Text = GetData("Item1")
Item2.Text = GetData("Item2")
Item3.Text = GetData("Item3")
Item4.Text = GetData("Item4")
Item5.Text = GetData("Item5")

… and I want to make a similar change to each of these lines, such as:

Item1.Value = Convert(GetData("Item1"), String)
Item2.Value = Convert(GetData("Item2"), String)
Item3.Value = Convert(GetData("Item3"), String)
Item4.Value = Convert(GetData("Item4"), String)
Item5.Value = Convert(GetData("Item5"), String)

Currently, I can use tools such as Find and Replace to replace e.g. “.Text = GetData(” with “.Value = Convert(GetData(“, but replacing “)” with “), String)” is a bit more tricky. For that I would probably copy and paste “, String)” onto the end of each line. Either way, this is a very repetitive task. And if there’s one thing that we know, it’s that computers are excellent at automating repetitive tasks. I would love a tool that, after I’ve changed a couple lines, spots the repetition and intelligently asks if I want to apply the same modification to subsequent similar lines – ideally with a preview to check accuracy.

Another example. Supposing I have a list of blank <select> options that I’ve quickly copied and pasted ready for population:

<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>

… and I fill the lines in like so:

<option value="Item1">Item1</option>
<option value="Item2">Item2</option>
<option value="Item3">Item3</option>
<option value="Item4">Item4</option>
<option value="Item5">Item5</option>

Again, I would fill in the first couple of lines, but this one would work a bit differently. The tool would realise that the value and text of each item is the same, and automatically fill out one based on what I type in the other. I.e. I’d type “Item3″ into the value field of the third option, and it would automatically put “Item3″ as the inner HTML. Taking it a step further, in this particular example, it could also pick up the sequential numbering of items, and suggest to fill out the remaining items automatically. A step further again, and you could get it to work with e.g. form elements or project datasource columns, to automatically produce entire forms and classes based on a bit of initial prompting – i.e. write out some code that mentions the first and second columns of a given datasource, and it suggests lines of code similar to the lines entered, but with the other column names.

Of course this tool is completely hypothetical – at least as far as I’m aware… But in theory would not be too drastically hard to create, and would save developers everywhere a lot of time; I’m allowed to dream, aren’t I? If it became a reality, it would be a huge feature – the next big thing perhaps?

2 Responses to “Next big thing”

  1. Simon says:

    In the first instance, you might benefit from the multi-cursor select tools in editors like Sublime Text and TextMate. They let you expand your cursor to multiple sites, and then whatever you type in will be applied to all of them at once.

    In the second, have a look at http://code.google.com/p/zen-coding/ – and stop copy-pasting lines altogether ;D!

  2. Tom says:

    Yeah I use e, which admittedly makes some of these things easier (particularly now with command mode, which emulates some of vi’s functionality for powerful text selection and so on)… But I still think being able to spot a pattern and predict what I’m trying to do next would not only be immensely useful, but also not particularly difficult. Computers are great at spotting patterns. For example, (as far as I’m aware), there’s currently no easy way to create some lines of code, with a numbered item on each line, apart from typing “1 DOWN 2 DOWN 3 DOWN 4 DOWN” etc.

    Incidentally, e v2.0 includes zen – I’ve had a play and it certainly is quite nice! :)

Leave a Reply