I used ChatGPT to write the same routine in 12 top programming languages. Here's how it did

We Keep you Connected

I used ChatGPT to write the same routine in 12 top programming languages. Here's how it did

Most Popular
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 both the strengths and weaknesses of ChatGPT's coding capabilities.
But how far does ChatGPT's coding knowledge extend? For this article, I threw the classic "Hello, world" programming assignment against the twelve most popular languages in O'Reilly Media's popularity rankings for 2023.
Also: How LinkedIn's free AI course made me a better Python developer
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."
This gives give 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.
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: The best AI art generators to try
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:
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 to write better ChatGPT prompts
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:
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:
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: How to make ChatGPT provide sources and citations
Go is open source, but it's managed by Google. Go. Google. Get it?
Here's ChatGPT's code:
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:
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: Future ChatGPT versions could replace a majority of work people do today
Also, along with CSS (one of the web's main visual design languages), JavaScript is directly responsible for 87.45% of the profanity I've uttered over the past nine or so years.
Here's ChatGPT's code:
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:
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 to use ChatGPT to write Excel formulas
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:
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 write code
TypeScript is also a Microsoft product, but unlike C#, it's open-source and non-proprietary.
Here's ChatGPT's code:
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:
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: I spent a weekend with Amazon's free AI courses, and highly recommend you do too
Kotlin was developed by JetBrains, a small company that also makes PhpStorm, my current favorite development environment.
Here's ChatGPT's code:
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:
Also, notice the output for Scala (shown above). I've never programmed in Scala and don't know very much about it. Apparently neither does ChatGPT, because while the AI provided syntax coloring for all the other languages, it didn't seem to have that information on hand for Scala.
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: How to use Copilot Pro AI to generate formulas and analyze data in Excel
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 both generated Forth (the colons are 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.
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.

source

GET THE LATEST UPDATES, OFFERS, INFORMATION & MORE