Hacker News new | ask | show | jobs
by aerovistae 2233 days ago
Semi-related thought~ I find myself often dreaming about the AI-assisted development processes of the future. I'll frequently be writing code and start thinking "this task I'm doing is pretty formulaic and constrained-- it should be automatable someday, even if we haven't figured out how yet."

Examples:

1. I memoized the arguments for a util function. Repeat this on the very similar functions defined alongside it.

2. I need to put a wrapper component around six similar components. Just do it for me after seeing me do it once.

3. I imported a new logging mechanism and called a specific method from it in one of my class's methods. Repeat for four similar classes.

Basically I want a "repeat after me" functionality that can intelligently infer which part of thing I just did is generic and can thus be replaced with the next item in the series. In a dream future it would also infer what the next items in the series are.

I haven't a clue how such a thing could be created though, or I would already be on it myself. It would have to understand the code not just syntactically but conceptually.

God it would make development less tedious though. The difference between today and that future is the same as the difference between today and the days of punchcards.

3 comments

When is it better to solve those problems through the organization of your code rather than an autocomplete feature?

The things you mentioned all seem to yield to the decorator pattern.

Creating the right abstraction (instead of using autocomplete) would benefit future collaborators who may not have access to the same autocomplete functionality.

The GP wanted to repeat some code modification 2-6 times. At that scale, adding abstractions often just adds unnecessary indirection and makes the code harder to read.
Depends on how often they intend to make changes to that code. But in general I think you are right.
Even if that was true, which I'm not arguing one way or the other, it wouldn't take much effort of imagination to come up with other use cases that aren't solved by decorators.

This has a taste of the old "they would have asked for a faster horse" argument.

I actually agree with you. I wasn't implying that the OP should consider refactoring their code. Just trying to understand for myself when I would prefer autocomplete over organization of code.
> I imported a new logging mechanism and called a specific method from it in one of my class's methods. Repeat for four similar classes.

How would an IDE know the local variable you've declared, that is a suitable match to the logging method's parameter?

How indeed. I think basically a rudimentary version might guess and then ask you if its mapping is right.

i.e. a modal asking:

"As done to MethodA, do to MethodB?" "As done to VariableNameA, do to VariableNameB?"

And the B values would just be dropdowns that would let you correct it. Idk.

I'm just imagining what you could do with some decent speech-to-text, NLP, and an engine that understands code conceptually on a basic level.

"Create a new enum on line 14 called SuchAndSuchCategories, with the values A, B, and C. Replace the string literal on line 27 with SuchAndSuchCategories.B."

"Move method A above method B."

"Add a new method to class X called doSomething() that accepts three parameters: a string called A, a generic called B, and a SomethingClass called C. Inside the method, start a for-loop...."

Like, idk. These aren't repeat-after-me tasks but they're complimentary to them. It would just be great to be able to just talk code into existence.

>"As done to MethodA, do to MethodB?"

Don't know about you, I would have no idea of a method name's exact spelling from a declaration multiple folders and files away.

Well, I mean you wouldn't really need to know the spelling. It would be picking the methods from the code, having parsed it. There would be no spelling involved. It's just a matter of it checking that its target is correct-- "Is this the one you wanted to change?" And if the dev doesn't know the answer to that, then they couldn't have made the change without the tool, either.
TabNine already does this "repeat after me" autocomplete really well, and Kite probably does too, you should give them a try!

These kinds of repetitive tasks are really where AI-based autocomplete shines!