First Aid Kit

 < Day Day Up > 



There are very few tools for preventing Premature Optimization. The primary tool in this case is your own skill and experience. . Establishing the proper thought processes to handle developing code without Premature Optimization is the most important prevention technique. The other important tools are the proper high-level programming languages. With language features closer to the problem domain, there is less temptation to spend time optimizing low-level implementation details.

The effects of Premature Optimization, however, can be cured by several tools that assist the programmer. For example, when encountering prematurely optimized code while development is still in progress, you might need to refactor the code to improve readability and maintainability over optimization. Smalltalk’s refactoring browser and the refactoring tools provided with IntelliJ’s IDEA assist in this effort, automating the more tedious parts of refactoring.

In addition, when it does come time to optimize, there might be poor optimizations introduced by premature optimization. Whether or not poor optimizations have been introduced, the most important tool for the job of optimizing is the profiler. Profilers range from snippets of hand-written code to full software packages such as Intel’s VTune Performance Analyzer. It is often necessary to avail yourself of several different profilers to reach the final performance goals of the application.

Both refactoring and optimization are assisted by two very important tools. The first tool type is testing tools. There are several freely available testing frameworks for different languages, such as JUnit for Java, CppUnit for C++, and PyUnit for Python. As with refactoring tools, these remove many of the tedious details from performing testing. Removing the boring aspects of testing is very important psychologically in encouraging testing, hence it is important to spend a little extra time learning to integrate these tools into your development and build processes.

The second type of tool is source control, such as CVS, PerForce, or Microsoft’s Visual SourceSafe. The primary differences between the many versions of source control available are cost, features, and ease of use. Table 1.3 shows a comparison of three version control products as an example, but be aware that others are available. Determining which to use must be done on a project basis, based on budget, needs, and the skill level of those using the source control. Do not underestimate the importance of ease of use, however, because it can affect development time. Ensure that all developers who must use the source control chosen can use it efficiently.

Table 1.3: Comparison of Three Version Control Software Systems
 

Perforce

Visual SourceSafe

CVS

License

Per user, volume discounts

Various

Open source

Interface

Command line/GUI

Command line/GUI

Command line*

Learning curve

Moderate

Short

Steep

Ease of use

Easy

Easy

Moderate

Flexibility

High

Low

Very high

* Separate GUI front-ends are available from other developers, most of them open source as well.

While many programmers have been told the importance of source control for the purposes of preventing the loss of code, less emphasis has been placed on its use during the process of refactoring and optimization. Particularly in the case of optimizations, and sometimes when refactoring, changes made do not have the desired effect. By using source control properly, the code state before the change was attempted can be stored and thus be available to revert to when a change does not work as desired. Figure 1.14 shows the workflow that takes advantage of this use of source control. This is an important part of the optimization cycle and can be extremely useful while refactoring as well.

click to expand
Figure 1.14: Workflow that takes advantage of source control for reverting failed changes.

To place these tools in context, here are the steps in a single optimization cycle and their associated tools:

  1. Profile (profiler)

  2. Modify (editor)

  3. Profile (profiler)

  4. Test (test framework)

  5. Keep or revert (source control)

Each of these steps is important, and therefore the tools that are associated with them are a necessary part of the development process.



 < Day Day Up > 



Preventative Programming Techniques. Avoid and Correct Common Mistakes
Preventative Programming Techniques: Avoid and Correct Common Mistakes (Charles River Media Programming)
ISBN: 1584502576
EAN: 2147483647
Year: 2002
Pages: 121
Authors: Brian Hawkins

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