AI
LLMs Stumble on Real-World Code Design: Study Reveals Gaps in Cohesion and Coupling Analysis
New research shows large language models perform well on clean code examples but struggle dramatically when asked to reason about design flaws in noisy, realistic scenarios.
Researchers have put large language models through their paces on a core software engineering challenge: understanding how well-designed code should be organized. The findings suggest that while LLMs can spot obvious design problems in textbook examples, their grasp becomes fragile the moment real-world complexity enters the picture.
The Test: Cohesion vs. Coupling#
The study examined whether major LLMs—including DeepSeek-R1 (14B, 32B, 70B variants), GPT-5 Nano, and Gemini-2.5 Flash Lite—could evaluate two fundamental principles in software design:
- Cohesion: how well functions and data within a module belong together
- Coupling: how much one module depends on another
Researchers generated poorly designed code samples and tested the models under three escalating levels of difficulty: simple verification tasks (spotting a known flaw), guided generation (fixing code with hints), and open-ended generation (solving problems with no scaffolding). They also added distractor elements to simulate the noise of real codebases.
Where Models Excel—and Fail#
The results split cleanly along a troubling line. When given clean code and clear guidance, all tested models showed reasonable baseline competence. However, performance collapsed differently depending on the concept:
- Coupling analysis proved especially brittle. As guidance evaporated and noise increased, reasoning about inter-module dependencies degraded sharply, with F1 scores dropping more than 50%.
- Cohesion reasoning held up better in guided, noisy tasks but completely fell apart in open-ended scenarios without instructions.
A Gap That Widens#
The researchers also compared LLM performance against experienced developers and researchers. When tasks were straightforward (verification only), humans and models performed similarly. But as the problems grew messier and less structured, the gap widened significantly—a sign that LLMs lack the robust mental models human engineers build through practice.
Detailed analysis of how models reasoned through problems revealed why: on coupling tasks, models "shortcut" to quick answers rather than reasoning deeply, while on cohesion they attempted exhaustive analysis but still failed to reach correct conclusions.

