Hacker News new | ask | show | jobs
by ikealampe200 1276 days ago
Just today I used ChatGPT to help me speed up writing somewhat trivial C Code for a project in an embedded systems class.

Prompt: "Generate a tiny PID controller with only a Proportional factor written in C. That takes a rotational input from -360 to 360 degrees. The setpoint in degrees. And returns a motor speed in the range of -255 to 255."

=> Produced a compiling correct result.

Later I wanted to know how to communicate between my kernel module and user space program: Prompt: "How do I get a value via character device from my kernel module into my user space c programm?" gave a bunch of answers and digging deeper with Prompt: "Could you provide me with an example of the user space program" gave a compiling and correct answer again.

I could have written all of that myself while spending a good amount researching on google. But this way I felt less frustrated and was definitively a lot quicker.

Not the solution for everything but maybe for a C beginner where research can take a long time and often leads to more confusion than anything else. Now the question is if that confusion is critical in the learning process. And if so how critical and at what stages of the experience spectrum the most?

2 comments

I guess the main concern with its use as a learning tool is what happens if it's wrong? It might be helpful for boilerplate when you already know what you want, but if you don't even know that it'll blow up in your face when it doesn't give you something workable.

Still, seems like a viable assistant so long as you have an understanding of what you're working with.

It's basically an augmenting tool. Can't rely on it 100% without a check, can't just do it without a vague idea of what the code does. As a combined boilerplate + search assistant it takes crazy amounts of work away as long as your specs are well defined, though.
It is almost the same as stackoverflow. I've seen many answers which is runnable but without proper error handling or security mitigations. They are just as misleading as ChatGPT.
Umm, no. I haven't seen answers there where people just invent non-existing options like ChatGPT does.
It basically gives you suggestions of what could be correct, or close to correct, but yes you have to verify yourself, and possibly make some adjustments.
And honestly that's already amazingly valuable and I've been using it constantly for weeks because it narrows your search space through the documentation to the head of a pin.

Hey I need to process the EXIF data for an image; let's Google "pillow exif" and see what we get.

https://pillow.readthedocs.io/en/stable/reference/ExifTags.h...

Uhh, okay. Kinda? Maybe? This doesn't actually tell me how to actually get that data from a real image.

> Write a python program using pillow to print all the EXIF data for an image in a human readable way

    from PIL import Image
    from PIL.ExifTags import TAGS 

    # Create an Image object 
    img = Image.open('image.jpg') 

    # Get EXIF data
    exif_data = img._getexif() 
 
    # Iterate over all EXIF data fields
    for tag_id in exif_data: 
 
        # Get the tag name, instead of human unreadable tag id
        tag = TAGS.get(tag_id, tag_id) 
 
        data = exif_data.get(tag_id) 
 
        # Decode bytes 
        if isinstance(data, bytes): 
            data = data.decode() 
 
        print(f"{tag:25}: {data}")
Is it correct, sorta, close though. But it tells me I should look for a method on the image object called getexif -- hey it exists, nice! And that's what TAGS is for! Makes way more sense.
what happened after AI introduce undefined behaviour...
I've just re-created your "PID" controller, and was completely underwhelmed with the response. I just don't find it amazing that something using that much compute power can generate source code that multiplies an input by a constant.

If you can't write that quicker than the ChatGPT prompt you provided, then you probably should pay more attention to your class.