Deciding when to split a growing script into modules instead of one file

A Python script that started as fifty lines is now almost six hundred. It fetches data, cleans it, writes reports and sends notifications. Everything technically works, but scrolling between functions is becoming ridiculous. I'm tempted to split by responsibility into modules, though I don't want to design a grand architecture for a personal tool. What signs tell you it's time to split a script, and what would you keep in the entry-point file?

  • programming-help
  • split
  • growing
  • script
54

5 replies · Sort: Best

Best
  1. CS
    charles_5
    4 points

    4 replies

    Split it when you start hesitating before opening the file. Six hundred lines with four jobs is already past the point where a few modules w...

    44 replies

    Split it when you start hesitating before opening the file. Six hundred lines with four jobs is already past the point where a few modules will probably help.

    4
    1. SO
      suzanne_55
      1 point

      I’d keep the entry point tiny: parse args, call functions, maybe log status. The rest can live in separate files by responsibility.

      1
    2. IT
      tagliafierro-i
      4 points

      Also, if you keep scrolling back up to remember where something lives, that’s your sign. The code is telling you it wants a drawer system.

      4

        I’m less sure you need to split immediately just because it’s long. If the script is stable and you know it well, sometimes a few well-named...