–EDIT–
I believe this is a valid question that may have multiple answers (as defined here). This is NOT a discussion nor a poll. Furthermore, this question is evidently NOT argumentative as none of the respondents so far seem to argue with each other.
–ORIGINAL TEXT–
Amazing! I do software for about 15 years now and I still have no idea what I’m doing 🙂
Seriously, I still struggle with the basics:
- overengineering vs. YAGNI
- cutting corners in order to meet the deadline vs. pushing back on the business
- risky innovations vs. tedious good old stuff
- enjoying the freedom of working alone vs. the power of the team
But the worst of all is code complexity. My code tends to get evil. It even bites myself after a few weeks. I put tremendous effort in keeping it simple, readable, maintainable, elegant, beautiful, cohesive, loosely coupled, based on nice straightforward abstractions. But all this effort goes down the drain!
Don’t get me wrong, my code is pretty good by most people’s standards. I mean it’s flexible, more or less unit-testable, and does what it needs to do. However, it is far from simple.
Every change requires substantial refactoring. If another person opened my code with the intent of adding a feature he would HAVE to do something stupid. There’s no way he’d be able to do it RIGHT, even if he was a GENIUS, even if he was my own CLONE unfamiliar with the codebase. Why, why for God’s sake does this happen? Isn’t there some methodology, some technology, some meditation technique, anything at all?!
How to keep my code simple?
I feel your pain, buddy. The struggle for simplicity in complex systems is the struggle of software engineering. If you’ve nailed it, you’re probably not working on hard enough engineering problems. And hard doesn’t always mean complex, it may be “implement x by tomorrow to keep the sky from falling.”
Towards simplicity … TDD mentioned thoroughly, agree totally. TDD is a trick to keep code focussed on what it needs to do and no more. Re-factor frequently mentioned. Totally agree.
On simplicity vs complexity and working alone … don’t work alone on shipping code. Get code reviews every check in, and encourage code reviewers to rake you over the coals. That will keep you on track to make the right compromises and balances. Talk to someone about your code at least once a day. Rotate reviewers. My work is more lucid and just better with a teammate. Don’t care how green they are. Actually, the greener the better to ensure clear code.
On working alone … Working alone has its place in R&D, not shipped code. At best, lone cowboy projects make cool stuff that is terrible pain to maintain. Work done alone always needs a month or or two to re implement and re-factor into code maintainable by mortals and fix a few huge oversights. It’s really really painful if that month or two hits you after you shipped the cowboy code.
Edit: On the detail side, I’ve found various books on Domain Drive Design extremely helpful in providing ways to create super clear code. DDD not applicable to every problem though.
If you do find the answer to the balance between simplicity and over-engineering … well, I wouldn’t even know what to do then. I suppose I’d get bored and find another line of work.