News for hackers. Stuff that matters.
Re:Getting AI to write good SQL by layer8 on Friday May 16, 2025 @08:10PM (#44010931)
How do you validate it if you don’t know the syntax? Or are you saying that looking up syntax –> semantics is significantly quicker than semantics –> syntax? Which I don’t find to be the case. What takes time is grokking the semantics in context, which you have to do in both cases.
Re:Getting AI to write good SQL by tough on Friday May 16, 2025 @08:16PM (#44010966)
Re:Getting AI to write good SQL by layer8 on Friday May 16, 2025 @08:43PM (#44011120)
That doesn’t answer the question. By “validate”, I mean “prove to yourself that the regular expression is correct”. Much like with program code, you can’t do that by only testing it. You need to understand what the expression actually says.
Re:Getting AI to write good SQL by widdershins on Saturday May 17, 2025 @05:41AM (#44013194)
Testing something is the best way to prove that it behaves correctly in all the cases you can think of. Relying on your own (fallible) understanding is dangerous.

Of course, there may be cases you didn't think of where it behaves incorrectly. But if that's true, you're just as likely to forget those cases when studying the expression to see "what it actually says". If you have tests, fixing a broken case (once you discover it) is easy to do without breaking the existing cases you care about.

So for me, getting an AI to write a regex, and writing some tests for it (possibly with AI help) is a reasonable way to work.

Re:Getting AI to write good SQL by layer8 on Saturday May 17, 2025 @09:48AM (#44014320)
I don’t believe this is true. That’s why we do mathematical proofs, instead of only testing all the cases one can think of. It’s important to sanity-check one’s understanding with tests, but mere black-box testing is no substitute for the understanding.
Re:Getting AI to write good SQL by tough on Saturday May 17, 2025 @11:40AM (#44015072)
Code is not perfect like math imho

libraries some times make weird choices

in theory theory and practice are the same, in practice not really

in the context of regex, you have to know which dialect and programming language version of regex you’re targeting for example. its not really universal how all libs/languages works

thus the need to test

Re:Getting AI to write good SQL by marcosdumay on Friday May 16, 2025 @08:29PM (#44011044)
Notice that site has a very usable reference list you can consult for all those details the GP forgets.
Re:Getting AI to write good SQL by eddd-ddde on Saturday May 17, 2025 @10:22AM (#44014538)
In my case most of my regex is for utility scripts for text processing. That means that I just run the script, and if it does what I want it to do I know I'm done.

LLMs have been amazing in my experience putting together awk scripts or shell scripts in general. I've also discovered many more tools and features I wouldn't have otherwise.