Get startedGet started for free

Analyzing production code with AI

1. Analyzing production code with AI

Hi there!... I'm glad you're here.

2. Beyond code generation

Together, we're going to explore how experienced developers write, reason about, and evolve production code, moving beyond simple code generation toward deep analysis and better engineering decisions.

3. Course overview

During this course, you will learn to develop AI-based code analysis skills to understand and optimize production code, apply AI-assisted testing and security practices, and use AI assistance for software design and collaboration.

4. The scenario: Wayfarer Labs

Now, let's begin by setting the stage for a regular working day as software developers. Imagine you are a software developer at Wayfarer Labs, a tourism startup. You are responsible for finding an open-source analytics tool to integrate into a tourism-mobility platform.

5. Discovering Atlas

After extensive search, you come across Atlas, an analytics toolbox for city mobility operators that appears to be a strong functional fit for your use case. Before adopting it, however, you need to determine whether the code base is maintainable, reliable, and a solid long-term addition to your stack. Otherwise, you risk spending significant time on debugging and rework. In this scenario, AI can help accelerate and systematize the evaluation of this new code base!

6. Understanding a new repository

Let's start with a challenge: understanding a repository we've never seen before. Instead of reading files at random, we can ask the AI to help us orient ourselves on how to get started with the codebase.

7. Structured prompting for codebase orientation

We can do this with a well-structured prompt that provides task context, a clear goal, and the expected output. For example, explaining the high-level purpose of the project, the main modules, entry points, execution flow, and so on.

8. Structured prompting for codebase orientation

Let's examine the AI response to this first prompt... Here, we have asked the AI to do what an experienced engineer does when seeing a repository for the first time: read, infer, and reason without running anything yet.

9. Structured prompting for codebase orientation

One main takeaway from the AI response is the command needed to execute the codebase on sample data for a specific period of time.

10. AI-guided static analysis

We can also use AI to guide us in running a proper static analysis of the codebase. Here is a sample prompt.

11. AI-guided static analysis

With this second prompt, the AI recommends which tools to use for our purpose. The AI also guides us on how to interpret the results from each tool.

12. AI-guided dynamic analysis

In a similar way, AI can guide us in profiling the application at runtime and tracing the data flow, that is, performing dynamic analysis.

13. Assessing code quality with AI

Now that we're familiar with the code structure, let's move on to code quality. By prompting the AI about maintainability, complexity, and technical debt, we can better assess whether Atlas is a solid long-term addition to our stack. With maintainability prompts, the AI can flag issues such as overloaded modules and blurred responsibilities.

14. Complexity and technical debt

For complexity assessment, we can identify areas with long functions, nested conditionals, and branching. Overly complex codebases should raise adoption concerns. Finally, technical debt prompts can help us spot TODOs, duplicated logic, legacy patterns, and more.

15. Evaluation conclusion

After the AI-guided assessment, we can conclude that Atlas is well-structured and reasonable to adopt, once a few issues are addressed. We should tackle technical debt early to keep the codebase healthy over time.

16. AI-assisted refactoring

Up to now, we have used AI to reason about certain aspects of the codebase. However, AI models can also assist with refactoring code by highlighting high-impact changes and proposing patches.

17. Important reminder

Before we wrap up, one final reminder: AI is not a replacement for engineering judgment. It can make mistakes, miss context, and sometimes hallucinate. But when used correctly, it can accelerate understanding, surface risks earlier, and help us make better coding decisions.

18. Let's practice!

Now, let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.