The Psychology of Quality and More |
CHAPTER 3 : General Principles
3.6 Minimize scopeScoping rules have a significant bearing on considerations for layout of items within (and without) a file. A general rule to apply is try to minimize unnecessary scope. Thus if there is no reason for an item to be referenced in some place, then it should not be possible to reference it there, as this increases the chance of misunderstanding or accidental error. Of course, this limit can never be completely reached, but with careful thought it can be approached. Care must also be taken not to take it too far, as there is a (debatable) point below which restricting scope causes an unacceptable level of fragmentation. For example, if a variable is used only within a code block, should it be defined at the start of that block, or (as is more commonly done) at the start of the function? There is also the notion of visual scope (as opposed to the more normal logical scope), where an item is placed close to its usage so it can be easily found by the reader. Note that in larger programs, the potential scope of any given item is much wider; consequently its scope must be controlled more carefully. This general rule can be applied to a number of situations, from data definition to function parameters to decisions on what items should be in what file. Individual items are discussed in the appropriate chapters. The four principles, of simplicity, explicitness, consistency and scope, form cornerstones for building coding standards. For an acronym to remember them by, take the first letter of each principle: SECS.
|
Site Menu |
Quality: | Quality Toolbook | Tools of the Trade | Improvement Encyclopedia | Quality Articles | Being Creative | Being Persuasive | |
And: | C Style (Book) | Stories | Articles | Bookstore | My Photos | About | Contact | |
Settings: | Computer layout | Mobile layout | Small font | Medium font | Large font | Translate | |
You can buy books here |
And the big |