Aspect-Oriented Programming: Guiding AI to Extract Cross-Cutting Logic So Logging, Auth, and Instrumentation Are Never Written Twice
In the age of AI programming, there is one kind of code that gets copied around with abandon: logger.info("Start processing request") if not token: raise UnauthorizedError() start = time.time() result = await service.do_something() logger.info(f"Execution time: {time.time() - start}") return result At first there is only one endpoint, and it looks harmless enough. But once the project grows to dozens or even hundreds of endpoints, things quickly become: User endpoints ├─ Authentication ├─ Logging ├─ Parameter validation ├─ Business logic └─ Instrumentation Agent endpoints ├─ Authentication ├─ Logging ├─ Parameter validation ├─ Business logic └─ Instrumentation Knowledge base endpoints ├─ Authentication ├─ Logging ├─ Parameter validation ├─ Business logic └─ Instrumentation ... The only truly different part is the few lines of business logic in the middle. As for the rest, every time the AI writes another endpoint, it dutifully copies it all over again. This is exactly the problem that AOP (Aspect-Oriented Programming) set out to solve. ...