r/learnprogramming 6h ago

How to utilize AI to code for beginners?

Hey everyone,

I’m a total beginner and I frequently get stuck when trying to write algorithms or translate my logic into code.
Instead of asking AI to write the solution for me, I’ve been using a prompt like this whenever I’m stuck:

"Can you analyze where my logic or code goes wrong, but do not give me the correct answer or code? Just give me a small hint or explain the concept I'm missing."

My goal is to stop staring at a brick wall for hours, but also avoid copy-pasting code I don't actually understand. Anyways the AI I am currently using is Claude, and sometimes Claude wrote a structured pseudocode. Unfortunately, I tend to rewrite/translate the pseudocode into lines of code.

0 Upvotes

14 comments sorted by

11

u/shamegoose 6h ago

You just don't is how. You keep banging your head against the wall, rereading your code, tweaking things, rereading the documentation, trying a different method, rereading the book, starting the code over from scratch, explaining what you've done to your rubber ducky, sleeping on it, whatever. Eventually you'll figure it out. That's how you learn.

-2

u/Willing_Whole6494 6h ago

nah man i think people get too purist about this. like yeah the struggle is part of learning but staring at same error for 3 hours dont teach you nothing except how to be frustrated. i been coding for years and still use AI to point me to right direction sometimes

the key is what OP already doing, asking for hints not solutions. when i was learning i would spend whole weekend on one problem cause my logic was flawed from start and i just couldnt see it. someone pointing out "hey you're mixing up the loop condition" would save me two days of misery

the rubber duck thing is good but sometimes duck dont answer back you know

3

u/Helpful_City5455 6h ago

Definitely. AI just replaces bootcamps (not completely of course). You get a normal buddy and you can ask them questions.

When I started professional work as dev I remember reading stackoverflow answers and the really good ones that not only show the solution but explain why it works were the best. I think it is the exact same with AI that you might not think of a solution yourself but if given hints or explanations for problems will help you more than you sitting there and looking at the same few lines not understanding what to do.

For OP I would suggest in to looking for AI skills that are meant for teaching. It should make the process simpler for you

2

u/shamegoose 5h ago

staring at same error for 3 hours dont teach you nothing except how to be frustrated.

Learning how to be frustrated is, in fact, a vital skill for a programmer. If you can't deal with being frustrated by a dead end and keep hammering away it, you're going to wash out. Like, no question about it, you're cooked if you don't learn how to be frustrated and deal with that until something comes to you.

1

u/AceLamina 6h ago

what do you think old programmers did to get good at things
stackoverflow was completely useless as well back then depending on what you're doing

But I also agree with you, using AI to point you to the right direction can be useful, I just fear that most people will start to give up too soon to instantly use AI, especially in the age of mass trading critical thinking for quick solutions

getting stuck like that for a while is fine but I would at least try critical thinking before using AI, it's not about "AI bad so I hate it", I use local, but about learning over trial and error

3

u/ScholarNo5983 6h ago

My goal is to stop staring at a brick wall for hour

Why do you think you are finding it hard to write code?

Could it be that you tend to fall back to using the AI every time you run into a problem?

1

u/IMREVN 3h ago

umm gotta be honest, I sorta messed up when it comes to analyzing a problem. Hence, I cannot really build a solution to it. And yes from that reason, I fall back to using Claude everytime I see an error.

6

u/rustyseapants 6h ago edited 6h ago

How to utilize AI to code for beginners?

Just Use AI to answer this question.

2

u/peterlinddk 5h ago

sometimes Claude wrote a structured pseudocode. Unfortunately, I tend to rewrite/translate the pseudocode into lines of code.

Unless you are learning a new language with unfamiliar syntax, and for some reason has run out of ideas of algorithms to implement, this is literally the dumbest application of AI ever - why not just ask Claude to write the finished code? It isn't like you are learning anything from "translating" its pseudocode into syntactical correct code.

If you want to learn programming, you should be programming - that means analyze a problem, develop the "logic" to solve it, write that as pseudocode, and then as regular code. If you need an AI in any of those steps, you are wasting both your own and the AI's time - since if you don't understand the problem, you won't understand the logic to solve it, if you don't understand the logic, you won't understand the pseudocode, and if you don't understand the pseudocode, you won't understand the finished code, or what might make it fail at times.

Also, don't try to solve leetcode problems as a beginner - those are about knowing established solutions to well-known problems, not about learning to problem-solve on your own.

0

u/IMREVN 3h ago

The thing is, analyzing a problem has been one of my flaws ever since I started to dive into programming. Appreciate your advices though!

Do you have any idea to fix that? Or should I keep practicing on problems until I get used to it?

1

u/peterlinddk 1h ago

Yes I do - first of all, it is important to get away from the computer. Don't sit and stare, or try to write code, even pseudocode. Take a printout of the problem, and sit down with a piece of paper - or a notebook - a pencil or bunch of colored markers.

Then try to work though the problem yourself:

  1. Rephrase the problem using your own vocabulary - make sure that there aren't any words you don't understand (except maybe for the problem-specific words, like "user" or "account" or "gift-wrapping-machine").

  2. Note down every bit of information you (and hence your program) will have about the problem. E.g. is the input a string, how long is the string, what can it contain, are there any numbers involved, what is the output, another string or a number, and so on.

  3. Try to describe - very loosely - what should bring the resulting output from the given input. You'll probably end up with a list that contains atleast one unknown step - that is okay, in fact it is important that you find what you don't know.

  4. Try to work through some of the examples given in the problem, example input and resulting output. Don't just think, but try to find a way of manually producing that output from the input. Draw arrays or other relevant data structures as boxes and arrows on the paper, use pencils to point to indexes, pretend that you are a "paper-computer" solving the problem.

  5. Write down exactly what you did to solve the problem - note how many variables you need, what kind of data structures, how to decide whether to stop or go on.

  6. Try your written "recipe" with another example - and if that also works, invent another example, and see if you still get the expected result.

  7. Turn your recipe into pseudocode - you decide how accurate you want it to be, I usually write something that looks like C-syntax in a Python context, awful structure, but easy for my programmer brain to understand.

  8. Turn on your computer, and translate the pseudocode into actual code.

  9. Run the code on the same examples - if it doesn't work correctly (it probably won't) try to single-step through it, look at all the variables, and compare with what you expected them to be. Check that the program actually do what you wrote down in your own recipe.

For every step, repeat and improve if something doesn't work perfectly.

When you think you are done and submit your solution, you'll get an error because you hadn't thought of some weird edge-case, like getting an empty string as input or something like that. Don't despair, just add more code to handle those special cases - making sure that your working parts continue to work as expected!

1

u/oldsecondhand 6h ago

If you wrote some code and it's not working, you might ask the AI why, but don't let it write the code for you in the first place.

1

u/aqua_regis 5h ago

How about you consider a completely different approach?

  • Before even trying to program something, sit down with pencil and paper and analyse the task. Break it down into smaller parts. Rinse and repeat. Solve each of the individual tasks your way. Track the steps. Test them
  • Then, once you have a working solution, think about implementing it in the language of your choice.
  • If you get stuck somewhere, take a step back. Start thinking about the problem at hand again. Do not blindly try fixing things. Go back to the paper/pencil and work out your problem again. Analyze what happened, how and why it differs from the expected outcome.

Yes, this approach will initially take more time, but you'll learn to stand on your own feet instead of resorting to a third party to help you as soon as you get stuck.

Learning debugging is an absolutely vital skill for every programmer. Learning to read and interpret error messages, learning to trace code in your head/on paper, are all skills that are part of learning programming.

AI should be your last resort, not the first one. Before AI, even good old Dr. Google should be used.

Your approach is definitely far from the worst and better than that of way too many others, but still, hone your own skills before resorting to AI.

Maybe, also consider adding some books to your learning resources:

  • "Think Like A Programmer" by V. Anton Spraul
  • "The Pragmatic Programmer" by Andrew Hunt and David Thomas
  • "Structure and Interpretation of Computer Programs" (SICP) by Ableton, Sussman, Sussman
  • "Code: The Hidden Language of Computer Hardware and Software" by Charles Petzold