keep quitting projects because i get stuck on logic. any suggestions?
Posted by sandboxus3r77@reddit | learnprogramming | View on Reddit | 15 comments
so whenever i try to start a new project (like even something simple like a snake game), i get stuck really early not on syntax or anything, but like… the logic behind it. i just don’t know how to think through “what happens next” or how to structure it step by step then i sit there for a while, get frustrated, and end up quitting the project.
how did you get better at building logic for projects instead of just getting stuck?
AntiDynamo@reddit
It’s called “problem solving”, it’s a generic skill that is really really important to develop just for general life stuff. It’s the way you sit down and reason out a solution to any problem in your life.
Start by identifying the core aim - in very explicit detail. Like, first you want a character which can move within a box, directed by keyboard input. So make a box and a character (even a dot) that can be moved with the keyboard. Then you add complexity from there one step at a time
spinwizard69@reddit
You didn't mention your experience but the first thing is to stop trying to program complex games. Like any other skill, you develop over time, starting small and working upwards.
I oftne say programming is easy and frankly writing code is easy. Figuring out how to build a performant program though can be very hard. Often you need to write out, in english, what you want to happen. In games you are often an interactive story teller, so write a story that makes sense and then turn that into code.
Gnaxe@reddit
Know where you're going, and figure out a step to get you closer to that, even if it's not 100% there. Make the problem into a smaller/easier problem. Then write a test which would prove you've done that. Then write code that makes the test pass. Then save/commit your progress. Then do it again, but closer this time. Keep iterating until you actually get there.
SupremeArtistry@reddit
breaking down problems is huge but also don't underestimate just copying someone else's implementation first. like seriously, find a snake game tutorial and type it out line by line, then mess around with it once it works
the logic clicking moment usually happens when you see patterns across different projects. after doing a few guided builds you start recognizing "oh this is just a loop checking collisions" or "this is updating coordinates based on direction"
also snake is actually pretty tricky for a beginner project despite seeming simple - maybe start with something like a basic calculator or to-do list first
BanaTibor@reddit
Draw flow charts of the parts of the core logic.
Lagfoundry@reddit
You have to break it into small pieces and take it one logic layer at a time. Like building a memory management unit in hardware for my first time. I thought well first I need to make sure it always sits on an empty register ready for a write. So I added a incrementor to the matrix decoder lines and split the output BUS lines so I could OR tree them into a NOR gate. That output feeds the NOT gate that powers the +1 on the incrementor so that it scans till it hits an empty register allowing the NOR to turn off the NOT stopping the increment… with that solved I still have to make sure I can use the decoders by addressing them. So similar to jump addressing a program counter I take a split of the address lines and OR them all into the clear of the incrementor so that if an address comes through it clears the Increment value allowing the address to take over. Once the address leaves the inputs the scan takes over again…. I know this seems like a lot but this is quite literally step by step hardware design. You have to think what’s the signal that tells my system what to do, how does it know, how do I stop it, how do I automate it. Just little chunks at a time
TheNewJoesus@reddit
I really like drawing graphs or charts. UML diagrams specifically. There are visual studio code extensions that make drawing UML diagrams easier.
The reason I do that is so I can see “the current state of my project.” And when there is a feature I want, I can think “Where should the pieces go?”
Also, feel free to quit projects whenever you want. I have dozens of unfinished projects. Most of my projects are barely working prototypes. It doesn’t need to be good until you’re getting paid to make it.
For your snake example, I’m going to gamble and say you need to learn Object Oriented Programming concepts to help unblock your progress. OOP is an essential programming concept. Look up “Learn OOP using “my languageOfChoice” and go from there.
My favorite tutorial was learning how to make Asteroids with Java.
TheNewJoesus@reddit
Just a note: I’m happy I learned during the time period I did. Free access to computer education was a priority amongst a decade ago. Now it seems like google prefers to give paid content a boost. I’ve been searching for an hour and have only found two courses that I’d recommend. When I was younger, I could find 12 without thinking hard. Insanity.
HashDefTrueFalse@reddit
Do you try to write code without knowing where you're going first? If so, try to spend some time with pen and paper and write/doodle whatever you need to in order to get it clear in your mind what you need to write. Crude diagrams of flow control, pseudo-code, even just defining the problem you're trying to solve. Break down the problem into smaller problems. Then turn some of the smaller problems into data and/or code. For example:
I need a program that simulates a traffic light sequence. I need to represent a box with three lights that can be on or off in memory. I need to move from one state to the next, so I need a way to find the next state using the current. I need to loop forever. I need each state to last a certain duration. I'm eventually going to need a thousand lights in my city simulation, starting at random states.
I'm sure you could imagine two flow diagrams you could draw before you got to this, e.g. the states of the light and the sleep->change->sleep->change loop, and maybe some pseudo-code for the loop etc.
Now that I've solved this part I can create my thousand lights in a loop, using
rand()or similar for the starting states. Then each tick of the above loop I'd iterate over all lights, running the above code, and so on...Try not to program "by accident" or "by coincidence" and never write too much code without running and testing it.
QVRedit@reddit
Work it out on paper, for example buy yourself some paper with squares on it, and setup a sequence of coloured in squares, work out the logic from there.
What you are looking at is progressing ‘vectors’ so much x, and so much y, to move things, then what happens when a collision occurs ? What do you want it to do - does it change direction - if so then maybe the ‘Y’ increment goes from adding to subtracting ?
Eg. Y= Y+1 to Y= Y-1, reversing its direction (that’s in the simplest case). But more complex mixtures are just variants of this.
azimux@reddit
Hi! I can give some recommendations.
One is to talk it through with somebody else or maybe even pair on it with somebody. Or even rubber-duck program it.
Another is to take a more top-down design approach. I like to do bottom-up when I mostly know what I want and how I want it to work. If I don't know yet then I like to work top-down instead. So in those cases I will focus more on what I want the system to do at a high level and flesh things out that way. This can delay my need to wrangle all sorts of logic until a moment where it's more obvious what it should be.
Another might be to pick less-ambitious projects. The easier the project, the more likely you will be to finish it.
I also think if you're doing this for learning that it's fine to abandon projects. So maybe just abandon the project and work on a different one. You will continue to learn unless you stop working on projects entirely. I think it's helpful to finish projects but it's fine to also not finish projects if the goal is learning. You probably should at least occasionally finish a project and the last point, pick less-ambitious projects for now, would help with that.
Those are my opinions though. Everybody is different and you might have to just figure out what works for you.
QualityOk6614@reddit
Ask AI when you get stuck, and try to understand what the ai wrote, I think it’s normal to get stuck when implementing features (happens to me all the time). I remember the first time I tried building a search feature on my website, but when it came to implementing it, I couldn’t do it so I had to ask chat gpt
ffrkAnonymous@reddit
It's a prototype. It's supposed to be bad. It's entire purpose is to be a learning experience.
iOSCaleb@reddit
Think about the data that the program uses, how it’s stored, and what operations you can do to it. For a snake game you’d need: a board, any obstacles, and the snake. Drill down more, e.g. how would you represent the snake? It needs to be able to grow over time, and when it moves each segment moves to the former position of the segment ahead of it. You could use an array or a linked list or just change the values of cells on the board; what representation makes it easy to do whatever you need to do to the snake?
beavedaniels@reddit
Whiteboard it! Or use pencil and paper.
Diagram the flow of data, your inputs/outputs, what you expect to happen or how you expect the data to change. It'll work wonders! You can also use the rubber duck approach and talk through it with an inanimate object, another human, or an LLM (just don't ask it to do the logic for you, instead ask it to evaluate your approach and suggest alternatives and help you evaluate tradeoffs).
You'll get there, it takes time and repetition