A Coding Session with ChatGPT
Qusay Mahmoud
Professor & Associate Dean - Experiential Learning & Engineering Outreach at Ontario Tech University
If you haven't heard about OpenAI ChatGPT, check it out. It is a variant of GPT-3 (Generative Pre-trained Transformer 3) language model, specifically designed for generating human-like text in a conversation context. I have had a few conversations (in English and Arabic) and found it entertaining :-) but seriously it can produce some pretty useful content. In this article I will focus on a coding session on C/C++ preprocessor and macros.
Getting Started
I wanted to see how much does ChatGPT know about pre-processor macros, and specifically if it can detect the odd effect of text-replacement in the following macro, and what possible solutions it can offer.
#define sqr(x) x*x
My first question was to identify the problem with the above macro.
Brilliant! Not only it detected the odd behavior and offered a couple of possible solutions, but its responses as you can see in the rest of the article come with detailed explanations.
The use of parenthesis was not among the possible solutions provided, so I asked 'how to fix the macro':
And, I got a similar response when I asked it to optimize the macro.
I then asked if it knows of other solutions - how else to fix the macro? It provided a different reasonable answer every time I asked it this question.
Conversation Context
I wanted to check if it remembers the name of the macro we have been discussing, so during the same session I asked the very first question but I misspelled the macro name:
领英推荐
Very cool!
Missing Details
In a new chat session, I asked it the very first question again. Here is a response that was not as accurate (missing *) as my first experiment, but I believe a programmer would be able to interpret the response correctly.
Since the response was missing some details, I asked for an example?
I then asked about using an inline function in C:
Do you want more details? Ask it to elaborate on the response. :-)
Conclusion
The speed at which ChatGPT is able to generate code when I asked for an example is very impressive! Can't wait to see what students are able to produce with it, but can it replace a programmer?
Its response sums it up perfectly. We can teach a machine do whatever we want, but creative problem solving and thinking are human activities.
Associate Professor at Zayed University
1 年Thanks for the info!
Associate Professor at Zayed University
1 年Thanks, Dr. Qusay, It May be great if the ChatGPT is used as a learning tool rather than a tool to replace the professor??
Radar Electronic Warfare Lead/Engineer | Antenna and RF Systems | Electromagnetic Spectrum Operations
1 年How do you think this will impact students from an ethics perspective? Will they be able to resist the temptation to use services such as this? How will this impact how universities and their ability to grade the performance of students?