Recently, I’ve been using GPT4 to do some refactoring. I’ve been decomposing large refactorings into smaller ones to make my changes incremental. One of the smaller refactorings that I wanted was a way of replacing the use of one construct with another within a method.
Imagine that you have a Java application and you want to replace all of its uses of Date with LocalDate, but you want to do it in small, behavior-preserving steps. It would be great to have a refactoring that does the replacement within a method without changing its signature. After refactoring, the method should be able to accept Dates as parameters but internally it should just use LocalDate. The method should convert from Date to LocalDate, use the LocalDates internally, and then convert them to Dates if they are returned or passed outside of the method.
I gave GPT4 a few examples and it was able to figure out what I wanted. I could just paste methods into the chat and and ask it to do the same thing that it did to the previous one. Eventually that felt silly so I told it that whenever I wanted it to do that refactoring I’d use the word “intralate.” It was the best name I could come up with at the moment.. sort of a mashup of the concepts of “being within” and translating.
I tend to do this sort of thing a lot now. I suppose it’s a strategy that makes sense to me after decades of programming. If I need a thing, I create it and name it. It doesn’t matter whether it is a variable, a method, or a class. The different thing that I am doing now is inventing new words rather than using and compounding words that show up in a dictionary.
We don’t often do this in programming because we have to communicate with other people, but AI gives us a chance to abandon that constraint in short sessions. I can ask what intralate means and it will tell me.
Technically, I could have named the refactoring ”hornscramble” and done the same work. Hornscramble is a definitely a worse choice than intralate but really, the word intralate isn’t much better. People would still need a definition or a few examples to know what it means. In either case, the nice thing about creating a new word is that it completely disambiguates communication. Artists know this. Search for “The Weeknd” and you only get hits for one person.
In GPT, a new word can guarantee that you’ve disambiguated completely from its training data. Your new name is only good for the session, but that could be good enough. If you want to use it in other sessions, you can turn the definition and its examples into a system prompt.
This has been a useful tactic for me when working with AI, but I have to admit that I’m really interested in something that is “off to the side” of this technique — concept discovery and naming.
GPT seems rather adept at learning from examples. Make up a name and then give it a number of examples of what you mean by it. Then give it new examples and ask it to tell you whether they fit the concept it is developing from your description.
Through interactive training, we can invent new lexicons with shades of meaning finer than we are used to. The useful ones might escape from personal use into widespread use — or not. Regardless, we can precisely identify and apply what we are incubating.
So, is intralate a good name for the what I described? Can we intralate within a class as well as a method?
Like GPT, I could use a few more concrete examples for what _intralate_ looks like.
In addition to telling ChatGPT what Intralating is, you could also train it to know what smells such a refactor can fix. Then if you ask ChatGPT to look at your code and suggest refactorings, Intralate would be included as an option along with the existing Fowler & Feathers canon. :) I can even imagine a scenario where books like Refactoring, Working Effectively with Legacy Code, or Refactoring to Patterns would come with an access code for digital content you can dump into your ChatGPT session to train it in all the book's smells and fixes.