By Maxwell Edwards · November 25, 2026 · 5 min read · 3 views
Fighting AI Code Slop with Objects
As more software development is ceded to Claude, the importance of modular, encapsulated code grows. Better objects mean clearer, more easily maintained code.
How AI Changes Development#
When I started programming in college, our professors would have us turn in both the source code and our plan for the program. We would manually think through our logic and write it out in a markdown file before ever starting coding.
Nowadays, I work with Claude to setup the plan, then do little to none of the actual coding implementation. The plan itself is getting closer and closer to being fully automated too.
The problem with the agents nowadays is that they'll write code that "works" but is horribly difficult to maintain. Multiple classes all declared in one long, 2000 line file. 8 functions that all do the same thing. Duplicated code across 4 different services. Similar to how AI-generated art looks like "slop", AI-generated code reads like a pig in the mud.
60% of the cost of software is the maintenance phase, long after core development has been completed. Building applications using only vibe-coded AI output increases those long-term maintenance costs. I have several applications I work on now that are so far gone, they are virtually impossible to maintain without an agent that can read the whole thing and make sense of it. That's a dangerous place to be. Programs can be "functional" without being maintainable. The more important the program is, the more effort needs to be placed on cleaning it up for maintenance's sake.
Ai has largely increased the pace of code that is output, while reducing the quality of the code design. It does improve with prompts like, "follow the DRY principles of software engineering" and "use an object whenever multiple functions need the same data", but those are not the default behavior, nor satisfactory guardrails on code-slop.
How Objects Help#
Objects became the predominant design methodology in the '90s and into our modern era. After decades of functional programming, C++ and Java came along, ushering in a new paradigm. Instead of needing to manage the state of data globally, the data could be updated within specific objects. There are 4 key principles of object oriented design.
Encapsulation#
Encapsulation is all about keeping the data within the object it is supposed to be in. By restricting value changes to specific methods, often get and set, visualizing how data changes throughout a program is simple. Only functions defined in the class are accessible to the broader program; if something is going wrong it's easy to put a debugger on to fix it.
This is a helpful idea for clarity. For example, if we have a class (an object is an instantiated class) called Car and it has a method computeCost(), it doesn't make any sense for the getDistanceToOcean() method to set the cost of the car. All of the logic for calculating the cost of the car should be within the computeCost method.
Abstraction#
Once the object is created, the program doesn't need to know how the cost is calculated, it just needs to know the returned value. This cleanly isolates the logic to one location. No other parts of the program should be changing or modifying that value.
To continue the example Car may expose a method computeCost() which returns an integer value like 20000. Within that computeCost method, it may say
def computeCost():
return applyCustomerDiscount(getAgeOfCar() + getInterestRate() * getLoanYears())All of the internal logic is kept in the object, letting the program only care about the method name and its return type. This is also beneficial if the underlying logic changes. In a functionally programmed application, a logic change may require updates in various parts of the code base. In this object-oriented paradigm, the underlying logic only needs to be changed once for the entire application to adopt it.
Inheritance#
This says that the behavior of the parent can be passed down to the children. Inheritance is helpful when defining relationships. A Vehicle class may have a method getMilesPerGallon, which is a common behavior across all vehicles. Then any class that inherits from Vehicle will support that method.
Inheritance reduces code slop by defining things once and letting the inheritance of the logic be adopted in the codebase. I have used this idea frequently in enterprise development. At AT&T we had 4 different data sources that all needed to aggregated into 1 dataset. Because all of the datasets were different, I built a common ParentTransformer class, which had a common loadData method shared. This lets it be declared once while keeping the lineage associations from parent to child.
Polymorphism#
Polymorphism is similar to inheritance, but instaed of a direct child of a class, it represents an interface that a class implements. While a Vehicle may have children, an interface would be closer to a behavior. If a Vehicle also implements the Color interface, then it supports the Color methods getDayColor and getNightColor.
Polymorphism is one of my favorite design principles because it abstracts so much away logic from the core code, letting the business logic display clearly. Working with interfaces allow for easy swaps of the implementations, as well as flexiblity as a developer. Instead of managing various objects and calling their own getDayColor methods, they can all be treated as a Color and iterate through them.
# All dayColor objects are implementations of the Color interface
dayColors = [turtle, car, house]
for i in dayColors:
print(i.getDayColor())Object-Oriented Design and Token Costs#
Token costs are important to manage, especially as AI companies begin to leverage their new, deep integration into developer workflows. Because the agents operate as prediction machines, guessing the next best token to generate, they make better estimations with better context. However, more context that explains the task also requires more tokens to read into it's working memory. This creates a dilemma for cost: more context gives better output, but will cost more per prompt. Less context gives worse output but its much cheaper, likely requiring more prompts to get a coherent result. This ends up being just as expensive.
Strong design saves money in both cases. LLMs will make better choices when a program has clearly defined classes and interfaces for using them. They don't need to load as much into context because it's immediately obvious where changes should go.
When a program does give context and the code is well designed, the LLM saves on token costs because it only needs to make the change once. Without strong design, it will end up generating the same set of code multiple times across the codebase and copy it around different files. This is code-slop and it rapidly degrades understandability.
Conclusion#
The rapid adoption of LLM use in software development has made way for a flood of unmaintainable, functional yet unclear code; this is code slop. Guiding the LLM towards stronger design builds the long-term maintainability of code. Better objects make further feature work easier and reduces overall token usage.