34.4. Program into Your Language, Not in It

 < Free Open Study > 

Don't limit your programming thinking only to the concepts that are supported automatically by your language. The best programmers think of what they want to do, and then they assess how to accomplish their objectives with the programming tools at their disposal.

Should you use a class member routine that's inconsistent with the class's abstraction just because it's more convenient than using one that provides more consistency? You should write code in a way that preserves the abstraction represented by the class's interface as much as possible. You don't need to use global data or gotos just because your language supports them. You can choose not to use those hazardous programming capabilities and instead use programming conventions to make up for weaknesses of the language. Programming using the most obvious path amounts to programming in a language rather than programming into a language; it's the programmer's equivalent of "If Freddie jumped off a bridge, would you jump off a bridge, too?" Think about your technical goals, and then decide how best to accomplish those goals by programming into your language.

Your language doesn't support assertions? Write your own assert() routine. It might not function exactly the same as a built-in assert(), but you can still realize most of assert()'s benefits by writing your own routine. Your language doesn't support enumerated types or named constants? That's fine; you can define your own enumerations and named constants with a disciplined use of global variables supported by clear naming conventions.

In extreme cases, especially in new-technology environments, your tools might be so primitive that you're forced to change your desired programming approach significantly. In such cases, you might have to balance your desire to program into the language with the accidental difficulties that are created when the language makes your desired approach too cumbersome. But in such cases, you'll benefit even more from programming conventions that help you steer clear of those environments' most hazardous features. In more typical cases, the gap between what you want to do and what your tools will readily support will require you to make only relatively minor concessions to your environment.

 < Free Open Study > 


Code Complete
Code Complete: A Practical Handbook of Software Construction, Second Edition
ISBN: 0735619670
EAN: 2147483647
Year: 2003
Pages: 334

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net