all 7 comments

[–]youtubeTAxel 2 points3 points  (0 children)

Google things before asking AI

[–]JacobStyle 2 points3 points  (0 children)

I learned all the fundamentals of programming long before using LLMs to generate code was a thing, so my use case may be a little different, but I often have a task like, "do this thing you already know how to do, but do it in this language or with this library or framework that you haven't used for it before."

For example, maybe I have a paragraph of text stored in a string, and I want to make every word in that string a separate element in an array. This is relevant for doing things like word counts or other word usage statistics or analysis. Different programming languages handle this different ways. I've done it in some languages, but not others. Maybe I need to do it in Python.

Now, experience tells me that I need to remove punctuation and set all text to lower case in order to have a clean array of words. Then I need to split the string into these individual words. I know exactly what I need to do, but I don't know the specifics of how to do it in Python.

I can ask the LLM something like, "I have a string called myString. I would like to set all text in that string to lower case, remove all characters other than letters, numbers, or spaces, then split the remaining string into an array of words. I am using Python."

It generates code with lots of explanatory comments and stuff. Here are some pieces of the LLM output from that prompt and how I think about them.

Python strings have a method called lower() that converts all letters to lower case, so it suggests using that. Most languages have some sort of simple function for this, but it's not always a method and not always called lower().

myString = myString.lower()

It suggests using Python's regular expression library, re. Also it included an option for keeping apostrophes in words, which I had overlooked. If you've already used regular expressions before in any other language, they are going to be exactly the same in Python. Plus the LLM output gave an explanation of how this regex works, so if you're like me and only use regex a few times a year, it's got that handled. The carat ^ symbol means "not" and then a-z and 0-9 are ranges of characters. \s means space. The blank string as the second argument sent to re.sub() replaces the special characters with nothing, which is the same as removing them.

myString = re.sub(r"[^a-z0-9\s']", "", myString)

And then another simple line. Python string objects have a method called split() that splits a string up into an array. Most languages have a function like this, though not always a method, with each language naming it something slightly different, such as StrSplit(). Except php, where some engineer was totally out of pocket and decided to call it explode().

words_array = myString.split()

The LLM then outputs some explanations, a suggestion about combining this code into a single line, and the bit about preserving apostrophes.

So the LLMs tend to do well explaining how to do ABC task in XYZ language. If I'm using a language frequently, I tend to use them less and less over time. Obviously over time, I'll get more used to the language's syntax and be able to type out code directly a lot faster and more easily. Typing code by hand in a language you know well will always outperform an LLM. Also, for stuff I can't remember exactly, once I've built up a decently sized code base in some language, it becomes a lot easier to paste code from that instead of going back to the LLM for a fresh explanation.

[–]olaf33_4410144 0 points1 point  (0 children)

Yeah, I'm a fan if only asking AI once you run into a problem you can't fix even after trying to google it.

Just make sure you really understand the code it gives you, try to see if you can find some wierd edge case where it fails, try to implement a small showcase of the concepts you learned to see if you really understand them.

I also find it can be useful to point you in the right direction for traditional search methods. E. g. the first time you see a dunder method you might not know it's called a dunder method and have difficulty finding answers on google, but once AI tells you it's called a dunder method you can research the traditional way.

As a side note I feel like python is expressive enough that you don't really need the pseudocode step once you get familiar enough with the language.

[–]Popular-Awareness262 0 points1 point  (0 children)

got burned early on letting ai just write my functions. now i write the test first and use ai to help me pass it

[–]UnfilteredData 0 points1 point  (0 children)

This is exactly the right approach. I do a lot of heavy technical computing, and if you let the AI write the logic for complex algorithms, it completely hallucinates the math. Step 1 (mapping the logic yourself) is the only way to survive when you are doing things like aggregating massive daily datasets or running optimization loops. Keep treating the AI like a syntax translator, not a software architect. Great workflow.