4 ms·
Indeed. Patterns are what you use when there is no cleaner option for the situation. Recently I've been writing some code which is surprisingly amenable to a c
by triplefox 18y ago
Indeed. Patterns are what you use when there is no cleaner option for the situation.
Recently I've been writing some code which is surprisingly amenable to a cut+paste approach: A tool which automatically generates level layouts for a game. At first I endeavored towards a data-driven approach to customizing each type of level I wanted to make, but soon I decided, "There are only six types of levels. Each one has different requirements and they get maintained in isolation. There is no point in trying to reconcile all of them at once."
And so I went ahead with a strategy of reuse for the most common elements - low-level generation strategies - and made big switch statements for the remainder. It works, I get the job done, and there's almost never anything surprising. The only time something did surprise me was when I accidentally pasted the same code twice in different places and threw the results askew in a non-obvious way. That flags some need to slim down bloated methods, but even as-is, it still feels pretty slim at ~2500 lines.