How to Effectively Use LLMs for Programming: Methods and Checklists for Developers
This article explores the practical application of large language models in software development. It covers capability boundaries, requirement decomposition, iterative generation, and code review. By understanding common pitfalls and adopting specific checklists, developers can safely leverage AI to improve coding efficiency while maintaining code quality.
Introduction: What LLMs Can Do and Where They Fail
The programming capabilities of large language models (LLMs) have advanced rapidly. From the early days of completing short functions, they can now participate in requirement analysis, module implementation, and integration debugging. Many developers find that the initial implementation time for simple modules is significantly reduced. However, this acceleration comes with prerequisites: clear requirements, sufficient context, and tested results. This article explains how developers can use LLMs across capability boundaries, requirement decomposition, iterative generation, code review, common errors, and role evolution, providing actionable checklists.
1. What LLMs Are Good At and What They Aren’t
Different tasks vary in difficulty and risk, requiring different approaches. The table below serves as a reference for selecting scenarios.
| Task Type | Typical Examples | Applicable Conditions | Verification Method | Main Risks |
|---|---|---|---|---|
| High-frequency, low-difficulty tasks | Data cleaning scripts, regex, Shell commands, boilerplate code | Clear requirements, fixed input/output | Run samples, compare with expected output | Ignoring null values and abnormal formats |
| Writing unit tests | Adding test cases for existing functions | Can access tested code | Tests pass, and fail when intentionally broken | Tests only cover the happy path |
| Advanced troubleshooting | Concurrency deadlocks, performance bottlenecks, unfamiliar frameworks | Provide error stack, runtime environment, and reproduction steps | Reproduce issue and verify fix | Providing seemingly plausible but invalid fixes |
| Complete modules or small systems | Business modules with state management, small utility apps | Clear module boundaries, phased execution | Test modules separately, record integration results | Chaotic coupling between modules, difficult to locate issues |
Models perform relatively stably on common languages and mainstream frameworks. For niche frameworks, private APIs, and tasks requiring extensive business context, the error rate is typically higher. Regardless of the task, generated code must pass unit tests and code review before entering the project.
2. How to Write Clear Requirements for AI-Generated Code
Since code generation is no longer scarce, defining the problem becomes the main bottleneck. Requirements submitted to the model should typically include the following five elements:
- Input and Output: Data formats, field meanings, sample data.
- Constraints: Performance requirements, dependency versions, disallowed patterns.
- Acceptance Criteria: Which test cases must pass, which exceptions must be handled.
- Runtime Environment: OS, language version, framework version.
- Existing Information: Error stacks, relevant code snippets, previously attempted methods.
Take a reputation system in a game as an example. “Reputation affects NPC attitude” is just a design statement and cannot be implemented directly. Developers need to supplement details: the reputation value range (e.g., -100 to 100), which NPC behaviors it affects (trade prices, dialogue options, whether to attack the player), which events change reputation (completing quests, killing specific characters), and whether there is a cap on changes. The more specific the details, the easier the generated result is to verify and accept.
3. One-Shot Generation vs. Iterative Generation
| Comparison Dimension | One-Shot Generation of Entire System | Iterative Generation |
|---|---|---|
| Initial Speed | Fast, large chunks of code in a short time | Slower, requires confirmation at each step |
| Structural Quality | Prone to module coupling | Architecture and interfaces checked at each step |
| Error Localization | Hard to determine the source after an error | Error scope limited to the current module |
| Applicable Scenarios | Prototype demos, one-off scripts | Systems requiring long-term maintenance |
Iterative generation can proceed with the following steps, advancing to the next only after manual confirmation at each step:
- Ask the model to output the overall architecture, including module division and dependencies, and judge whether the division is reasonable.
- Define the interface for each module, specifying inputs, outputs, and exceptions.
- Implement modules one by one, adding tests for each module.
- Conduct integration testing after module assembly, recording issues found and fixes.
4. How to Review AI-Generated Code
AI-generated code might miss boundary conditions or introduce security vulnerabilities. It is recommended to check item by item against the following list:
- Boundary Conditions: Are empty inputs, oversized inputs, numerical overflows, timezone, and encoding issues handled?
- Security: Are unescaped SQL or Shell commands concatenated? Are keys hardcoded? Is user input validated?
- Performance: Are there repeated queries in loops? Will it timeout or exhaust memory under large data volumes?
- Dependencies: Do the imported libraries exist? Are versions consistent with the project? Are licenses acceptable?
- Concurrency: Are shared states locked? Are failures and timeouts handled in asynchronous calls?
- Testing: Do tests cover exception paths, not just the normal flow?
Regarding the review process, AI-generated code should use the same pipeline as human-written code: submit for code review, run tests via CI/CD, and observe logs and monitoring after deployment. Teams can flag AI-generated code in review records to facilitate tracking issues later.
5. Common Errors in LLM Programming
- Hallucinated APIs: The model might call non-existent functions or parameters. The solution is to check against official documentation or let the compiler and type checker run first.
- Version Mismatches: Generated code applies to older framework versions. The solution is to specify version numbers in the prompt.
- Only Handling the Happy Path: The code runs the examples but crashes on abnormal input. The solution is to ask the model to provide exception handling and corresponding tests simultaneously.
- Hardcoded Sensitive Information: Keys or addresses in sample code are directly retained. The solution is to switch to environment variables or a key management service.
- Over-trusting Output: Plausible-looking code is merged without running. The solution is to mandate running tests before submission.
6. Efficiency Improvement and Developer Role Evolution
Developers generally worry about job stability, a concern that can be viewed rationally. Development roles will likely evolve rather than disappear. As AI takes over repetitive coding tasks, developers can focus more on architecture design, complex problem-solving, and system integration, shifting from pure code writers to system thinkers.
