Gemini vs ChatGPT vs Claude: Which Writes Code Best?

One Two Three AI — in your inbox

AI news, practical tips and how-to guides. One useful idea a day.

Gemini vs ChatGPT vs Claude: Which Writes Code Best?
Image generated with AI

If you’re using AI to help with coding, you’ve probably noticed that different models handle programming tasks differently. ChatGPT, Claude, and Gemini all claim strong coding capabilities, but which one actually delivers when you need to write, debug, or understand code?

We tested all three on identical coding tasks across Python, JavaScript, and SQL to see how they compare in real-world scenarios.

Writing Functions from Scratch

We asked each model to write a Python function that processes a list of dates, converts them to different timezones, and handles edge cases like invalid inputs.

ChatGPT (GPT-4) provided clean, working code with helpful comments. It included error handling without being asked and explained what each section did. The code ran on the first try.

Claude wrote similar quality code but added more extensive documentation and suggested test cases. It also proactively mentioned potential performance issues with large datasets and offered an optimized version.

Gemini’s code also worked but was more verbose. It included more explanatory comments than necessary, which can be helpful for beginners but clutters the code for experienced developers. The function structure was solid but slightly less elegant.

Winner for writing new code: Claude, for balancing clean implementation with thorough documentation and performance awareness.

Debugging Existing Code

We gave each model broken JavaScript code with three distinct bugs: a syntax error, a logic error, and an off-by-one error in a loop.

ChatGPT identified all three bugs quickly and explained each fix clearly. It provided the corrected code and a brief explanation of why each error occurred.

Claude also caught all three issues but went further—it suggested refactoring the function to prevent similar bugs in the future and pointed out a potential security vulnerability we hadn’t even asked about.

Gemini found the syntax error immediately and the logic error after its initial pass, but initially missed the off-by-one error. When we asked it to check again, it caught the third bug and fixed it correctly.

Winner for debugging: Claude, for comprehensive bug detection plus proactive security and code quality suggestions.

Explaining Complex Code

We provided each model with a 50-line Python function implementing a binary search tree and asked for an explanation suitable for someone learning the concept.

ChatGPT broke down the code into logical sections with clear explanations. It used analogies to explain the binary search tree concept and walked through an example of how the code would execute.

Claude provided a similar explanation but structured it differently—starting with the high-level concept, then diving into implementation details, then back to practical use cases. This approach felt more educational.

Gemini’s explanation was thorough but overly detailed for a beginner. It explained every single line, which made the overall structure harder to grasp. However, for someone wanting exhaustive detail, this approach works.

Winner for code explanation: ChatGPT, for striking the best balance between clarity and completeness for learners.

SQL Query Generation

We asked each model to write a complex SQL query involving multiple joins, aggregation, and a subquery to analyze sales data across regions and time periods.

All three models produced working queries, but with different approaches. ChatGPT’s query was straightforward and efficient. Claude’s included additional CTEs (common table expressions) that made the query more readable and easier to modify. Gemini’s query worked but used nested subqueries where joins would have been clearer.

Winner for SQL: Claude, for writing queries that are both functional and maintainable.

Which Model Should You Use for Coding?

Based on these tests, here’s the practical breakdown:

  • Use Claude when you need high-quality, production-ready code with good documentation and you want proactive suggestions about performance and security.
  • Use ChatGPT when you need quick, reliable code that works immediately and clear explanations for learning purposes.
  • Use Gemini when you’re learning and want extremely detailed explanations, or when you need to understand every aspect of how code works.

The differences aren’t dramatic—all three models are competent at coding tasks. Your choice depends more on your experience level and what kind of help you value most: Claude’s thoroughness, ChatGPT’s balance, or Gemini’s detailed explanations.

One important note: none of these models are perfect. Always test AI-generated code yourself, especially for production use. They all occasionally introduce subtle bugs or suggest outdated approaches.

Want more practical AI insights like this? Subscribe to the One Two Three AI newsletter—one useful AI idea delivered to your inbox every day.

One Two Three AI — in your inbox

AI news, practical tips and how-to guides. One useful idea a day.

Other newsletters you might like

Love Netherlands

Canal towns, hidden villages, Dutch stories — a slow, loving look at the Netherlands, written by the people who love it most.

Subscribe

Irish Rugby Fans

The best Irish rugby updates, straight to your inbox — Six Nations, the Nations Championship and the provinces. Only when there's something worth reading.

Subscribe

Scottish Rugby Fans

The best Scottish rugby updates, straight to your inbox — Six Nations, the Nations Championship, Glasgow and Edinburgh. Only when there's something worth reading.

Subscribe

Love Space

Love Space — in your inbox. Space travel, rockets, planets and the cosmos. One cosmic idea a day.

Subscribe

Newsletters via the One Two Three Send network.  ·  Want your newsletter featured here? Click here

Scroll to Top