Byte by Byte › Book 8: Real-World Coding, Data and AI › Chapter 14: Using AI as a Coding Assistant Responsibly
Chapter 14: Using AI as a Coding Assistant Responsibly
🔎 The Case
Pip, now eleven and impatient, asks a chatbot to "make a quiz app" and pastes the 200 lines it returns into the Truth Desk site. It almost works. Then it fails on the first quiz with an apostrophe in a question, and Pip has no idea why, because he never understood the code. Memoon sits down with him. "An AI can be a brilliant helper," she says. "But it can't be the one who understands. That job is yours."
💡 The Concepts
What AI coding assistants do well:
- Explain an error message or a confusing line of code.
- Suggest how to approach a problem, or several approaches to compare.
- Write small, routine pieces (a function to format a date) that you then read and test.
- Review your code and point out bugs, edge cases or unclear names.
- Generate test cases you hadn't thought of.
Where they fail:
- They hallucinate functions or libraries that don't exist.
- They produce code that runs but is subtly wrong (logic errors), or insecure (for example, putting user input into
innerHTML, Chapter 4). - They don't know your whole project, data or requirements unless you tell them.
- They may use outdated versions of libraries.
The responsible workflow:
- Think first. Write your own plan or pseudocode before asking.
- Ask small and specific. "Write a JavaScript function that returns true if a string contains only digits" beats "make my app".
- Give context. Language, version, what you have tried, the exact error message.
- Read every line. If you can't explain a line, ask the AI to explain it, or don't use it.
- Test it yourself with normal, boundary and wrong inputs (Chapter 15).
- Credit it. Note in a comment or report where AI helped. Follow your school's rules.
- Protect secrets. Never paste passwords, API keys or other people's personal data into a chatbot.
Learning vs producing. While you are learning, the struggle is the learning. Use AI as a tutor that gives hints, not a machine that gives answers. A good prompt: "Don't give me the code. Give me a hint about why my loop never ends."
Licences. Code you find online or get from AI may be copied from projects with licences. Open-source licences (MIT, GPL, Apache) say how code may be reused. For school projects, small snippets are fine with credit; for products, check.
🛠️ Build It
- Explain a bug. This Python has a logic error. Ask an AI assistant to explain (not fix) it, then fix it yourself:
def average(marks):
total = 0
for m in marks:
total += m
return total / len(marks)
print(average([80, 90, 70])) # should be 80.0
- Review AI code. Ask: "Write a JavaScript function
isValidPin(pin)that returns true for exactly 4 digits." Then test it yourself with:"1234","123","12345","12a4",""," 1234". Did it pass all six? Write down any failure. - Hint-only tutoring. Pick a Test Yourself challenge you found hard in an earlier chapter. Ask an AI for hints only, never the answer, and solve it.
- Record your use. Start an AI use log for your capstone: date, tool, what you asked, what you used, what you changed.
✅ Case Closed
Pip deletes the 200 pasted lines and rebuilds the quiz in three small functions, asking the AI to explain each error as it happens. The apostrophe bug turns out to be a string broken by a quote character, and this time Pip finds it himself. His version is shorter, and he can explain every line of it.
Think About It: If an AI writes most of a program, who is responsible when it fails: the AI company, the student, or the teacher who allowed it?
❓ Test Yourself
- Give three good uses and three risks of AI coding assistants.
- Why should you write a plan before asking an AI for code?
- Improve this request: "fix my code".
- What should you never paste into a chatbot?
- What is an open-source licence?
- Challenge: Explain in plain words what was wrong with
average()in Build It step 1.
📚 Key Terms
AI coding assistant · pseudocode · context · code review · edge case · hallucinated library
- insecure code · hint-based tutoring · attribution · AI use log · open-source licence · MIT
licence · GPL · secret / API key
Keep learning with Byte by Byte
Explore Book 8: Real-World Coding, Data and AI. Find the ebook, purchase details and teaching slides on MemuniCity.
Comments
Post a Comment