Using ChatGPT To Write Code and its limitations

How AI is used in development

  • Code generation and code suggestion/completion: 47%
  • Explanations of how a piece of code works: 40%
  • Summaries of code changes: 38%
  • Chatbots that allow users to ask questions in documentation using natural language: 35%
  • Summaries of code reviews: 35%

Using ChatGPT to write code in 2025 can be highly efficient and productive, whether you’re a beginner or an experienced programmer. Here’s a guide on how to effectively use ChatGPT for coding tasks:


1. Specify Your Goal Clearly

Before starting, define the task or problem:

  • Explain the functionality or feature you want.
  • Provide context, such as the programming language and environment.
  • Example: «Write a Python script to scrape weather data from a website using BeautifulSoup.»

2. Leverage ChatGPT for Code Generation

ChatGPT can help with:

  • Writing complete code snippets.
  • Explaining how the code works.
  • Modifying or optimizing existing code.

Example:

Prompt:
«Can you write a JavaScript function to validate an email address?»

Response:

javascriptCopy codefunction validateEmail(email) {
    const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    return regex.test(email);
}
// Usage
console.log(validateEmail("example@example.com")); // true
console.log(validateEmail("invalid-email")); // false

3. Debugging Code

If you encounter errors, share the problematic code and error message. ChatGPT can assist with debugging.

Prompt:
«My Python code throws a ‘KeyError’ when accessing a dictionary. Here’s the code: …»


4. Request Explanations

For learning purposes, ask ChatGPT to explain how a piece of code works.

Prompt:
«Explain this SQL query: SELECT name FROM users WHERE age > 30 ORDER BY age DESC.»


5. Refactoring Code

You can provide your code and ask for improvements or optimizations.

Prompt:
«Here’s my code. Can you refactor it to make it cleaner?»


6. Generating Documentation

Ask ChatGPT to create documentation for your code.

Prompt:
«Generate comments and a README file for this Python project.»


7. Learning New Concepts

ChatGPT can teach programming concepts, algorithms, or frameworks.

Prompt:
«Explain the difference between REST and GraphQL.»


8. Write Test Cases

Request test cases to ensure your code is working correctly.

Prompt:
«Write unit tests in Python for this function.»


9. Stay Collaborative

  • Provide feedback: If the output isn’t correct or complete, guide ChatGPT to refine it.
  • Share examples: Include specific details to improve the accuracy of the response.

10. Save and Adapt

Once ChatGPT generates code:

  • Save it in your preferred IDE.
  • Test it in your development environment.
  • Adapt the code as necessary to fit your specific requirements.

By iterating between your input and ChatGPT’s output, you can efficiently develop, debug, and learn new programming skills.

QUOTES

After a bunch of repeated tests, it became clear to me that if you ask ChatGPT to deliver a complete application, it will fail. A corollary to this observation is that if you know nothing about coding and want ChatGPT to build you something, it will fail. (1)

Where ChatGPT succeeds — and does so very well — is in helping someone who already knows how to code to build specific routines and get specific tasks done. Don’t ask for an app that runs on the menu bar. But if you ask ChatGPT for a routine to put a menu on the menu bar, and then paste that into your project, the tool will do quite well. (1)

LINKS

(1) https://www.zdnet.com/article/how-to-use-chatgpt-to-write-code-what-it-does-well-and-what-it-doesnt

/2/ https://www.zdnet.com/article/ai-accelerates-software-development-to-breakneck-speeds-but-measuring-that-is-tricky/

Author: admin

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *