A Coding Session with ChatGPT

A Coding Session with ChatGPT

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.

No alt text provided for this image

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.

No alt text provided for this image

The use of parenthesis was not among the possible solutions provided, so I asked 'how to fix the macro':

No alt text provided for this image

And, I got a similar response when I asked it to optimize the macro.

No alt text provided for this image

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.

No alt text provided for this image

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:

No alt text provided for this image

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.

No alt text provided for this image

Since the response was missing some details, I asked for an example?

No alt text provided for this image

I then asked about using an inline function in C:

No alt text provided for this image

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?

No alt text provided for this image

Its response sums it up perfectly. We can teach a machine do whatever we want, but creative problem solving and thinking are human activities.

#chatgpt #creativity #coding #writing #thinking

Huwida Said (PhD, FHEA)

Associate Professor at Zayed University

1 年

Thanks for the info!

Huwida Said (PhD, FHEA)

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

Jonathan Anderson

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?

回复

要查看或添加评论,请登录

Qusay Mahmoud的更多文章

社区洞察

其他会员也浏览了