Techno Blender
Digitally Yours.

AI Code Intentions – DZone

0 108


Any modern IDE includes Code Intentions that allow you to perform some predefined actions on your code based on a context. For example, for a  for statement, there can be several intentions like Convert to while, Reverse orderUse Streams, etc. The use of Intentions is very handy as it allows us to perform quick refactoring or do some manipulation with the code. 

Intentions are pretty hard to develop, so they are usually hard-coded and bundled with the IDEs by respective IDEs vendors. In some IDEs, it is possible to develop your own Intentions, but it is not so easy as it requires good knowledge of an IDE platform, writing lots of code, developing plug-ins to deploy your Intentions, etc.

Though, hard-coded Intentions can become obsolete. Today, you can ask an LLM, e.g., ChatGPT, to perform some action on your code, and it is pretty easy. You have to provide your code snippet and a proper prompt. For example, if you supply the following loop with the Reverse direction of a loop prompt to ChatGPT:

for (int i = 1; i <= max; i++) 
    System.out.println("i = " + i);

You will get the same result as using similar hard-coded Intention provided by your IDE:

for (int i = max; i >= 1; i--) 
    System.out.println("i = " + i);

So, it is pretty natural that we should introduce AI Intentions, which are basically named AI prompts bound to some context. Context can be a file, class, statement, particular method, etc., and IDE would be responsible for supplying the correct context, asking LLM with the correct prompt, obtaining and parsing results, and committing them back to the code. 

The advantages of having AI Intentions are:

  1. Almost any refactoring can be done using plain language. The prompts can be as simple as Replace using format for well-known  APIs (like Java’s PrintStream.println(String)), or they can be more complex with more instructions for less-known APIs.
  2. No need to hardcode AI Intentions.
  3. No need to write plugins to distribute AI Intentions.
  4. AI Intentions can be easily user-configurable.
  5. No need to use a Chat interface, especially for repeating activities.
  6. Less LLM token traffic to allow saving the cost compared to the use of a Chat interface.

Another cool option is AI intentions that are baked right into the API using annotations. Such declarative AI Intentions would instruct the IDE what intentions are available per class, field, or method and which prompt should be used to perform a particular Intention by asking an LLM. Such declarative AI Intentions can be supplied by framework/libraries authors, and therefore they can be immediately available to all the developers in IDEs that support them.

For example, the following annotation would specify a Replace using format AI Intention that allows replacing println(String) calls taking a concatenated string to println(String, Object...) calls taking format and arguments list:

@AIIntention(title="Replace using format", prompt="Replace using format and arguments list")
public void println(String x) {
}

So applying such an Intention to a call:

System.out.println("i = " + i);

Would result:

System.out.printf("i = %d%n", i);

The use of declarative AI Intentions can drastically improve dealing with deprecated APIs. So some/each deprecated method can include a few AI Intentions to allow refactoring it to a modern version — no more need to skip refactoring in the future. Browse docs and manual coding – just make your code up-to-date in a single click.

I believe AI Intentions is the future of IDEs and LLMs integrations. So I hope they will appear in many IDEs in the nearest future.


Any modern IDE includes Code Intentions that allow you to perform some predefined actions on your code based on a context. For example, for a  for statement, there can be several intentions like Convert to while, Reverse orderUse Streams, etc. The use of Intentions is very handy as it allows us to perform quick refactoring or do some manipulation with the code. 

Intentions are pretty hard to develop, so they are usually hard-coded and bundled with the IDEs by respective IDEs vendors. In some IDEs, it is possible to develop your own Intentions, but it is not so easy as it requires good knowledge of an IDE platform, writing lots of code, developing plug-ins to deploy your Intentions, etc.

Though, hard-coded Intentions can become obsolete. Today, you can ask an LLM, e.g., ChatGPT, to perform some action on your code, and it is pretty easy. You have to provide your code snippet and a proper prompt. For example, if you supply the following loop with the Reverse direction of a loop prompt to ChatGPT:

for (int i = 1; i <= max; i++) 
    System.out.println("i = " + i);

You will get the same result as using similar hard-coded Intention provided by your IDE:

for (int i = max; i >= 1; i--) 
    System.out.println("i = " + i);

So, it is pretty natural that we should introduce AI Intentions, which are basically named AI prompts bound to some context. Context can be a file, class, statement, particular method, etc., and IDE would be responsible for supplying the correct context, asking LLM with the correct prompt, obtaining and parsing results, and committing them back to the code. 

The advantages of having AI Intentions are:

  1. Almost any refactoring can be done using plain language. The prompts can be as simple as Replace using format for well-known  APIs (like Java’s PrintStream.println(String)), or they can be more complex with more instructions for less-known APIs.
  2. No need to hardcode AI Intentions.
  3. No need to write plugins to distribute AI Intentions.
  4. AI Intentions can be easily user-configurable.
  5. No need to use a Chat interface, especially for repeating activities.
  6. Less LLM token traffic to allow saving the cost compared to the use of a Chat interface.

Another cool option is AI intentions that are baked right into the API using annotations. Such declarative AI Intentions would instruct the IDE what intentions are available per class, field, or method and which prompt should be used to perform a particular Intention by asking an LLM. Such declarative AI Intentions can be supplied by framework/libraries authors, and therefore they can be immediately available to all the developers in IDEs that support them.

For example, the following annotation would specify a Replace using format AI Intention that allows replacing println(String) calls taking a concatenated string to println(String, Object...) calls taking format and arguments list:

@AIIntention(title="Replace using format", prompt="Replace using format and arguments list")
public void println(String x) {
}

So applying such an Intention to a call:

System.out.println("i = " + i);

Would result:

System.out.printf("i = %d%n", i);

The use of declarative AI Intentions can drastically improve dealing with deprecated APIs. So some/each deprecated method can include a few AI Intentions to allow refactoring it to a modern version — no more need to skip refactoring in the future. Browse docs and manual coding – just make your code up-to-date in a single click.

I believe AI Intentions is the future of IDEs and LLMs integrations. So I hope they will appear in many IDEs in the nearest future.

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – [email protected]. The content will be deleted within 24 hours.

Leave a comment