This repository contains the complete, polished submission for the CIT 411: Programming with Python course, Module 2 Applied Generative AI assignment: "AI for Code-Smell Detection — Defending Your Choices".
The primary objective of this project is to demonstrate how to perform an AI code review for code-smell detection, critically evaluate automated suggestions regarding Python data structures and control flow, refactor code based on accepted recommendations, and write formal technical justifications for rejected suggestions.
In this assignment, we build a realistic inventory analyzer for an art supplies store. The application processes database records from a CSV file, summarizes inventory totals, calculates category valuations, identifies low-stock items, and prints a deterministic status report.
We compare two versions of the analyzer:
analyzer.py: The original working version, intentionally written with various Python code smells (e.g., manual CSV string parsing, index-based tuple lookups, in-place list sorting, and verbose dict checking).refactored_analyzer.py: The optimized version, incorporating clean, idiomatic Python improvements (e.g., standard library context managers,csv.DictReader,collections.defaultdict,dict.items(), and non-destructivesorted()copies).
We verify that both scripts produce 100% identical outputs using automated differential testing, guaranteeing that refactoring improved internal design without altering external behavior.
The project is structured logically for submission:
python-ai-code-review-inventory-analyzer/
├── README.md # Project guide & metadata (this file)
├── analyzer.py # Original analyzer with intentional code smells
├── refactored_analyzer.py # Refactored, clean, and idiomatic Python analyzer
├── sample_inventory.csv # Source database containing 10 art supply items
├── .gitignore # Python-friendly git exclusion rules
├── docs/ # Academic analysis and reflection documentation
│ ├── ai_code_review_transcript.md # Mock AI review transcript & suggestions
│ ├── classification_table.md # Decision matrix mapping the 7 suggestions
│ ├── rejection_defenses.md # In-depth technical defenses of rejections
│ ├── verification_output.md # Capture steps and diff check validation
│ └── reflection.md # Essay on using Generative AI as a developer
└── outputs/ # Captured run logs
├── original_output.txt # Standard output from original analyzer
└── refactored_output.txt # Standard output from refactored analyzer
Explore the detailed reports generated for the assignment:
- AI Code Review Transcript: Contains the exact review prompt, original code, and 6 highly detailed suggestions generated by the AI reviewer.
- Classification Table: A complete matrix classifying all suggestions as
ACCEPT,REJECT-WITH-REASON, orDEPENDS, accompanied by formal developer justifications. - Rejection Defenses: Thorough technical explanations of why converting sorted lists to sets and replacing readable loops with complex, dense list comprehensions were rejected.
- Verification Output: Logging of terminal operations proving that the original and refactored outputs match character-for-character.
- Reflection: A professional academic essay discussing the value, friction, and software engineering philosophy of developing alongside Generative AI.
- Python 3.12 or newer.
- No third-party packages are required (uses standard library modules:
os,csv,collections).
You can run both scripts directly from your shell inside the workspace directory:
# Run the original analyzer
python3 analyzer.py
# Run the refactored analyzer
python3 refactored_analyzer.pyTo replicate the output verification protocol and confirm absolute parity between the original and refactored code, execute:
# Create outputs directory
mkdir -p outputs
# Capture standard outputs
python3 analyzer.py > outputs/original_output.txt
python3 refactored_analyzer.py > outputs/refactored_output.txt
# Run the diff utility
diff outputs/original_output.txt outputs/refactored_output.txtIf the diff command returns no output and exits with code 0, it confirms that the outputs are 100% identical.
Through this CIT 411 Module 2 assignment, several advanced concepts were mastered:
- Refactoring & Clean Code: Transitioning from manual string parsing to standard library parsers (
csv.DictReader), and improving data structure selection using idiomatic Python structures likedefaultdict. - Side-Effect Prevention: Realizing the danger of in-place mutation (
.sort()) inside read-only reporting routines, and replacing it with pure, functional sorting copies (sorted()). - Defending Engineering Decisions: Understanding that AI assistants lack critical domain context, and learning to write structured technical defenses based on ordering constraints and code readability over code brevity.
- Strict Verification: Utilizing automated differential testing (
diff) to prove refactoring correctness.