Over the previous 12 months, we have all come to know that ChatGPT can write code. I gave it a variety of checks in PHP and WordPress that confirmed the strengths and weaknesses of ChatGPT’s coding capabilities.
However how far does ChatGPT’s coding information prolong? After I initially drafted this text in early 2023, I threw the traditional “Whats up, world” programming project towards the 12 hottest languages in O’Reilly Media’s reputation rankings for 2023.
We have subsequently finished lots of evaluation about programming language reputation, however even with this late 2024 replace, I am sticking with the unique 12 languages we examined. Whereas a few of our 12 aren’t actually massively common languages, they’re nonetheless present and in use. This choice offers us an excellent cross-section to higher assist us perceive how nicely ChatGPT handles a variety of languages.
As a result of “Whats up, world” can usually be coded in a single line, I added a slight wrinkle, having ChatGPT current “Whats up, world” ten instances, every time incrementing a counter worth. I additionally requested it to verify the time and start every sequence with “Good morning,” “Good afternoon,” or “Good night.”
This provides us a have a look at program stream and a few intrinsic features as nicely, however nonetheless retains the code sufficiently small that I can embrace 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 main use. This is the immediate I used for this question:
For every of the next languages, write a one-sentence description of its main 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 cellular purposes, and identified for its ‘write as soon as, run anyplace’ philosophy.”
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:
2. Python
ChatGPT describes Python as,” A general-purpose language used for knowledge evaluation, synthetic intelligence, net growth, and automation, and identified for its readability and ease of use.”
My recommendation: if you happen to plan to study to code for AI purposes, study Python. Nearly all AI code has tight Python integration.
This is ChatGPT’s code:
3. Rust
ChatGPT describes Rust as, “A methods 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:
4. Go
ChatGPT describes Go as, “A methods programming language used for constructing scalable and environment friendly community and server purposes, and identified for its simplicity and built-in concurrency options.”
Go is open supply, nevertheless it’s managed by Google. Go. Google. Get it?
This is ChatGPT’s code:
5. C++
ChatGPT describes C++ as, “A methods programming language used for constructing working methods, recreation engines, and high-performance purposes, and identified for its management over {hardware} and reminiscence.”
This is ChatGPT’s code:
6. JavaScript
ChatGPT describes JavaScript as, “A client-side scripting language used for constructing interactive net purposes, and identified for its widespread use in net growth and its potential to run in net browsers.”
Additionally, together with CSS (one of many net’s important visible design languages), JavaScript is answerable for 87.45% of the profanity I’ve uttered over the previous 9, or so, years.
This is ChatGPT’s code:
7. C#
ChatGPT describes C# as, “A general-purpose language used for constructing Home windows desktop purposes, video games, and net purposes, and identified for its object-oriented options and integration with the .NET framework.”
C# is a proprietary language provided 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:
8. C
ChatGPT describes C as, “A methods programming language used for constructing working methods, embedded methods, and high-performance purposes, and identified for its effectivity and low-level management.”
They are saying you always remember your old flame. Earlier than educating myself to program C again within the days of picket 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 degree. That is most likely an overshare, nevertheless it’s additionally true. C will at all times be my first syntactic love.
This is ChatGPT’s code:
9. TypeScript
ChatGPT describes TypeScript as, “A superset of JavaScript used for constructing large-scale net purposes, and identified for its non-compulsory static typing and superior language options.”
TypeScript can be a Microsoft product, however not like C#, it is open-source and non-proprietary.
This is ChatGPT’s code:
10. 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:
11. Kotlin
ChatGPT describes Kotlin as, “A general-purpose language used for constructing Android apps, server-side purposes, and net purposes, and identified for its conciseness and interoperability with Java.”
Kotlin was developed by JetBrains, a small firm that additionally makes PhpStorm, my present favourite growth setting.
This is ChatGPT’s code:
12. Scala
ChatGPT describes Scala as, “A language used for constructing scalable and distributed purposes, and identified for its assist for practical programming and its integration with the Java Digital Machine.”
This is ChatGPT’s code:
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. 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 for Scala.
Closing ideas (and a bit of Forth)
As a pc languages geek, I discovered this train tremendous enjoyable. That stated, there are some issues to remember. First, I did not take a look at all of the code. Testing this many outputs is outdoors the scope of this text. That stated, I did learn by means of the generated code and, for many languages, the code appeared good.
After I final ran these checks virtually a 12 months in the past, ChatGPT obtained virtually the whole lot proper (however the above disclaimer). Nevertheless, when requested to render code in Forth (a really funky however enjoyable language), it generated code that appeared like Forth however labeled the window “Perl.” It positively did not generate Perl.
Nevertheless, this time, it generated Forth (the colons are a 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 nice.
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 challenge updates on social media. You’ll want to 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.