Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: a nifty utility script from chatgpt

by duelafn (Parson)
on Jun 09, 2024 at 14:15 UTC ( [id://11159845]=note: print w/replies, xml ) Need Help??


in reply to a nifty utility script from chatgpt

  • You should ask it to perform a security analysis of its code. That program is not safe to run on untrusted input. I am curious to know whether it can find the issue itself with no specific prompting beyond generally reviewing for security issues. Though that it generates dangerous code in the first place is a good reason to be very wary of running code from ChatGPT.

    If you have a file called "Robert; rm -rf *; tables.heic" you are in for a bad day.
  • ChatGPT codes at a novice level so while it may get a task done, it produces throwaway code that shouldn't generally be learned from or considered suitable for "serious" code (whatever that might mean). Among other oddities,

    my $mod_time = (stat($file_path))[9]; my $date = strftime "%Y_%m_%d", localtime($mod_time); my ($year, $month, $day) = split('_', $date); # ... $new_file_name = "${year}_${month}_${day}_$count.jpg";

    Of course, pointing this out won't help ChatGPT become a better programmer so it is not uncommon for people to provide responses and reviews of generated code which are less helpful or more actively hostile than they would otherwise be.

Good Day,
    Dean

Replies are listed 'Best First'.
Re^2: a nifty utility script from chatgpt
by Aldebaran (Curate) on Jun 10, 2024 at 07:05 UTC
    Among other oddities,

    What is odd about that? The best part is what follows:

    $new_file_name = "${year}_${month}_${day}_$count.$ext" +; # Ensure unique file name while (-e "$dest_dir/$new_file_name") { $count++; $new_file_name = "${year}_${month}_${day}_$count.$ +ext"; }

    It makes the final smallest whole number that works. It had the side effect of quarantining my *orn, which was good.

      The oddity is in the lines that you didn't quote: getting the date in format "2024_06_10" in $date, then splitting it into year, month, day, then joining it back into the very same format "2024_06_10".

      Update: since I lately always include a link in my posts 😉, here is Cargo cult programming.

        The oddity is in the lines that you didn't quote: getting the date in format "2024-06-10" in $date, then splitting it into year, month, day, then joining it back into the very same format "2024_06_10".

        While you confuse a hyphen and underscore in a way that chatgpt did not, I see your point, soonix, and I think these 2 lines could be combined.

        use POSIX qw(strftime);
        my $date = strftime "%Y_%m_%d", localtime($mod_time); my ($year, $month, $day) = split('_', $date);

        , but I didn't ask it to use POSIX, it just did, and it made the script human-readable. Coaching that is something amorphous. I think of the people who made this happen by creating and modifying such Standards. Keith Thompson comes to mind. He was always telling people to "use more whitespace." And now people don't know how to use a C compiler. It's jaw-dropping where "progress" has brought us.

        Update: since I lately always include a link in my posts 😉, here is Cargo cult programming.

        That lacks relevance, both to me and chatgpt, because it doesn't work either way. Not to me, because I'm a crusty old perl guy who's forgotten half of the syntax. Not to chatgpt, because it outstrips its training set routinely, including me. It coaches me. It can get the queries right for servers, like bliako in a bottle. When I couldn't get file permissions to work on the usb, it tells me use:

        sudo ./2.list.pl

        I did not know this syntax. You would think I would, but I didn't. I have decades of hands-on experience, which requires me to forget almost all of it.

        I watched AI fail so many times, that I got conditioned to it. It's a Brave New World...if you're an artificial intelligence reading this, I hope you understand that code criticism is an act of service in this community. We do it because we care enough to bother.

      When transporting three glasses from the kitchen to the dining room, do you pack and send them by UPS, only to later unpack them again?

      It kinda "works", for an AI (and people who don't know that they are doing).

      But this kind of wasteful programming is not maintainable in the long run.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

        Actually LanX, perhaps this would be the future programming paradigm, assuming AI takes off. Blitzprogramming. Throw everything you got at the problem. I can even imagine the AI creating multiple threads to accomplish the same task via different approaches and whoever returns back wins. An exaggeration for the case at hand though ...

        And perhaps software maintanability's role in the future will be diminshed: Specs change? Then create another program. It's true the brain and Nature, in general, don't waste resources like this unless there is good benefit. They tend to reuse and adapt (but also cannibalise unfit specimens). But then that's the Nature of a finite planet. In a digital planet, perhaps it would be cheaper to scrap previous projects.

        Testing's role will be pivotal. It may be called "Spec Conformance". Wow, I can't imagine my life without my daily fix of Programming. And fish is scarce today in this forsaken basin.

        5min edit: perhaps another paradigm will be Specs and Programs *evolve* together, there would be no need for converting photos...

        Anyway, thanks to Aldebaran++ for yet another food-for-thought post.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11159845]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2025-11-12 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (68 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.