In today’s fast-paced development environment, keeping code optimized and up-to-date can be challenging. This is where Codee steps in, by performing an automated static analysis of your code to identify improvement opportunities by following the recommendations of the Open Catalog of Code Guidelines for Correctness, Modernization, and Optimization. The static analysis capabilities of Codee allow it to analyze every line of Fortran, C, and C++ code to identify opportunities without requiring code execution. As a result, Codee allows you to quickly and efficiently capture potential improvements such as code compliance with modern standards, and performance enhancements.
Tailored Reports for Managers and Developers
Once Codee analyzes your code, it generates detailed reports customized for different roles within your team. For managers, Codee provides high-level insights, allowing them to assess the project’s alignment with strategic objectives. Developers, on the other hand, receive specific, actionable feedback on code improvements.
Codee doesn’t just identify opportunities; in certain cases, it can automatically rewrite parts of your code. For example, Codee can disable the error-prone implicit data typing of Fortran, by inserting in programs the implicit none statement and missing variable declarations, helping improve code clarity and maintainability.
The reports are available in different output formats, ensuring seamless integration with your existing CI/CD pipeline. This means you can automatically test every code change, continuously improving code quality throughout development.
A key aspect of Codee is that it runs entirely on your local system, ensuring complete privacy. Your source code never leaves your disk, making Codee a secure solution for analyzing and optimizing proprietary or sensitive codebases.

Codee’s Suggested Workflow: Five Simple Commands
To make the most of Codee’s capabilities, we’ve standardized a workflow consisting of five core commands. These commands capture all improvement opportunities and present them in different formats, following a top-down approach. The workflow starts with management-oriented reports and progressively moves toward detailed technical analysis. This ensures that high-level strategic goals are aligned with the technical actions taken by the developers.
1. Technical Debt Report
To run any Codee command, you first need a working compiler invocation. For instance, let’s consider a simple matrix multiplication code compiled with gfortran.
$ cat -n matmul.f90
1 subroutine matmul(n, A, B, C)
2 double precision, dimension(n, n), intent(in) :: A, B
3 double precision, dimension(n, n), intent(out) :: C
4
5 ! Initialization
6 do i = 1, n
7 do j = 1, n
8 C(i, j) = 0.0
9 end do
10 end do
11
12 ! Accumulation
13 do i = 1, n
14 do j = 1, n
15 do k = 1, n
16 C(i, j) = C(i, j) + A(i, k) * B(k, j)
17 end do
18 end do
19 end do
20 end subroutine matmul
$ gfortran matmul.f90
The first action is generating a technical debt report, which quantifies the refactorings needed to leverage all identified improvements. Over time, your goal should be to reduce this technical debt score to zero.
$ codee technical-debt -- gfortran matmul.f90
TECHNICAL DEBT REPORT
This report quantifies the technical debt associated with the modernization of legacy code by assessing the extent of refactoring required for language constructs.
The score is determined based on the number of language constructs necessitating refactoring to bring the source code up to modern standards.
Additionally, the metric identifies the impacted source code segments, detailing affected files, functions, and loops.
Score Affected files Affected functions Affected loops
----- -------------- ------------------ --------------
12 1 1 4
TECHNICAL DEBT BREAKDOWN
Lines of code Analysis time Checkers Technical debt score
------------- ------------- -------- --------------------
16 12 ms 12 12
1 file, 1 function, 5 loops successfully analyzed (12 checkers) and 0 non-analyzed files in 12 ms
2. Screening Report and Ranking
While the technical debt report provides guidance on how many issues there are, the screening report details which recommendations of the Open Catalog are applicable to the code, and ranks them based on their estimated positive impact to help prioritize the refactoring efforts.
$ codee screening -- gfortran matmul.f90
SCREENING REPORT
Lines of code Analysis time # checks Profiling
------------- ------------- -------- ---------
16 13 ms 12 n/a
RANKING OF CHECKERS
Checker Priority AutoFix # Title
------- -------- ------- - ----------------------------------------------------------------------------------------------------------------------
PWR039 P27 (L1) x 1 Consider loop interchange to improve the locality of reference and enable vectorization
PWR068 P27 (L1) 1 Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
RMK015 P27 (L1) 1 Tune compiler optimization flags to increase the speed of the code
PWR003 P18 (L1) 1 Explicitly declare pure functions
PWR008 P18 (L1) x 1 Declare the intent for each procedure parameter
PWR070 P18 (L1) 1 Declare array dummy arguments as assumed-shape arrays
PWR071 P6 (L2) 2 Prefer real(kind=kind_value) for declaring consistent floating types
PWR007 P6 (L2) x 1 Disable implicit declaration of variables
PWR035 P2 (L3) 1 Avoid non-consecutive array access to improve performance
RMK010 P0 (L3) 2 The vectorization cost model states the loop is not a SIMD opportunity due to strided memory accesses in the loop body
3. ROI Report
Next, the ROI report estimates the time and effort saved through Codee’s automated analysis, and tailor the ROI estimation to your organization. This report contrasts, against the automated process of Codee, the manual time that would have been spent evaluating the applicability of each rule of the Open Catalog to the code.
$ codee roi -- gfortran matmul.f90
ROI ANALYSIS SUMMARY
This analysis underscores the tangible benefits Codee brings to the development process,
not only in terms of savings in development effort, but also in realizing significant cost efficiencies for the organization.
Impact on Development Effort:
This report identifies critical areas within the source code that necessitate attention from the development team,
and forecasts a significant reduction in workload by an estimated 223 hours.
Without Codee | With Codee | Hours saved
------------- | ---------- | -----------
235 hours | 12 hours | 223 hours
Impact on Cost Savings:
Considering a standard developer's workload of approximately 1800 hours/year,
Codee's intervention translates to saving an equivalent to 0.12 (223h / 1800h) developers working full-time.
Assuming an average cost of a developer for the company (salary + associated costs) of €100,000,
this amounts to cost savings of €12,388 (€100,000 x 0.12).
Developer hours/year | Number of devs. saved/year | Developer salary/year | Total costs saved/year
-------------------- | -------------------------- | --------------------- | ----------------------
1800 hours | 0.12 | €100,000 | €12,388
ROI CALCULATION BREAKDOWN
<...>
4. Checks Report and Autofix
The checks report pinpoints the exact locations in your source code where opportunities for improvement exist. Codee’s verbose mode provides even more detailed information, along with recommendations on how to proceed.
$ codee checks -- gfortran matmul.f90
CHECKS REPORT
matmul.f90:6:3 [PWR039] (level: L1): Consider loop interchange to improve the locality of reference and enable vectorization
matmul.f90:1:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
matmul.f90 [RMK015] (level: L1): Tune compiler optimization flags to increase the speed of the code
matmul.f90:1:1 [PWR003] (level: L1): Explicitly declare pure functions
matmul.f90:1:1 [PWR008] (level: L1): Declare the intent for each procedure parameter
matmul.f90:1:1 [PWR070] (level: L1): Declare array dummy arguments as assumed-shape arrays
matmul.f90:1:1 [PWR007] (level: L2): Disable implicit declaration of variables
matmul.f90:2:3 [PWR071] (level: L2): Prefer real(kind=kind_value) for declaring consistent floating types
matmul.f90:3:3 [PWR071] (level: L2): Prefer real(kind=kind_value) for declaring consistent floating types
matmul.f90:13:3 [PWR035] (level: L3): Avoid non-consecutive array access to improve performance
matmul.f90:7:5 [RMK010] (level: L3): The vectorization model states the loop is not a SIMD opportunity due to strided memory accesses
matmul.f90:15:7 [RMK010] (level: L3): The vectorization model states the loop is not a SIMD opportunity due to strided memory accesses
$ codee checks --verbose -- gfortran matmul.f90
CHECKS REPORT
<...>
matmul.f90:1:1 [PWR007] (level: L2): Disable implicit declaration of variables
Suggestion: Add IMPLICIT NONE in the specification part of the procedure 'matmul'
Documentation: https://github.com/codee-com/open-catalog/tree/main/Checks/PWR007
AutoFix:
codee rewrite --modernization implicit-none --in-place matmul.f90:matmul -- gfortran matmul.f90
<...>
For example, Codee might suggest adding implicit none in Fortran to disable implicit variable declarations. With Codee’s autofix feature, you can automatically apply such recommendations, improving your code with a simple command-line invocation.
$ codee rewrite --modernization implicit-none --in-place matmul.f90:matmul -- gfortran matmul.f90
Results for file '/home/user/matmul.f90':
Successfully applied AutoFix to the procedure at 'matmul.f90:1:1' [using insert implicit none]:
[INFO] Inserted implicit none:
- matmul.f90:1:1
Successfully updated matmul.f90
$ git diff matmul.f90
subroutine matmul(n, A, B, C)
+ ! Codee: Made all variable declarations explicit (2024-08-02 13:04:38)
+ implicit none
+ integer :: i
+ integer :: j
+ integer :: k
+ integer :: n
double precision, dimension(n, n), intent(in) :: A, B
double precision, dimension(n, n), intent(out) :: C
Conclusion
Codee simplifies the complex process of modernizing and optimizing your codebase through automated static analysis. By offering a comprehensive, top-down approach that integrates seamlessly into your workflow, Codee ensures that both strategic objectives and technical improvements are in sync.
What part of your codebase do you think could benefit most from automated analysis? Let us know in the comments!
Build correct, secure, modern and fast Fortran, C and C++ scientific software
This company is capitalized by INNVIERTE, AN INVESTMENT PROGRAM OF CDTI, E.P.E
Leave a Reply