Skip to main content
If you’ve ever spent hours debugging code only to discover the fix was much simpler than you thought, you already know ChatGPT can be an excellent pair-programming buddy. This practical guide covers how to use ChatGPT effectively for software development: asking targeted questions, uploading files, scaffolding code, debugging, and choosing models or building custom GPTs for team workflows. What you’ll learn:
  • How to structure prompts and keep conversation context for iterative development.
  • Patterns for safe database connections and HTTP requests in Python.
  • When to use different ChatGPT models and Canvas for interactive editing.
  • How to design and use Custom GPTs for repeatable team tasks.
Quick overview:
  • The chat interface is clean and minimal: conversation history appears on the left and can be starred or continued.
  • You can upload files, ask incremental questions, and maintain context within a conversation.
  • ChatGPT is excellent for documentation, scaffolding, feature design, and debugging. For IDE-integrated, repository-aware assistance, consider tools like GitHub Copilot, Tabnine, or Blackbox AI.
Treat ChatGPT as a starting point. Read and understand generated code before copying it into production.

Best practices for using ChatGPT as a programming assistant

  • Provide a minimal reproducible example: include the smallest failing code, exact error messages, and environment details (Python version, OS, installed libs).
  • Break large problems into smaller steps and iterate: ask for a scaffold, then request tests or edge-case handling.
  • Use uploaded files or Canvas when you want the model to operate on real files or an editable surface.
  • Validate generated code with linters, unit tests, and static analysis before merging.

Example: Connecting to MySQL with Python

This concise, correct pattern shows how to connect to MySQL using mysql-connector-python, run queries safely, and ensure clean resource cleanup. Install the connector:
Python example:
Notes:
  • Use cursor(dictionary=True) to return rows as dictionaries for named access.
  • Always close cursors and connections in finally or equivalent cleanup logic.
  • Never embed credentials in source control—use environment variables or secret managers.

Choosing the Right Model for Development Tasks

Selecting a model depends on your need for reasoning depth, latency, and cost. Use this table to compare common choices: Choose the model that balances latency, cost, and the depth of reasoning you need. For repository-aware changes, prefer IDE-integrated assistants or provide the relevant files to ChatGPT. Links and references:

Canvas: Interactive Editing of Files

Canvas (available with some gpt-4o variants) provides a running, editable surface where the model can output and modify files directly. It’s ideal for prototyping, single-file refactors, or collaborative edits. Example — HTML boilerplate with CSS and JavaScript:
When to use Canvas vs IDE assistants:
  • Canvas: fast, focused edits on one or a few files and interactive mockups.
  • IDE assistants (Copilot, Tabnine): repository-aware changes, refactors spanning many files, and tests aligned to your codebase.

Working with Custom GPTs

Custom GPTs let you embed domain knowledge, coding standards, and helper commands into a tailored assistant. They’re useful for automating routine review tasks, enforcing style rules, or accelerating onboarding. Example command styles for a Custom GPT:
Custom GPTs can be trained with style guides, code examples, and rules (e.g., excerpts from Code Complete) so the assistant’s suggestions align with your team’s expectations.
Use custom GPTs to enforce code review heuristics, suggest refactorings, and provide tailored debugging guidance.

Example: Sending HTTP Requests with requests (Python)

Install:
Robust patterns for GET, POST, and file uploads, with timeouts and error handling:
Practical tips:
  • Always set a timeout to avoid hanging requests.
  • Use response.raise_for_status() to convert HTTP errors into exceptions.
  • Prefer logging over print() for production and visibility.
  • Validate and sanitize inputs before sending them.
Table: HTTP helper overview

Using Advanced Reasoning Models for Debugging

Models like o1-preview are optimized for stepping through code and identifying root causes. When you use them:
  • Share the full function or module and the failing test or error trace.
  • Ask the model to list likely failure modes, missing imports, or incorrect assumptions.
  • Request a proposed patch with tests or a diff.
Common improvements recommended by advanced models:
  • Verify imports and package versions.
  • Add explicit exception handling and edge-case checks.
  • Introduce timeouts, retries, and clear logging.
  • Add unit tests and CI-friendly assertions.

Custom GPT Example: Automated Code Review (CodeMonkey)

A Custom GPT trained on code-quality principles can output structured reviews with actionable suggestions:
  • Strengths (readability, modularity)
  • Weaknesses (missing exception handling, hard-coded values)
  • Actionable steps (use logging, add validation, improve error handling)
Example suggested improvements for a naive POST script:
  • Wrap request calls in try/except.
  • Use response.raise_for_status() and explicit status checks.
  • Replace prints with logging.
  • Return structured data or None on failure.
Suggested improved snippet (example):

Final Recommendations and Workflow Tips

  • Use ChatGPT as a context-free brainstorming and explanation tool; validate and test everything it suggests.
  • For repository-aware suggestions or large-scale refactors, rely on IDE-integrated assistants or provide the specific files to ChatGPT or Canvas.
  • Build or adopt Custom GPTs for repetitive team rules, automated code reviews, or onboarding checklists.
  • Always use linters, unit tests, and peer reviews before merging generated changes.
  • Treat generated code as a starting point: improve error handling, observability, and security before deploying.
This lesson covered practical patterns for MySQL connections, HTTP requests, Canvas-based editing, model selection, and building custom assistants. Use these patterns to accelerate development while maintaining code quality and operational safety.

Watch Video