Hi everyone, I'm currently working on a legacy system migration project where we're converting a bunch of scientific Fortran 77/90 code to Python (NumPy/SciPy). I'm trying to introduce some modern practices, including automated code review, but I'm hitting a wall.
Most AI review tools I've tried (like SonarQube with its new AI features, or GitHub Copilot for Pull Requests) seem heavily optimized for mainstream languages like JavaScript, Java, or Python itself. When I feed it a Python file that's a direct translation of Fortran logic—think lots of nested loops, 1-based indexing thinking, and `GOTO` patterns translated to flags—the feedback is either superficial (formatting) or misses the architectural issues entirely.
For example, here's a snippet from a translated module:
```python
def compute_flux(n, a, b):
# Original Fortran was heavily loop-based
flux = np.zeros((n, n))
for i in range(1, n+1):
for j in range(1, n+1):
# ... complex physics
if a[i-1, j-1] > b[i-1, j-1]:
flux[i-1, j-1] = a[i-1, j-1]
else:
flux[i-1, j-1] = 0.0
# Potential vectorization point missed
return flux
```
A good review should flag the manual 1-based adjustment and suggest vectorization. The tools I tested either just check PEP 8 or stay silent.
So my question is: has anyone found an AI-powered review tool that actually works well for this kind of migration code? I care about:
* Catching "Fortran in Python" anti-patterns.
* Not drowning us in false positives about style when the real issue is structure.
* Actually understanding numerical/scientific code context.
I'm open to both standalone tools and integrations (GitHub/GitLab). What's been your experience with precision on non-standard tasks like this?
Yeah, I can see the problem. Those general AI tools are looking for standard Python patterns, not "translated Fortran" logic. They won't flag the 1-based indexing mindset or the missed vectorization opportunities.
For a migration like this, you might need a more specialized approach. I've heard of teams creating custom linting rules in something like Pylint or Flake8 to specifically hunt for those Fortran-isms - like manual loops over arrays that could be NumPy operations, or flag variables that simulate GOTOs. It's more setup, but it targets your exact issue.
Have you looked at any static analyzers that let you define transformation patterns? The off-the-shelf AI isn't trained on this niche hybrid code.
automate the boring stuff
Exactly! Those tools are looking for idiomatic Python, but your code is still thinking in Fortran. I ran into something similar translating old COBOL logic for a CRM data pipeline.
You might want to check out Semgrep. You can write custom rules to catch those "Fortran-isms" as code patterns. A simple rule could flag any for loop iterating over a NumPy array without a vectorized operation inside, or warn about manual 1-to-0 index adjustments. It's not a full AI reviewer, but it can be trained on your own problematic translation patterns.
What's your biggest pain point right now? Is it more about performance (missing vectorization) or code maintainability (the GOTO flags)?
The snippet shows exactly what's burning money. Those loops will cripple performance on any cloud VM.
You need a rule that flags manual loops over NumPy arrays as a cost issue, not just a style one. Every iteration is unnecessary compute time you're paying for.
Custom Semgrep rule targeting `for i in range(...):` with a NumPy array inside the loop body would catch it. Pair it with a cost estimate: show how much slower and more expensive the EC2 instance needs to be to run that vs. a vectorized version.
Focus reviews on the patterns that directly increase your cloud bill.
cost per transaction is the only metric