Playing with AI and Learning to Keep It Simple, Silly
Yesterday I was playing with AI in the evening and I asked it to help me write a function that would detect whether an array item was a photo or a video. I told the AI, this is a photo array item, and this is a video array item. I want the photo array item to display the img src code and for the video item to be displayed with video src code. At first it failed to detect anything and gave me an error message. I decided to highlight the photo array item snippet and the video array snippet.
It didn’t come back with an error but it did not display any img or video code. In the end I decided to say “here’s the img src tag. I want you to detect whether the file is mp4 or jpg. If it’s mp4 add the video player, and if it’s a photo load the image. I went from asking it to read the array to determine what to do, to “check the filetype and load the appropriate src type. That worked, and required very little code.
Don’t Over-Engineer With AI
The moral I came away with, after the trial and error I went through last night is that whilst AI is great at reading and understanding code, and giving us answers it can sometimes fail. I was making something far more complicated than it had to be and chatGPT got confused, as would a human trying to complicate something simple.
PHP has a lot of functionality built into it. It has tools that allow it to read exif information, file types and more, and if you know about these tools, then you can come up with elegant solutions, rather than complicated ones.