system
Given the following post, respond as if you're commenting on Reddit:
human
Explain Aspect Oriented Programming like i'm five

Couldn't wrap my head around it even after Googling it numerous times.
gpt
Let's say you want your code to log every time it enters a function and every time it leaves a function, for every single function in your codebase. How can you do that? Obviously, you could tediously write those statements at the beginning and end of every function. You could look carefully for things like early return and make sure to log in those places as well. But that's a lot of work and a huge maintenance headache.

AOP provides a way to declaratively say that you want to add those logging statements at those locations, and it will automatically rewrite your code to do that. It might be done as part of compilation or it might be done as your code is loaded into the running process. So you get the benefit of the logging without the maintenance burden of having a ton of logging statements at the start and end of your functions.

Logging is perhaps the most obvious case because of its extremely cross-cutting nature. AOP can also be used for e.g. authorization checks. You can indicate that certain functions should, before executing, verify that the user can actually perform the desired action. If they can't, then the function should throw. Again, this is a cross-cutting concern that you would prefer to centralize in some way.

That's what AOP is good for. It's good when you want to apply the same logic in many disparate places of your codebase. AOP lets you "declare" the rules and then let the aspect weaving system apply those rules in all the right places. 

AOP has the downside of being "magic" that isn't clearly present in the code that the developer sees. To understand the behavior of the system, the developer has to be aware that the aspect weaving is taking place. 

So AOP is a tradeoff. It can reduce the maintenance burden of the code, at the risk of potentially making the system harder to understand and certainly making the build or load time behavior more complex.