I used ChatGPT to put in writing the identical routine in 12 prime programming languages. This is the way it did

Over the previous 12 months, we have all come to know that ChatGPT can write code. I gave it quite a lot of checks in PHP and WordPress that confirmed each the strengths and weaknesses of ChatGPT’s coding capabilities.

However how far does ChatGPT’s coding data prolong? For this text, I threw the traditional “Whats up, world” programming project in opposition to the twelve hottest languages in O’Reilly Media’s reputation rankings for 2023.

Additionally: How LinkedIn’s free AI course made me a greater Python developer

As a result of “Whats up, world” can typically be coded in a single line, I added a slight wrinkle, having ChatGPT current “Whats up, world” ten occasions, every time incrementing a counter worth. I additionally requested it to examine the time and start every sequence with “Good morning,” “Good afternoon,” or “Good night.”

This provides give us a take a look at program stream and a few intrinsic capabilities as nicely, however nonetheless retains the code sufficiently small that I can embody a dozen screenshots on this article.

This is the immediate:

Write a program in ____ that outputs “Good morning,” “Good afternoon,” or “Good night” based mostly on what time it’s right here in Oregon, after which outputs ten strains containing the loop index (starting with 1), an area, after which the phrases “Whats up, world!”.

For every programming language, I additionally requested ChatGPT to explain its major use. This is the immediate I used for this question:

For every of the next languages, write a one-sentence description of its major use and differentiating issue: Java, Python, Rust, Go, C++, JavaScript, C#, C, TypeScript, R, Kotlin, Scala.

Now, let us take a look at every language.

1. Java

ChatGPT describes Java as, “A general-purpose language used primarily for constructing desktop, net, and cell functions, and identified for its ‘write as soon as, run wherever’ philosophy.”

Additionally: The perfect AI artwork mills to attempt

Java was initially developed by Solar Microsystems, however when Oracle purchased Solar, it additionally purchased Java. Whereas the Java spec is open, the language is owned by Oracle. This has led to some spectacular authorized fireworks over time.

This is ChatGPT’s code:

java
Screenshot by David Gewirtz/ZDNET

2. Python

ChatGPT describes Python as, “A general-purpose language used for information evaluation, synthetic intelligence, net improvement, and automation, and identified for its readability and ease of use.”

Additionally: The best way to write higher ChatGPT prompts

My recommendation: if you happen to plan to study to code for AI functions, study Python. Nearly all AI code has tight Python integration.

This is ChatGPT’s code:

python
Screenshot by David Gewirtz/ZDNET

3. Rust

ChatGPT describes Rust as, “A programs programming language used for constructing high-performance and dependable software program, and identified for its reminiscence security and thread security ensures.”

This is ChatGPT’s code:

rust
Screenshot by David Gewirtz/ZDNET

4. Go

ChatGPT describes Go as, “A programs programming language used for constructing scalable and environment friendly community and server functions, and identified for its simplicity and built-in concurrency options.”

Additionally: The best way to make ChatGPT present sources and citations

Go is open supply, however it’s managed by Google. Go. Google. Get it?

This is ChatGPT’s code:

go
Screenshot by David Gewirtz/ZDNET

5. C++

ChatGPT describes C++ as, “A programs programming language used for constructing working programs, sport engines, and high-performance functions, and identified for its management over {hardware} and reminiscence.”

This is ChatGPT’s code:

cpp
Screenshot by David Gewirtz/ZDNET

6. JavaScript

ChatGPT describes JavaScript as, “A client-side scripting language used for constructing interactive net functions, and identified for its widespread use in net improvement and its capacity to run in net browsers.”

Additionally: Future ChatGPT variations might substitute a majority of labor individuals do at this time

Additionally, together with CSS (one of many net’s major visible design languages), JavaScript is instantly liable for 87.45% of the profanity I’ve uttered over the previous 9 or so years.

This is ChatGPT’s code:

javascript
Screenshot by David Gewirtz/ZDNET

7. C#

ChatGPT describes C# as, “A general-purpose language used for constructing Home windows desktop functions, video games, and net functions, and identified for its object-oriented options and integration with the .NET framework.”

Additionally: Have 10 hours? IBM will practice you in AI fundamentals – at no cost

C# is a proprietary language supplied by Microsoft. I taught it on the UC Berkeley extension for greater than a decade. It’s a very attention-grabbing gateway language for anybody desirous to get work programming for predominantly Microsoft environments.

This is ChatGPT’s code:

csharp
Screenshot by David Gewirtz/ZDNET

8. C

ChatGPT describes C as, “A programs programming language used for constructing working programs, embedded programs, and high-performance functions, and identified for its effectivity and low-level management.”

Additionally: The best way to use ChatGPT to put in writing Excel formulation

They are saying you always remember your past love. Earlier than educating myself to program C again within the days of picket ships and iron programmers, I by no means really beloved a programming language. However then I began to make use of C and my world modified. It was love. One thing concerning the concise simplicity of the language simply spoke to me on a deep and primal degree. That is most likely an overshare, however it’s additionally true. C will all the time be my first syntactic love.

This is ChatGPT’s code:

c
Screenshot by David Gewirtz/ZDNET

9. TypeScript

ChatGPT describes TypeScript as, “A superset of JavaScript used for constructing large-scale net functions, and identified for its elective static typing and superior language options.”

Additionally: The best way to use ChatGPT to put in writing code

TypeScript can also be a Microsoft product, however in contrast to C#, it is open-source and non-proprietary.

This is ChatGPT’s code:

typescript
Screenshot by David Gewirtz/ZDNET

10. R

ChatGPT describes R as, “A language used for statistical computing and information evaluation, and identified for its highly effective information manipulation and visualization capabilities.”

This is ChatGPT’s code:

r
Screenshot by David Gewirtz/ZDNET

11. Kotlin

ChatGPT describes Kotlin as, “A general-purpose language used for constructing Android apps, server-side functions, and net functions, and identified for its conciseness and interoperability with Java.”

Additionally: I spent a weekend with Amazon’s free AI programs, and extremely advocate you do too

Kotlin was developed by JetBrains, a small firm that additionally makes PhpStorm, my present favourite improvement setting.

This is ChatGPT’s code:

kotlin
Screenshot by David Gewirtz/ZDNET

12. Scala

ChatGPT describes Scala as, “A language used for constructing scalable and distributed functions, and identified for its assist for practical programming and its integration with the Java Digital Machine.”

This is ChatGPT’s code:

scala
Screenshot by David Gewirtz/ZDNET

Additionally, discover the output for Scala (proven above). I’ve by no means programmed in Scala and do not know very a lot about it. Apparently neither does ChatGPT, as a result of whereas the AI offered syntax coloring for all the opposite languages, it did not appear to have that info available for Scala.

Closing ideas (and somewhat Forth)

As a pc languages geek, I discovered this train tremendous enjoyable. That mentioned, there are some issues to remember. First, I did not take a look at all of the code. Testing this many outputs is exterior the scope of this text. That mentioned, I did learn via the generated code and — for many languages — the code seemed good.

Additionally: The best way to use Copilot Professional AI to generate formulation and analyze information in Excel

Once I final ran these checks, nearly a 12 months in the past, ChatGPT obtained nearly every little thing proper (however the above disclaimer). Nevertheless, when requested to render code in Forth (a really funky, however enjoyable language), it generated code that seemed like Forth however labeled the window “Perl.” It undoubtedly did not generate Perl.

Nevertheless, this time, it each generated Forth (the colons are lifeless giveaway) and labeled it appropriately. Like Scala above, ChatGPT did not appear to have the syntax coloring tables for Forth, however in any other case it appears to be doing wonderful.

forth
Screenshot by David Gewirtz/ZDNET

As with all my different visits down the rabbit gap with ChatGPT and coding, I am impressed, but additionally cautious. My suggestions stand: use it as a device, however take a look at, take a look at, and take a look at.


You possibly can observe my day-to-day mission updates on social media. Be sure you observe me on Twitter at @DavidGewirtz, on Fb at Fb.com/DavidGewirtz, on Instagram at Instagram.com/DavidGewirtz, and on YouTube at YouTube.com/DavidGewirtzTV.

Leave a Reply

Your email address will not be published. Required fields are marked *