Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on How should I structure a growing Python project?

Parent

How should I structure a growing Python project?

+2
−0

I’m working on a Python project that’s starting to grow, and the code is becoming harder to manage as different responsibilities are mixed together. Are there any recommended ways to organize modules or patterns to improve maintainability and scalability?

History

0 comment threads

Post
+4
−4

It's not really related to Python at all. For any language, you will use an object-oriented design for the sole reason that it scales well with larger projects. If every part of the program is written with lots of OO discipline, then the size of it won't matter since every module just ought to take care of it's own designated task and not worry about the outside world. This means that maintenance turns localized and bugs don't as easily escalate all over the program.

Similarly, if not enough care about design was taken from the start, then all design problems will escalate, "tight coupling" between unrelated parts will increase etc etc. It is good practice to always write production quality code from day 1 and not starting by hacking together some quick & dirty "debug release" code with the intention to clean it up later. "Just coding away" is the root of all evil.

The process of re-designing bad code is often called "refactoring", which is a snobby way of saying "I didn't consider requirements and/or design enough when I first wrote this bad code". Those who claim that "refactoring" is some sort of natural, mandatory part of the development process are probably not very experienced. With experience you'll learn that spending some extra week on requirements and design will save far more time later down the road. Because rewriting everything at a later stage takes lots of time and nobody wants to pay you for doing the work twice either.

If the code was originally well-designed but "scope creep", extra features or quick & dirty patches challenge that design, then that's known as code rot and it happens when you continuously maintain something over time. Particularly when abandoning discipline or when rolling out changes under time pressure. You might have to rewrite parts of the program from scratch to get rid of that. Ideally you should not abandon discipline when making a new extra feature and you should probably test it much more carefully than you tested the original code. A significant part of all bugs out there happen during maintenance.

In addition to paying extra attention to requirements and design, which are by far the most important parts, you also need:

  1. A coding style guide for how you should write code.
  2. Coding rules for which language/library features to avoid or treat with care.
  3. A documented procedure for how, when & where you do commits to the version control system.
  4. A documented procedure for how you publish/deploy programs.
  5. Peer code review and/or static/dynamic analyzers are great ways to reduce bugs.
History

2 comment threads

I disagree on your take that refactoring always means "I didn't consider requirements and/or design e... (2 comments)
+10 if I could. (1 comment)
I disagree on your take that refactoring always means "I didn't consider requirements and/or design e...
HeavyRain‭ wrote 6 months ago

I disagree on your take that refactoring always means "I didn't consider requirements and/or design enough". Sometimes you just don't know enough and need a balance between analysis paralysis and quickly getting a feature out. Requirements change. New technologies become available. Code cleanup should be an ongoing thing in every project. It does not automatically mean someone didn't do their homework.

Lundin‭ wrote 6 months ago · edited 6 months ago

HeavyRain‭ If you didn't know all requirements but did a proper OO design, you should be able to add new features on to that design without too much effort. That is the very reason we use OO design to begin with. On the other hand if you find yourself rewriting a lot of the code, then that means that the original design was not flexible enough. It really is as simple as that.

And code cleanup is only necessary if the original code is badly written. To avoid that, one can make it a habit of writing production quality code at all times. And never write something quick & dirty that you will "fix later". I used to waste huge amount of times too, cleaning up quick & dirty code. It is naive and not an efficient way to work, particularly not with large projects. I stopped writing "quick & dirty that will get fixed later" maybe some 15 years back, when I was a much worse programmer.