Get 12 programming languages with ChatGPT: see how it performs

We all know that ChatGPT can write code, but how does it perform when a bunch of languages ​​are thrown at it together? The answer is: not bad (but not perfect).

Over the past few months, we have experienced the coding capabilities of ChatGPT. I tested it with PHP and WordPress, and the results also reflected the advantages and disadvantages of ChatGPT programming.

1. How strong is the programming knowledge of ChatGPT?

In this article, we'll take a "Hello, world" programming test for 12 of the most popular languages ​​in O'Reilly Media's 2023 popularity rankings.

A few tweaks were made to the "Hello, world" encoding in the test, adding some variation: Have ChatGPT output "Hello, world" ten times, incrementing a counter value each time. I'm also asking it to check the time and output "good morning", "good afternoon" or "good evening" at the start of each sequence.

With such an adjustment, we can understand the program flow and function calls while ensuring that the amount of code is not large. For each programming language, I will screenshot the code output of ChatGPT.

Here are the ChatGPT tips I use:

Write a program in ____ that outputs "good morning", "good afternoon", or "good evening" according to the time in Oregon, then outputs ten lines containing the loop index (starting at 1), a space, and then the words "Hello, world!"

At the same time, for each programming language, I also asked ChatGPT to describe its main usage. Here's the hint I'm using for this query:

For each of the following languages, write a short description illustrating its main purpose and distinguishing factors: Java, Python, Rust, Go, C++, JavaScript, C#, C, TypeScript, R, Kotlin, Scala.

Now, let's take a look at ChatGPT's ability to control different programming languages.

1.Java

ChatGPT describes Java as "a general-purpose language primarily used for building desktop, web, and mobile applications, and known for its "write once, run anywhere" philosophy."

Java was originally developed by Sun Microsystems, but when Oracle acquired Sun, it also acquired Java. Although the Java specification is open, the language is owned by Oracle. This has led to some staggering legal battles over the years.

The following is the code of ChatGPT:

2.Python

ChatGPT describes Python as "a general-purpose language for data analysis, artificial intelligence, web development, and automation, known for its readability and ease of use."

My advice: If you plan on learning to code AI applications, learn Python. Almost all AI code is tightly integrated with Python.

The following is the code of ChatGPT:

3.Rust

ChatGPT describes Rust as: "A systems programming language for building high-performance and reliable software, notable for its memory-safety and thread-safety guarantees."

Here is the Rust code generated by ChatGPT:

4.Go

ChatGPT describes Go as "a systems programming language for building scalable and efficient network and server applications, known for its simplicity and built-in concurrency capabilities."

Go is open source but managed by Google.

The following is the code of ChatGPT:

5.C++

ChatGPT describes C++ as "a systems programming language for building operating systems, game engines, and high-performance applications, known for its control over hardware and memory."

The following is the C++ code generated by ChatGPT:

6.JavaScript

ChatGPT describes JavaScript as "a client-side scripting language for building interactive web applications, known for its widespread use in web development and its ability to run in web browsers."

The following is the code of ChatGPT:

7.C#

ChatGPT describes C# as "a general-purpose language for building Windows desktop applications, games, and web applications, known for its object-oriented features and integration with the .NET framework."

Meanwhile, C# is a proprietary language provided by Microsoft. I have taught C# for over a decade in the UC Berkeley Extension Program. It's a very interesting gateway language for someone who wants to work programming in a primarily Microsoft-oriented environment.

Here is the code for ChatGPT:

8.C

ChatGPT describes C as "a systems programming language for building operating systems, embedded systems, and high-performance applications, known for its efficiency and low-level control."

They say you never forget your first love. In the days of wooden ships and iron programmers, I taught myself to program in C, and I've really fallen in love with a programming language ever since. But when I started using C and my world changed, it was my love. The language, concise and simple, spoke to me on a deep and raw level. This may be oversharing, but it's true. C will always be my first syntax love.

Here is the code for ChatGPT:

9.TypeScript

ChatGPT describes TypeScript as "a superset of JavaScript for building large-scale web applications and known for its optional static typing and advanced language features."

TypeScript is also a Microsoft product, but unlike C#, it's open source and non-proprietary.

The code of ChatGPT is as follows:

10.R

ChatGPT describes R as "a language for statistical computing and data analysis, known for its powerful data manipulation and visualization capabilities."

The following is the code of ChatGPT:

11.Kotlin

ChatGPT describes Kotlin as "a general-purpose language for building Android applications, server-side applications, and web applications, known for its simplicity and interoperability with Java."

Kotlin is developed by JetBrains, a small company and developer of my current favorite development environment, PhpStorm.

The code of ChatGPT is as follows:

12.Scala

ChatGPT describes Scala as "a language for building scalable and distributed applications, as well as known for its support for functional programming and integration with the Java Virtual Machine."

The following is the code of ChatGPT:

2. Final Thoughts

As a computer language enthusiast, I find this exercise very interesting. However, it needs to be stated. First, I didn't test all the code. Testing this much output is beyond the scope of this article. I did browse the generated code though, and for most languages ​​the code looks fine.

Original link: https://www.zdnet.com/article/i-used-chatgpt-to-write-the-same-routine-in-12-top-programming-languages-heres-how-it-did/

Guess you like

Origin blog.csdn.net/wangonik_l/article/details/131707759