![]() |
|
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.
To enable Insights, simply add this to the top of your program:
SheerPower tracks various metrics during compilation and automatically generates a detailed Insights report at the end of the process.
The insights report provides the following key details:
The report is generated in HTML format and can be viewed in any browser.
The report assigns a Complexity Level score to each routine:
(Show/Hide Understanding Complexity Level)
Complexity Level (CL) is a way to measure how complicated
a routine (or function) is. It counts the number of decision points
in the code—such as if
and else
statements.
The more decisions your code makes, the more complex it becomes. A higher complexity score usually means the code is harder to read, test, and maintain.
Every routine starts with a complexity of 0. Then:
if
and else
, etc. adds to the score.Example:
This routine has CL = 2 (+1 for the if
statement).
If a routine’s Complexity Level is high (21+ or more), the code is getting difficult to read, test, and maintain.
local routines
Move parts of the logic into separate local routines. Each routine should focus on one task only.
Instead of many nested if
statements, use
early exits (guard
statements). This makes the code
flatter and easier to follow.
case
Instead of Multiple if
StatementsBefore:
After (Simplified with case
):
The CL is now lower! The code is easier to follow.
If logic isn’t needed, remove it! If an if
statement always leads to return
, rewrite it
more cleanly.
if
,
else
, etc.).select case
, and keeping logic simple.The report assigns a Lines of Code (Adjusted) status to each routine:
The report assigns a Literals Usage status to each routine:
Below is a sample output from the Option Insights report.
To make the most of Option Insights
, consider the
following best practices:
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. |