ChatGPT Takes on Coding: What I Learned from “Hello, World” in 12 Programming Languages
2024-11-18
Author: Noah
Over the past year, ChatGPT's coding prowess has made headlines everywhere. I’ve put its capabilities to the test, particularly in PHP and WordPress, uncovering both the strengths and weaknesses of this AI coding assistant. But the burning question remains: how deep does ChatGPT's coding knowledge extend?
To investigate, I devised an experiment in early 2023 by employing the classic "Hello, world" programming challenge across the twelve most popular programming languages as ranked by O'Reilly Media. These languages range from very popular to still relevant in the tech landscape, providing a comprehensive cross-section that helps gauge ChatGPT's performance across different coding environments.
To add an interesting twist, I expanded the assignment. I asked ChatGPT to output "Hello, world!" ten times, incrementing a counter, while incorporating a greeting based on the time of day in Oregon. This entailed outputting "Good morning," "Good afternoon," or "Good evening," depending on the time.
Here's the exact prompt I used: "Write a program in ____ that outputs 'Good morning,' 'Good afternoon,' or 'Good evening' based on the current time in Oregon, followed by ten lines that each contain the loop index, a space, and 'Hello, world!'."
For each language, I also sought a brief description of its primary use. Here’s a look at how ChatGPT fared with the twelve languages:
1. Java
- **Description:** “A general-purpose language used primarily for building desktop, web, and mobile applications, known for its 'write once, run anywhere' philosophy.” Java, originally created by Sun Microsystems and now owned by Oracle, is renowned for its versatility and widespread use in enterprise applications.
2. Python
- **Description:** “A general-purpose language commonly used for data analysis, AI, web development, and automation, prized for its readability.” A must-know for any aspiring AI developer, Python’s extensive libraries make it a go-to for machine learning and data science.
3. Rust
- **Description:** “A systems programming language designed for building high-performance, reliable software, with a focus on memory and thread safety.” Rust’s popularity has surged, especially among developers seeking to create safe and concurrent code.
4. Go
- **Description:** “A systems programming language optimized for scalable, efficient network and server apps, noted for its simplicity and concurrency.” Originating from Google, Go is celebrated for its ease of use and efficient performance in microservices.
5. C++
- **Description:** “A systems programming language favored for creating operating systems, game engines, and high-performance apps due to its hardware control.” C++ is the backbone for many high-performance applications, maintaining its relevance in both system software and game development.
6. JavaScript
- **Description:** “A client-side scripting language essential for developing interactive web applications, known for its omnipresence in web development.” Alongside HTML and CSS, JavaScript is a fundamental technology on the web, driving dynamic content and user experiences.
7. C#
- **Description:** “A general-purpose language used for building Windows applications, games, and web services, recognized for its object-oriented features.” C# is pivotal in developing for the Microsoft ecosystem, especially in game development with Unity.
8. C
- **Description:** “A systems programming language used for operating systems, embedded systems, and performance-critical applications, lauded for its efficiency.” Known for its close relationship with hardware, C remains a popular choice for systems programming and embedded development.
9. TypeScript
- **Description:** “A superset of JavaScript utilized for large-scale web app development, noted for its optional static typing.” TypeScript has become essential for many JavaScript developers, offering an improved structure for large codebases.
10. R
- **Description:** “A language designed for statistical computing and data analysis, famous for its advanced data manipulation capabilities.” R remains the language of choice for statisticians and data miners, providing powerful statistical techniques and visualizations.
11. Kotlin
- **Description:** “A general-purpose language aimed at Android and server-side applications, recognized for its conciseness and Java interoperability.” Kotlin's modern features and null safety have led to its adoption as the preferred language for Android development.
12. Scala
- **Description:** “A language catering to scalable and distributed applications, known for its functional programming capabilities and Java Virtual Machine integration.” Scala's unique blend of object-oriented and functional programming paradigms has garnered attention, particularly for big data applications.
**Conclusion: A Fun Experiment with Limitations** This exploration has been enlightening. While I didn't test all the generated code for functionality—due to the sheer number—it certainly showcases ChatGPT’s ability to write coherent code snippets. Most of them appear to be well-formed, which is a testament to its proficiency. However, I urge developers to always test AI-generated code, as fitting it into real-world applications involves numerous considerations beyond syntax.
As tech continues to evolve, including the rise of AI in software engineering, it’s wise to approach tools like ChatGPT with a mix of curiosity and caution. Use it as an aid but always apply due diligence in verifying and testing the outcomes it produces.