I’m still working on my project to restructure the application where the original programmer cut and pasted thousands of lines of code. So far, my fellow programmer, Steve, and I have eliminated over 100,000 lines of code. In the process, we’ve improved performance and added functionality.
So, what are the important things mentioned in the title of this post?
1. Write decent code in the first place. How?
- Make good base classes to hold common functionality.
- Constantly design and refactor code to keep it flexible, reusable, modifiable, and understandable.
- Comment your code! It’s usually obvious when a comment is out of date or inaccurate, but the value of an accurate comment, especially for confusing or complicated code is immense.
- If you think you need to copy a fragment of code, think about putting it in its own method, base class, or separate class.
- No, you won’t think of everything. We all write code that we later regret, but the closer you get to good, the easier it will be to get to excellent later.
2. Think ahead. That doesn’t mean that you should build in tons of functionality you don’t need now or may never need. It means being conscious of what could come in the future. Using reasonable data hiding to keep internal functionality flexible is a great way to start. If you expose all of your data directly to other code, you have more places to change it if you find performance bottlenecks.
3. Stay creative. Even when you’re working from a specification or set of requirements, you often have some flexibility in your coding. Some amount of flexibility is usually included in the functionality. If you work on consumer software, there’s usually a lot more flexibility. It can’t hurt to bring it to someone’s attention or sometimes, to just go ahead an implement it.
4. Think globally. It’s not just your code and your little part of the world. Your personal value increases when you pick your head up out of your code and look at the application as a whole. As long as you don’t step on everyone else’s toes, you’ll make the whole team look good.