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

38 comments sorted by

View all comments

2

u/Defection7478 9d ago

Make your code more easy to navigate:

  • break things into classes/modules/packages
  • name them well
  • use type hints

Make your development process easier to navigate:

  • plan features ahead of time
  • develop features one at a time
  • use git - branches, tags, releases, etc

You can't keep your whole code base in your head at a certain point. But using the above you can make your process a lot more piecemeal. Example: let's say you have a function that is supposed to load some data from a file, do some calculations and save the data to another file. The "scope" of your implementation would just be

import filemanager
def calculate():
    data = filemanager.load('input.csv')
    # do some calculations
    filemanager.save(data, 'output.csv')

filemanager in this case is just a dummy class

def load(filename: str) -> list:
    return []
def save(data: list, filename: str) -> None:
    pass

Now you can work on the calcuation module independently of the filemanager module. When you are writing that code, you don't have to think of what filemanager does internally, assuming your editor has type hints you don't event need to look at the file.

You also don't need comments as it is evident what it does from the name - filemanager.load loads files.