The Art of Prompting for a Developer

Is your LLM assistant more of a burden than a benefit? Many developers, including me, have struggled with AI models that misinterpret simple requests or overwhelm us with unrelated code. It feels like they are always in a “junior developer” stage. But what if the issue lies not with the LLM, but with how we communicate with it?

The Art of Prompting: Guiding Your AI Junior

We’ve all been there: a quick “give me X code” prompt returns a convoluted mess, or an analysis that merely parrots back what the code already does. This isn’t because the LLM is inherently bad; it’s because, much like a junior developer, it needs clear, precise guidance.

The core principle? You’re the senior developer, and the LLM is your diligent but uninitiated junior. You wouldn’t hand a new team member a vague request and expect production-ready code, would you? The same applies here.

Don’t Just Copy-Paste: Read and Reason

One of the biggest pitfalls with LLMs is the temptation to blindly copy-paste their output. Resist it. Always read the code. Always understand the logic. The LLM might generate syntactically correct code, but it could be inefficient, insecure, or simply not fit your specific context. Treat it as a starting point, not a final solution.

Beyond “Best Practices”: Be Specific

When you ask an LLM for “best practices,” you’ll get some best practices. But which ones? And are they relevant to your project, your team’s standards, or your current framework? Probably not all of them.

Instead, flip the script:

  1. Define Your Best Practices First: Before asking for an analysis or new code, have a clear idea of the best practices you want applied. Think about:
    • Performance considerations
    • Security vulnerabilities
    • Code readability and maintainability
    • Specific design patterns (e.g., SOLID principles)
    • Error handling strategies
    • Testing methodologies
  2. If you’re a junior developer wondering what a senior would look for, ask the LLM for that first. For example: “What are the key best practices a senior developer would consider when reviewing a Python REST API for scalability and security?” Then, refine that list to suit your needs.
  3. Craft a Guiding Prompt: Once you have your curated list of best practices, incorporate them into your subsequent prompts.
    • Bad Prompt: “Analyze this Python code for best practices.” (You’ll get a generic, potentially unhelpful response.)
    • Better Prompt: “Analyze the following Python code snippet for adherence to the following best practices: [List your specific best practices here, e.g., ‘single responsibility principle, robust error handling, efficient resource management’]. Provide specific line-by-line feedback and suggest improvements.”
    This level of detail forces the LLM to focus its reasoning on your criteria, not its broad, often too-creative understanding of “best practices.”

The LLM as a Reasoning Machine, Not an Expert

Here’s the crucial mental model shift: an LLM isn’t an expert with inherent knowledge. It’s a highly sophisticated reasoning machine that generates responses based on the patterns and information it has been trained on. It can connect concepts and present them coherently, but it doesn’t “understand” in the human sense.

If you’re not specific, it will fill in the blanks, often creatively, which is great for brainstorming but terrible for precision engineering.

Actionable Takeaways for Better Prompting:

  • Be the Senior: Assume the LLM is a capable but naive junior. Provide clear instructions and define the scope.
  • Pre-define Your Constraints: Before asking for an analysis or new code, explicitly state the rules, standards, and best practices you want it to follow.
  • Iterate and Refine: Your first prompt might not be perfect. Refine it based on the LLM’s initial output, just as you would guide a human junior through a task.
  • Read Everything Critically: Never blindly trust the output. Always review, test, and understand the code or analysis provided.

By adopting this mindset and embracing structured, specific prompting, you’ll transform your LLM from a source of frustration into a powerful, albeit guided, extension of your development workflow.


Never Miss Another Tech Innovation

Concrete insights and actionable resources delivered straight to your inbox to boost your developer career.

My New ebook, Best Practices To Create A Backend With Spring Boot 3, is available now.

Best practices to create a backend with Spring Boot 3

Leave a comment

Discover more from The Dev World - Sergio Lema

Subscribe now to keep reading and get access to the full archive.

Continue reading