I used ChatGPT to write the same routine in these ten obscure programming languages

I used ChatGPT to write the same routine in these ten obscure programming languages
gettyimages-171792113

An instructor at the Boston Latin School uses an IBM 1130 computer to teach Fortran to students on October 4, 1968. 

Photo by Underwood Archives/Getty Images

A few weeks ago, I took a look at using ChatGPT to write the same routine in a dozen of the most popular programming languages. But as a programming language geek, I wondered just how far ChatGPT would go. Would it program in a language from the 1950s? Would it program in a language that used its own character set? Could it write code in one of the languages that wrote its code?

Also: The best AI chatbots: ChatGPT and alternatives to try

And so, I dove in. I’ve used many of the languages I’m spotlighting here, so I’ll take a little walk down memory lane and include some stories about my experience with those I’ve used.

While I haven’t run the code itself, I’ve read through all the generated programs. Most look right, and show the appropriate indicators telling us that the language presented is the language I asked for.

Also: How does ChatGPT work?

I’m telling you this because the headers on all the screenshots are wrong. Most are listed as SQL. For some reason BAL is shown as VBNet, and Prolog is listed as Rust. ChatGPT didn’t make this error last time, but it made today, for all the languages shown here.

And with that, let’s dive in.

Fortran

Fortran (or FORTRAN, as it was depicted back then) stands for Formula Translation. It was developed primarily for scientific and engineering calculations. Even though it dates back to the 1950s, it was often the first language taught to engineering students in the 1970s and 1980s.

Also: This new technology could blow away GPT-4 and everything like it

For me, it was my fourth programming language, after BASIC, PDP-8 assembly language, and PDP-8 binary (yes, I wrote binary code so I could toggle it in on the front panel of an early minicomputer). My Dad generously drove me the hour down to Newark College of Engineering (now NJIT) so I could take their first-year programming course while I was still a sophomore in high school.

Fortran was never a favorite, although it would get most calculation-oriented jobs done. A variation of Fortran is still in use today, but it’s pretty limited to specialty scientific work since many other modern languages do Fortran-level analytics, and do it better.

Here, because of the use of the implicit keyword, it looks like ChatGPT is depicting code written in the Fortran-77 variant.

fortran-77

Even though the label is wrong, the code is Fortran.

Screenshot by David Gewirtz/ZDNET

COBOL

I was a teenaged COBOL programmer. I didn’t know COBOL at the time, but somewhere around 1980 I saw a want ad for a COBOL programmer at the Northeast Regional Data Center of International Paper in Denville, NJ. It was about 40 minutes from my parents’ home, and I needed a summer job. As soon as I managed to schedule

Read More

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

I used ChatGPT to write the same routine in 12 top programming languages. Here’s how it did
lang-1

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

Over the past few months, 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.

Also: Okay, so ChatGPT just debugged my code. For real.

But how far does ChatGPT’s coding knowledge extend? In this article, I’m going to throw the classic “Hello, world” programming assignment against the twelve popular languages in O’Reilly Media’s popularity rankings for 2023.

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

Also: How to use ChatGPT: What you need to know now

That should give us a look at program flow and some intrinsic functions as well, but still keep 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.

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: 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:

java

Screenshot by David Gewirtz/ZDNET

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 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:

python

Screenshot by David Gewirtz/ZDNET

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

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: How to make ChatGPT provide sources and citations

Go is open source, but it’s

Read More