Recognize and Prioritize
Programming is creative and challenging, but not every task is exciting. Sometimes tasks are boring and it's easy to put them off.
The key is to recognize the signs of drudgery. It's easy to justify avoiding tasks you don't like, especially when you have more interesting tasks to do.
Identify your own avoidances. Everyone has their own list, and what's boring for one person might be exciting for another. By knowing what you tend to avoid, you can prioritize tasks better."
A New Argument
Imagine a function findNearbyCharacters
that returns characters within a certain distance.
It's used many times throughout the codebase, and some calls are incorrect.
To fix this, you decide to add a new argument to exclude certain characters.
You have two options: update all existing calls to include the new argument or use default arguments or overloading to avoid the work. While the latter approach saves time, it also means you'll have to keep track of multiple versions of the function.
In reality, updating all calls is essential, as it allows you to examine how the function is used and fix issues where characters are excluded. This process also reveals cases where the new argument would be useful.
Later, you need to add more functionality, such as filtering out non-threatening enemies. You could add another overloaded version of the function or create a filter class that handles the new requirements. Choosing the latter approach simplifies the function and reduces the number of versions.
However, implementing filters everywhere requires significant work. You'll need to inspect and update all calls, which can be tedious. It's tempting to stick with the multiple versions, but this approach can lead to maintenance issues and confusion.
As programmers, we often prioritize short-term convenience over long-term benefits. But doing so can lead to problems later on. When faced with a difficult task, it's essential to prioritize the right solution, even if it requires more work upfront.
The Siren Call of Automation
Programmers often want to automate tasks they find tedious. You might use regular expressions or write Python code to add a new argument to a function. Alternatively, you could create a comprehensive utility app for adding arguments. Sounds like a fun project!
It's understandable to find manual editing tedious, but automated solutions can be overkill. Spend less time on manual edits and more on meaningful tasks, as per Rule 20.
Consider using regular expressions if they can solve 80% of the task. The remaining 20% can be handled manually.
Remember, tasks like these may feel repetitive, but they rarely require full automation. Judgment is often required, even for simple tasks like formatting code or updating comments.
Control File Sizes
As code evolves, it gets longer and more unwieldy. At Sucker Punch, our main character class has become a kitchen-sink class, accumulating features and code over time. But with 19,000 lines of code, it's become a problem.
The large file makes it hard to work with, as it takes too long to compile and finding specific code is a challenge. We've all briefly considered fixing it, but it would require a lot of tedious work: refactoring, rewriting, and moving code around. We've collectively decided to ignore the issue, even though we'd all be happier with a cleaner codebase.
As a disciplined team, we've faced other challenges that required effort. But this one seems too daunting. To tackle it, we need to acknowledge our reluctance, evaluate the benefits of fixing it, and then take action. It may be unpleasant in the short term, but it could pay off in the long run.
No Shortcuts
You have a big piece of wood with 100 nails sticking out. You can:
- Leave the nails alone
- Wait for someone else to fix it
- Waste time making a machine to do it
Or you can take your hammer and hammer the nails out. Sometimes, we just need to get things done.