Sheerpower Logo
C.3  Code Insights

Understanding SheerPower's Option Insights Feature

SheerPower’s option insights causes sheerpower to collect detailed metrics during compilation to generate a comprehensive Code Insights report. This feature analyzes code complexity and structure, making it an invaluable tool for writing code that is easier to develop, test, and maintain.

Enabling Option Insights

To enable Insights, simply add this to the top of your program:

option insights

SheerPower tracks various metrics during compilation and automatically generates a detailed Insights report at the end of the process.

Note: To use insights, you must install SheerPower. Insights are generated when option insights is enabled and you validate or deploy your program.

Generated Report

The insights report provides the following key details:

  1. Lines of code, number of routines, and variables.
  2. Complexity level per routine.
  3. List of most complex routines.
  4. List of unused variables -- they were given values but never used.
  5. Literal counts.
  6. Suggestions for optimization.
  7. and more.

The report is generated in HTML format and can be viewed in any browser.

Interpreting the Scores

The report assigns a Complexity Level score to each routine:

(Show/Hide Understanding Complexity Level)
  1. 0-10: Simple (Good)
  2. 11-20: Moderate (Review for improvement)
  3. 21+: Critical (Refactoring needed)

The report assigns a Lines of Code (Adjusted) status to each routine:

  1. 1-30: Simple (Good)
  2. 31-90: Moderate (Review for improvement)
  3. 91+: Critical (Refactoring needed)

The report assigns a Literals Usage status to each routine:

  1. 1-15: Minimal (Good)
  2. 16-30: Moderate (Consider refactoring)
  3. 31+: Excessive (Refactoring needed)

Example Insights Report

Below is a sample output from the Option Insights report.

-------------------------------- SheerPower Insights Report Program: example.spsrc -------------------------------- Total Lines: 1024 Routines: 38 Variables: 217 Max Complexity: 31 (Routine: process_data) Routine Complexity Summary: - process_data() [31] **Critical** - compute_stats() [22] **Moderate** - log_event() [8] **Good** Top 3 Literal Usages: - "Error: Invalid ID" (23 occurrences) - "Success" (15 occurrences) - "Data Updated" (9 occurrences) Optimization Suggestions: - Reduce nested loops in process_data() - Extract constants for common literals

Best Practices

To make the most of Option Insights, consider the following best practices:

  1. Regularly check complexity scores during code development.
  2. Refactor high-complexity routines to improve maintainability.
  3. Use named constants for frequently repeated literals.
  4. Minimize deep nesting in logic-heavy functions.
  5. Review the report periodically to ensure code quality.

Conclusion

SheerPower's option insights provides a valuable way to assess and optimize code complexity. By reviewing the generated report and applying best practices, developers can maintain clean, efficient, and scalable SheerPower applications.

Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.