syque.com

The Psychology of Quality and More

| Menu | Books | Share | Search | Settings |

C Style: Standards and Guidelines (contents)

CHAPTER 3 : General Principles

PART 1 : BASICS

CHAPTER 3 : General Principles

3.1 Keywords

3.2 Think of the reader

3.3 Keep it simple

3.4 Be explicit

3.5 Be consistent

3.6 Minimize scope

3.7 There's no one true style

3.8 A standard which isn't used, isn't a standard

3.9 Distinguish between standards and guidelines

3.10 Standards don't guarantee good coding

3.11 Decide on your portability quotient

3.12 Standards are a function of their audience

3.13 Keep project standards

3.14 Use standard libraries

3.15 Utilize available tools

3.16 Summary

<--Prev page | Next page -->

 

3.6 Minimize scope

Scoping 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.

 

<--Prev page | Next page -->

 

 

Site Menu

| Home | Top | Settings |

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

More Kindle books:

And the big
paperback book


Look inside

 

Please help and share:

 

| Home | Top | Menu |

© Changing Works 2002-2015
Massive Content -- Maximum Speed