Ask HN: How do you keep your code elegant?
A little background for this request. I am a self-taught hacker and when I work on projects, I typically spend a bit of time thinking through the structure of the code, breaking it down into functional modules, figuring out a good database schema, etc. In order not to get carried away with over thinking the architecture, I usually set a time limit on how long this process can take and almost always end up with a very simple, straightforward design that gets the job done efficiently (enough) and, dare I say, elegantly.
The problem comes when the project hits the harsh light of day and I start getting feature requests from users that I never anticipated. Once I start implementing these new features, I discover the code is no longer as streamlined or straightforward, the database schema is now less than ideal and I need to rely more and more on documenting my code instead of being able to trust that the flow is self-evident.
Now, don't get me wrong. I'm pragmatic enough to realize users do not give a shit about the code and just want stuff to work but I care. I'll throw in a hideous hack if that's what it takes but I like beautiful code and even if I am the only one who knows what's going on behind the scenes, I get a small sense of satisfaction knowing just how well it all hangs together.
So, let's hear your tips on how to ensure your code stays beautiful.