Is it one or the other? You can do both, right? Open source is great; as is building for the future. That is no reason you can't write something fun during a hackathon once in a while.
In my 20 years of professional coding, I've seen a lot more problems with people promoting code to shared status, attempting to build a foundation, before it's been used and before it's even remotely ready than I've ever seen with people throwing away good code. We're taught in CS school to always abstract and generalize, way too many people run with that and write code that abstracts away their specific problems, and build foundations that aren't sitting on the bedrock of solving a real problem. Almost all open source projects that start with the aim to build foundations are thrown away.
On the flip-side, one of the common goals of a hackathon is to build the best and most useful idea you can, quick and dirty, without getting mired in foundation building. The utility of that is to prove the idea is useful first, and if that succeeds for someone, what better starting place is there for building a foundation?