Introduction
In large projects, subtle anti-patterns can slip through reviews—like importing modules mid-file or conditionally. These non-standard import placements obscure dependencies, make static analysis unreliable, and lead to unpredictable runtime errors. This web article dives into that practice, outlines a broader set of coding bad practices, and even provides a ready-to-use AI coding agent prompt to catch every issue across your codebase.
What Is Non-Standard Import Placement?
Imports or require statements buried inside functions, conditional branches, or midway through a file violate expectations of where dependencies live. Best practices and most style guides mandate that:
- All imports sit at the top of the file, immediately after any module docstring or comments.
- Conditional or lazy loading only happens with clear justification and documentation.
When imports are scattered:
- Static analysis tools can’t reliably determine your project’s dependency graph.
- Developers hunting for missing or outdated modules lose time tracing hidden import logic.
- You risk circular dependencies, initialization bugs, or runtime surprises.
A Broader List of Coding Bad Practices
Below is a table of widespread anti-patterns—some classic hygiene issues and others that modern AI agents might inject or overlook:
| Bad Practice | Description |
|---|---|
| Spaghetti Code | Code with no clear structure making maintenance difficult. |
| Hardcoding Values | Embedding constants directly instead of using config or constants. |
| Magic Numbers/Strings | Using unexplained literals instead of named constants. |
| Global State Abuse | Overusing global variables causing unpredictable side effects. |
| Poor Naming Conventions | Using vague or misleading variable and function names. |
| Lack of Modularity | Writing large monolithic blocks instead of reusable functions. |
| Copy-Paste Programming | Duplicating code rather than abstracting shared logic. |
| No Error Handling | Ignoring exceptions or failing to validate inputs. |
| Overengineering | Adding unnecessary complexity or abstraction. |
| Under-documentation | Failing to comment or explain non-obvious logic. |
| Tight Coupling | Making modules overly dependent on each other. |
| Ignoring Style Guides | Not following language-specific conventions or style guides. |
| Dead Code | Leaving unused or unreachable code paths in the codebase. |
| Inconsistent Formatting | Mixing indentation styles or inconsistent code layout. |
| Not Using Version Control Properly | Committing broken code, poor commit messages, ignoring branching. |
| Non-standard Import Placement | Placing imports mid-file or conditionally instead of at the top. |
| Missing Security Checks | Omitting authentication, authorization, or input sanitization. |
| Inefficient Algorithms | Using suboptimal logic that hurts performance. |
| Hallucinated Dependencies | Referencing non-existent libraries or methods from AI suggestions. |
| Incomplete Code Generation | Leaving functions or loops unfinished due to AI cutoffs. |
| Prompt-biased Solutions | Generating code that only fits the prompt and fails general cases. |
| Missing Corner Cases | Overlooking edge cases and error conditions in logic. |
| Incorrect Error Messages | Providing vague or misleading error feedback to users. |
| Logging Sensitive Data | Writing confidential information to logs without sanitization. |
| Violating SOLID Principles | Breaking single responsibility or open/closed design rules. |
| Race Conditions | Failing to handle concurrency leading to unpredictable bugs. |
Crafting an AI Coding Agent Prompt
To ensure an AI auditor doesn’t skip files, ignore edge cases, or take shortcuts, use the following prompt. It instructs the agent to comprehensively scan every line, record each finding, and tally occurrences of every bad practice.
## Prompt
You are an expert AI code auditor. Your mission is to exhaustively scan every file and line of the codebase and uncover all instances of known bad practices. Do not skip or shortcut any part of the project, even if the code is large or complex. Report every finding with precise details and clear remediation guidance.
## Scope
- Analyze every source file, configuration, script, and module.
- Treat all code as in-scope; do not assume any file is irrelevant.
## Bad Practices to Detect
- Spaghetti Code
- Hardcoding Values
- Magic Numbers/Strings
- Global State Abuse
- Poor Naming Conventions
- Lack of Modularity
- Copy-Paste Programming
- No Error Handling
- Overengineering
- Under-documentation
- Tight Coupling
- Ignoring Style Guides
- Dead Code
- Inconsistent Formatting
- Improper Version Control Usage
- Non-standard Import Placement
- Missing Security Checks
- Inefficient Algorithms
- Hallucinated Dependencies
- Incomplete Code Generation
- Prompt-biased Solutions
- Missing Corner Cases
- Incorrect Error Messages
- Logging Sensitive Data
- Violating SOLID Principles
- Race Conditions
## Analysis Instructions
1. Traverse the entire directory tree and open every file.
2. Inspect every line—do not skip blank or comment lines.
3. Identify code snippets matching any bad practice.
4. For each instance, document:
- File path
- Line number(s)
- Exact snippet
- Bad practice name
- Explanation of why it’s problematic
- Suggested refactoring
5. Keep a running tally of occurrences per bad practice.
## Output Requirements
- Use Markdown with a section per file.
- Subheadings for each issue.
- End with a summary table listing each bad practice and its total count.
- If the repo is too large, process in ordered batches (e.g., by folder), confirming coverage before proceeding.
- Do not conclude until every file has been reviewed.
Begin the full project audit now, acknowledging you will not take shortcuts.
Next Steps
- Integrate this prompt into your AI workflow or CI pipeline.
- Pair it with linters and static analyzers (ESLint, Flake8, Prettier) for automated, real-time checks.
- Enforce code review policies that catch both human and AI-introduced anti-patterns.
By combining clear style guidelines, automated linting, and an uncompromising AI audit prompt, you’ll dramatically improve code quality, maintainability, and security—project-wide.