Chapter 9. Augmenting, Refactoring, and Updating with AI
Code does not stay static for long in today’s environments. Given the number of desired enhancements, security expectations, dependency updates, and overall complexity, it is inevitable that any codebase still being maintained will need some combination of updates, refactoring, and augmentation. There can also be cases where a section of code needs to be reimplemented with a different algorithm. And sometimes, entire repositories may need to be migrated into a different language due to any of various causes, such as efficiency, resource use, maintainability, etc.
In this chapter, we’ll explore how SDAs can help with these kinds of tasks. Let’s start with looking at basic refactoring assistance.
Understanding what you’re updating
Before making any kind of changes to a codebase, it’s critical to understand the code. As discussed in the previous chapter, SDAs include functionality to explain code. There are multiple ways to drill into the functionality through prompting to get the level of understanding you need using the AI. See Chapter 8 for more details.
Refactoring with AI
Refactoring generally refers to restructuring code without changing the end product’s external behavior. Even very short or simple code can benefit from refactoring. Consider this code written in Python to generate a password of a certain length:
import secrets import string def gp(): lg = int(input("Enter password length: ")) ab = string.ascii_letters ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access