I used ChatGPT to write the same routine in 12 top programming languages. Here’s how it did
David Gewirtz/ZDNET (with a bit assist from ChatGPT) Over the previous few months, we have all come to know that ChatGPT can write code. I gave it quite a few assessments in PHP and WordPress that confirmed each the strengths and weaknesses of ChatGPT’s coding capabilities. Additionally: Okay, so ChatGPT simply debugged my code. For … The post I used ChatGPT to write the same routine in 12 top programming languages. Here’s how it did appeared first on Ferdja.


Over the previous few months, we have all come to know that ChatGPT can write code. I gave it quite a few assessments in PHP and WordPress that confirmed each the strengths and weaknesses of ChatGPT’s coding capabilities.
Additionally: Okay, so ChatGPT simply debugged my code. For actual.
However how far does ChatGPT’s coding information lengthen? On this article, I’ll throw the basic “Howdy, world” programming task in opposition to the twelve common languages in O’Reilly Media’s recognition rankings for 2023.
As a result of “Howdy, world” can usually be coded in a single line, I am including a slight wrinkle, having ChatGPT current “Howdy, world” ten occasions, every time incrementing a counter worth. I am additionally asking it to test the time and start every sequence with “Good morning,” “Good afternoon,” or “Good night.”
Additionally: Easy methods to use ChatGPT: What you might want to know now
That ought to give us a take a look at program circulation and a few intrinsic capabilities as effectively, however nonetheless preserve 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 traces containing the loop index (starting with 1), an area, after which the phrases “Howdy, 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.
Java
ChatGPT describes Java as, “A general-purpose language used primarily for constructing desktop, internet, and cell functions, and identified for its ‘write as soon as, run anyplace’ 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 through the years.
This is ChatGPT’s code:
Python
ChatGPT describes Python as, “A general-purpose language used for knowledge evaluation, synthetic intelligence, internet improvement, and automation, and identified for its readability and ease of use.”
Additionally: Easy methods to write higher ChatGPT prompts
My recommendation: when you plan to study to code for AI functions, study Python. Nearly all AI code has tight Python integration.
This is ChatGPT’s code:
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:
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: Easy methods to make ChatGPT present sources and citations
Go is open supply, but it surely’s managed by Google. Go. Google. Get it?
This is ChatGPT’s code:
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:
JavaScript
ChatGPT describes JavaScript as, “A client-side scripting language used for constructing interactive internet functions, and identified for its widespread use in internet improvement and its potential to run in internet browsers.”
Additionally: Future ChatGPT variations may change a majority of labor folks do right now
Additionally, together with CSS (one of many internet’s principal visible design languages), JavaScript is immediately answerable for 87.45% of the profanity I’ve uttered over the previous 9 or so years.
This is ChatGPT’s code:
C#
ChatGPT describes C# as, “A general-purpose language used for constructing Home windows desktop functions, video games, and internet functions, and identified for its object-oriented options and integration with the .NET framework.”
Additionally: Easy methods to use ChatGPT to construct your resume
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 fascinating gateway language for anybody desirous to get work programming for predominantly-Microsoft environments.
This is ChatGPT’s code:
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: Easy methods to use ChatGPT to write down Excel formulation
They are saying you always remember your past love. Earlier than educating myself to program C again within the days of wood ships and iron programmers, I by no means actually liked 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 stage. That is most likely an overshare, but it surely’s additionally true. C will all the time be my first syntactic love.
This is ChatGPT’s code:
TypeScript
ChatGPT describes TypeScript as, “A superset of JavaScript used for constructing large-scale internet functions, and identified for its elective static typing and superior language options.”
Additionally: Easy methods to use ChatGPT to write down code
TypeScript can also be a Microsoft product, however in contrast to C#, it is open supply and non-proprietary.
This is ChatGPT’s code:
R
ChatGPT describes R as, “A language used for statistical computing and knowledge evaluation, and identified for its highly effective knowledge manipulation and visualization capabilities.”
This is ChatGPT’s code:
Kotlin
ChatGPT describes Kotlin as, “A general-purpose language used for constructing Android apps, server-side functions, and internet functions, and identified for its conciseness and interoperability with Java.”
Additionally: What’s Auto-GPT? Every thing to know concerning the subsequent highly effective AI instrument
Kotlin was developed by JetBrains, a small firm who additionally makes PhpStorm, my present favourite improvement atmosphere.
This is ChatGPT’s code:
Scala
ChatGPT describes Scala as, “A language used for constructing scalable and distributed functions, and identified for its assist for useful programming and its integration with the Java Digital Machine.”
This is ChatGPT’s code:
Ultimate ideas
As a pc languages geek, I discovered this train tremendous enjoyable. That mentioned, there are some issues to bear in mind. First, I did not check all of the code. Testing this many outputs is exterior the scope of this text. That mentioned, I did learn by means of the generated code and — for many languages — the code regarded good.
Additionally: AI may automate 25% of all jobs. This is that are most (and least) in danger
However, ChatGPT does generally lose the thread. Out of curiosity, I made a decision to ask it to generate the identical code in Forth (a really funky, however enjoyable language). Whereas the code generated was Forth (the colons initially are a lifeless giveaway), the code block was labeled “perl” (one other very enjoyable and funky language). This code is certainly not Perl:
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 supplied syntax coloring for all the opposite languages, it did not appear to have that data readily available for Scala.
As with all my different visits down the rabbit gap with ChatGPT and coding, I come away impressed, but in addition cautious. My suggestions stand: use it as a instrument, however check, check, and check.
You’ll be able to observe my day-to-day undertaking updates on social media. Make sure you observe me on Twitter at @DavidGewirtz, on Fb at Facebook.com/DavidGewirtz, on Instagram at Instagram.com/DavidGewirtz, and on YouTube at YouTube.com/DavidGewirtzTV.
The post I used ChatGPT to write the same routine in 12 top programming languages. Here’s how it did appeared first on Ferdja.