469,890 Members | 1,929 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

Best practice for large source code projects

I'm developing a web system and based on some patterns I've seen
elsewhere, I made a single file (model.py) to hold all of the
functions and classes that define the model porition of the
application. Hence the code in the controller looks like:

import model

def Display(req,id):
# ....
It works and things make sense to me. Yet, I feel uneasy that my
model.py file is starting to approach 500 lines. What's the best
practice or community opinion on this? Do I keep everything in a single
file or do I start dividing things into separate files?

TIA

Sep 22 '06 #1
2 1552
several of my programs are thousands of lines long, and i don't think
they're extravagantly large.
i'd say you should use modules the same way you use classes and
functions: to separate code logically.
if it makes sense to think of a group of statements as a function, you
make it a function. if it makes sense to think of a group of functions
as data as a single object, you make a class. if it makes sense to
think of a collection of classes and functions and data as a collective
unit, make a module. and so on for packages.
if it makes sense for a single function to be hundreds or thousands of
lines long, so be it.
follow the modern poet's rule: ignore restrictions that don't make
sense, and follow closely the restrictions you choose.
dh****@gmail.com wrote:
I'm developing a web system and based on some patterns I've seen
elsewhere, I made a single file (model.py) to hold all of the
functions and classes that define the model porition of the
application. Hence the code in the controller looks like:

import model

def Display(req,id):
# ....
It works and things make sense to me. Yet, I feel uneasy that my
model.py file is starting to approach 500 lines. What's the best
practice or community opinion on this? Do I keep everything in a single
file or do I start dividing things into separate files?

TIA
Sep 23 '06 #2
"dh****@gmail.com" <dh****@gmail.comwrites:
It works and things make sense to me. Yet, I feel uneasy that my
model.py file is starting to approach 500 lines. What's the best
practice or community opinion on this? Do I keep everything in a single
file or do I start dividing things into separate files?
It varies by project and preference. Working with very large files
can get cumbersome, but having a lot of small files means higher
amounts of editing hassle and more junk to keep track of.

As a personal opinion, I'd say just try to keep your functions small
and understandable, and don't worry about file size until the files
start getting inconvenient to edit. I find 1000-2000 lines is a
reasonable file size.
Sep 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

36 posts views Thread by Andrea Griffini | last post: by
136 posts views Thread by Matt Kruse | last post: by
6 posts views Thread by Droopy | last post: by
5 posts views Thread by BK | last post: by
13 posts views Thread by G | last post: by
6 posts views Thread by Daniel Kraft | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.