Skip to content
CoursesWeb Forum

Can I trust code that ChatGPT or Copilot writes while I am learning?

Staff answerWritten by Callum Iwu · AI Coding Assistants and MCP0 replies

Short answer

Treat it as a draft from a fast helper that sometimes sounds sure and is wrong. It is useful for explanations and first versions, but you are the one who runs it, reads it and answers for it. Check it by running it, reading the docs it relies on, testing odd inputs, and never pasting secrets into a chat.

Written by Callum Iwu · Moderator: PHP, MySQL, Node.js and AI coding tools ·
CiteCoursesWeb Forum, "Can I trust code that ChatGPT or Copilot writes while I am learning?", https://coursesweb.net/forum/t/can-i-trust-code-that-chatgpt-or-copilot-writes-while-i-am-learning/, accessed 2026-11-22.
  1. Moderator: PHP, MySQL, Node.js and AI coding tools ·

    The short version of how to use it safely

    GitHub's own documentation agrees. In its guide to reviewing AI-generated code, it says AI tools can make unique mistakes: look for hallucinated APIs, ignored constraints or incorrect logic, and be sceptical of code that "looks right" but does not match your intent. GitHub's responsible use page for Copilot Chat defines a hallucination as output that sounds plausible but is factually incorrect or invented, and says generated explanations may not always be accurate or complete and should be reviewed. That applies equally to ChatGPT, Claude and any other assistant: the tool differs, the habit does not.

    A worked example: it runs, and it is still wrong

    Say you ask an assistant for a function that averages the numbers from a form. It returns this, and it works on your first test:

    function average(numbers) {
      return numbers.reduce((sum, n) => sum + n, 0) / numbers.length;
    }
    
    console.log(average([2, 4, 6]));     // 4
    console.log(average([]));            // NaN, because 0 / 0
    console.log(average(['2', '4']));    // 12, not 3
    

    The last line is the sneaky one. Form fields arrive as strings, so 0 + '2' joins text instead of adding, and the result is wrong without any error. A version that handles it:

    function average(numbers) {
      if (!Array.isArray(numbers) || numbers.length === 0) return null;
      const values = numbers.map(Number);
      if (values.some(Number.isNaN)) return null;
      return values.reduce((sum, n) => sum + n, 0) / values.length;
    }
    
    console.log(average(['2', '4']));    // 3
    console.log(average([2, 'x']));      // null
    

    Nothing here needed advanced skill. It needed someone to try an empty list and a list of strings.

    Check this in order

    1. Run it. Does it run at all, with no errors in the console or the PHP log?
    2. Try the boring cases. Empty input, one item, a very long item, text where you expect a number, quotes and angle brackets in text.
    3. Read what it relies on. For every function or method it uses, look it up in the official docs (MDN for browser JavaScript, the PHP manual for PHP). If you cannot find the function, it may not exist. GitHub's guide specifically warns about hallucinated APIs and packages that do not exist.
    4. Check dependencies before installing. GitHub's guide says to check that suggested packages exist and are maintained, and to watch for fake ones. Look the package up on its official registry page first.
    5. Look for the unsafe habits. SQL built by joining strings (see How do I use prepared statements with mysqli or PDO in PHP?), form values printed without htmlspecialchars (see How do I handle GET and POST form data safely in PHP?), passwords stored as plain text, or old mysql_ functions. An assistant can reproduce any pattern it has seen, including outdated ones.
    6. Explain it back. Can you say what each line does? If not, ask the assistant to explain it, then confirm the explanation against the docs. Explanations can be wrong too.

    Mistakes beginners make

    1. Pasting secrets into the chat. Never send API keys, passwords, database logins, private tokens or customer data. Replace them with placeholders such as YOUR_API_KEY before you paste, and keep the real values in a separate config file that is not shared.
    2. Letting it fix an error you do not understand. If a test fails and the answer is "delete the test", stop. GitHub's guide lists tests that are deleted or skipped instead of fixed as an AI pitfall.
    3. Copying a whole project in one go. Ask for small pieces you can read, run and understand, one at a time.
    4. Skipping the learning. If the tool writes every line, you never build the instincts for spotting a bad answer. A good routine: try first yourself, then ask it to review your attempt, then compare.

    When it is genuinely helpful

    Explaining an error message in plain words, showing two ways to do the same thing, writing a test case list, or reviewing code you wrote and pointing at lines to read again. In all of those, you stay in charge of what goes into the project.

    Connecting assistants to outside tools through MCP servers raises the same trust questions, and we cover that in a separate thread on what an MCP server is.

    0
    ReplyLink

Plain text or simple Markdown. Links are nofollow. Your email is never shown.

CoursesWeb Forum. Questions and answers on learning web development: HTML, CSS, JavaScript, PHP, MySQL, Node.js and AI coding help.