December 6, 2024

Idon Rpg

Smart Solutions, Bright Future

ChatGPT writes my routine in 12 top programming languages. Here’s what the results tell me

ChatGPT writes my routine in 12 top programming languages. Here’s what the results tell me
lang-1-2024.jpg

David Gewirtz/ZDNET (with a little help from ChatGPT)

Over the past year, we’ve all come to know that ChatGPT can write code. I gave it a number of tests in PHP and WordPress that showed the strengths and weaknesses of ChatGPT’s coding capabilities.

Also: Your dream programming job demands this language, every site agrees

But how far does ChatGPT’s coding knowledge extend? When I originally drafted this article in early 2023, I threw the classic “Hello, world” programming assignment against the 12 most popular languages in O’Reilly Media’s popularity rankings for 2023. 

We’ve subsequently done a lot of analysis about programming language popularity, but even with this late 2024 update, I’m sticking with the original 12 languages we tested. While some of our 12 aren’t really massively popular languages, they’re still current and in use. This selection gives us a very good cross-section to better help us understand how well ChatGPT handles a wide range of languages.

Because “Hello, world” can often be coded in one line, I added a slight wrinkle, having ChatGPT present “Hello, world” ten times, each time incrementing a counter value. I also asked it to check the time and begin each sequence with “Good morning,” “Good afternoon,” or “Good evening.”

Also: The best AI for coding in 2024 (and what not to use)

This gives us a look at program flow and some intrinsic functions as well, but still keeps the code small enough that I can include a dozen screenshots in this article.

Here’s the prompt:

Write a program in ____ that outputs “Good morning,” “Good afternoon,” or “Good evening” based on what time it is here in Oregon, and then outputs ten lines containing the loop index (beginning with 1), a space, and then the words “Hello, world!”.

For each programming language, I also asked ChatGPT to describe its primary use. Here’s the prompt I used for this query:

For each of the following languages, write a one-sentence description of its primary use and differentiating factor: Java, Python, Rust, Go, C++, JavaScript, C#, C, TypeScript, R, Kotlin, Scala.

Now, let’s look at each language.

1. Java

ChatGPT describes Java as, “A general-purpose language used primarily for building desktop, web, and mobile applications, and known for its ‘write once, run anywhere’ philosophy.”

Also: Google’s Gems are a gentle introduction to AI prompt engineering

Java was originally developed by Sun Microsystems, but when Oracle bought Sun, it also bought Java. While the Java spec is open, the language is owned by Oracle. This has led to some spectacular legal fireworks over the years.

Here’s ChatGPT’s code:

java

Screenshot by David Gewirtz/ZDNET

2. Python

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

Also: How LinkedIn’s free AI course made me a better Python developer

My advice: if you plan to learn to code for AI applications, learn Python. Almost all AI code has tight Python integration.

Here’s ChatGPT’s code:

python

Screenshot by David Gewirtz/ZDNET

3. Rust

ChatGPT describes Rust as, “A systems programming language used for building high-performance and reliable software, and known for its memory safety and thread safety guarantees.”

Here’s ChatGPT’s code:

rust

Screenshot by David Gewirtz/ZDNET

4. Go

ChatGPT describes Go as, “A systems programming language used for building scalable and efficient network and server applications, and known for its simplicity and built-in concurrency features.”

Also: Will AI take programming jobs or turn programmers into AI managers?

Go is open source, but it’s managed by Google. Go. Google. Get it?

Here’s ChatGPT’s code:

go

Screenshot by David Gewirtz/ZDNET

5. C++

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

Here’s ChatGPT’s code:

cpp

Screenshot by David Gewirtz/ZDNET

6. JavaScript

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

Also: The 4 biggest challenges of AI-generated code that Gartner left out of its latest report

Also, along with CSS (one of the web’s main visual design languages), JavaScript is responsible for 87.45% of the profanity I’ve uttered over the past nine, or so, years.

Here’s ChatGPT’s code:

javascript

Screenshot by David Gewirtz/ZDNET

7. C#

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

Also: Have 10 hours? IBM will train you in AI fundamentals – for free

C# is a proprietary language offered by Microsoft. I taught it at the UC Berkeley extension for more than a decade. It is a very interesting gateway language for anyone wanting to get work programming for predominantly Microsoft environments.

Here’s ChatGPT’s code:

csharp

Screenshot by David Gewirtz/ZDNET

8. C

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

Also: How I test an AI chatbot’s coding ability – and you can, too

They say you never forget your first love. Before teaching myself to program C back in the days of wooden ships and iron programmers, I never truly loved a programming language. But then I started to use C and my world changed. It was love. Something about the concise simplicity of the language just spoke to me on a deep and primal level. That’s probably an overshare, but it’s also true. C will always be my first syntactic love.

Here’s ChatGPT’s code:

c

Screenshot by David Gewirtz/ZDNET

9. TypeScript

ChatGPT describes TypeScript as, “A superset of JavaScript used for building large-scale web applications, and known for its optional static typing and advanced language features.”

Also: How to use ChatGPT to create an app

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

Here’s ChatGPT’s code:

typescript

Screenshot by David Gewirtz/ZDNET

10. R

ChatGPT describes R as, “A language used for statistical computing and data analysis, and known for its powerful data manipulation and visualization capabilities.”

Here’s ChatGPT’s code:

r

Screenshot by David Gewirtz/ZDNET

11. Kotlin

ChatGPT describes Kotlin as, “A general-purpose language used for building Android apps, server-side applications, and web applications, and known for its conciseness and interoperability with Java.”

Also: Google’s new AI course will teach you to write more effective prompts – in 5 steps

Kotlin was developed by JetBrains, a small company that also makes PhpStorm, my current favorite development environment.

Here’s ChatGPT’s code:

kotlin

Screenshot by David Gewirtz/ZDNET

12. Scala

ChatGPT describes Scala as, “A language used for building scalable and distributed applications, and known for its support for functional programming and its integration with the Java Virtual Machine.”

Here’s ChatGPT’s code:

scala

Screenshot by David Gewirtz/ZDNET

Also, notice the output for Scala (shown above). I’ve never programmed in Scala and don’t know very much about it. Neither does ChatGPT, because while the AI provided syntax coloring for all the other languages, it didn’t seem to have that information for Scala.

Final thoughts (and a little Forth)

As a computer languages geek, I found this exercise super fun. That said, there are some things to keep in mind. First, I didn’t test all the code. Testing this many outputs is outside the scope of this article. That said, I did read through the generated code and, for most languages, the code looked good.

Also: Is AI in software engineering reaching an ‘Oppenheimer moment’? Here’s what you need to know

When I last ran these tests almost a year ago, ChatGPT got almost everything right (notwithstanding the above disclaimer). However, when asked to render code in Forth (a very funky but fun language), it generated code that looked like Forth but labeled the window “Perl.” It definitely did not generate Perl.

However, this time, it generated Forth (the colons are a dead giveaway) and labeled it appropriately. Like Scala above, ChatGPT didn’t seem to have the syntax coloring tables for Forth, but otherwise, it seems to be doing fine.

forth

Screenshot by David Gewirtz/ZDNET

As with all my other visits down the rabbit hole with ChatGPT and coding, I’m impressed but also wary. My recommendations stand: use it as a tool, but test, test, and test.


You can follow my day-to-day project updates on social media. Be sure to follow me on Twitter at @DavidGewirtz, on Facebook at Facebook.com/DavidGewirtz, on Instagram at Instagram.com/DavidGewirtz, and on YouTube at YouTube.com/DavidGewirtzTV.


link

Copyright © All rights reserved. | Newsphere by AF themes.