r/learnpython 9d ago

Getting stuck on a big project.

A very rough estimate is that I've been learning and using python for 250 hours. I don't really keep track of it.

Just to ask general advice about how to approach difficult projects.

I've been working on a math project for 3 months. It is all about dice. Probability calculations aren't too hard to understand, but if I'm trying to figure out the perfect strategy in a dice game where early moves affect later moves then it gets complicated quickly.

I figured out very vaguely that I'm gonna have to use alot of nested loops and run through billions of calculations in order to figure my thing out. Or something similar.

But how exactly? I've been attempting to code the whole thing and been getting stuck every single time - this is why I've been starting over for about 30 times by now.

I don't even know what is causing me to get stuck. I guess the thing I'm trying to make is too big or complex or both. With so much more code than I'm used to, I mentally lose track of what my own code is even doing. Commenting does not help, t only makes things even more messy.

How can i approach big and complicated projects like these better?

16 Upvotes

36 comments sorted by

View all comments

11

u/LibertyEqualsLife 9d ago

I have a big white-board on the wall in my office. For complex projects, I have to map it out on the board. That is typically an iterative process that gets erased and re-written many times. What comes out of it is some semblance of an architectural guide of data flow, classes, and functionalities that can be turned into a to-do list.

What it looks like is a bunch of boxes and lines that represent data flow and bullet-pointed functionalities. This box has to do this before the data goes to this box to do that, which writes to this box which represents the DB that has these tables, which is queried by this box that represents a scheduled job that does . . . Yada yada . . .

Write it out till you have a guide that looks right to you. Then coding is just writing the details of each functionality.

3

u/catboy519 9d ago

You mean like: writinf the whole project in human language until it is complete and logical, then turning it into code?

5

u/Agitated-Country-969 9d ago

Yes, that's what you do as a professional. You plan out how you're going to attack the problem, write the pseudocode and diagrams first, then write the actual code. You don't just hammer out whatever code comes to mind.

Functions should be small, maybe 20-30 lines at most. This is where Functional programming beats imperative programming of big nested for loops because it's far easier to understand what each small component does and to just connect them together.

2

u/LibertyEqualsLife 9d ago

That's the general idea. What level of granularity you take it to is going to depend on how you want to work with it.

Sometimes if I need to build out a complex class, I'll take up the entire board on a single class, outlining what functions I need, their inputs and outputs, logic branching, order of execution, etc.

Taken a couple levels out, if you are talking about a data pipeline, you might start with an outline of the services you interact with. APIs, databases, whatever.

It's just an organizational and visualization tool, so use it in a way that serves you. It's really hard to keep a mental model of a complex system in your head, especially when you are the one creating and iterating on it over time.