For that, there is a saying: "code as if your kids will maintain it".
But I think it does not convey the right meaning. When I code something I will have to maintain for a long time, I try to make it as simple as possible for my future, older, less motivated and weary self.
The worst codebases are written by people who landed the gig a few months before and do not expect to stay around longer than a year or two.
Anyone other than myself would instantly observe it as the the worst codebase they have ever seen.