Re: Taking a single large .cs file and making many smaller .cs files
- From: Lucian Wischik <lu.nn@xxxxxxxxxxx>
- Date: Wed, 13 Dec 2006 13:43:07 -0800
"Gabriel Lozano-Morán" <abuse@xxxxxxxxxxxxxxx> wrote:
Indeed by refactoring. In an ideal world a class would have no more than 3
methods and about 15 lines of code per method but these are just arguable
guidelines.
Famous saying: "Every problem in computer science can be solved by
adding a layer of indirection."
Lucian's addendum: "Adding a layer of indirection always creates more
problems than it solves."
Am I the only person who prefers larger files (around 4000-5000 lines)
and larger methods (10-200 lines) ?
The way I see it, if there are multiple files then it's harder to keep
track of what each file does, it's harder to do the sort of
refactoring that would involve changing these files -- especially if
they're under source control -- and it encourages the mindset we're
you're only aware of the small bit of code that you're working on, no
longer so aware of the larger picture. And you can't print out the
code very easily. And it's easier for other people to incorporate your
module as source code if it comprises only a small number of source
files.
Finally, if you have one file per class, then there's no longer a good
place to write "architecture/design" comments that span multiple
classes. These comments are the single most important part of
programming, I think.
As for procedures, a lot of procedures just do (say) ten things in a
row, one after the other. And each of those ten things might involve
ten smaller things. You could factor each one out into a separate
procedure, sure. But that creates extra layers of "mental indirection"
-- the person reading your code no longer has such a clear idea of
where the function might be called from, where it fits in, what its
public/private visibility is, and so on. If you leave them all in the
same 100-line procedure then it's clear how they fit in.
If we do as you say and have classes with only very few methods, then
the reader of your code suddenly has a lot of extra mental complexity
to keep track of all the classes. I think it's easier to keep track of
normal methods within a class than it is to keep track of classes and
their using/inheritance/calling/visibility relationships.
I guess I feel that progressively breaking the problem down into
smaller pieces is useful only inasmuch as its needed for human
comprehension. Once we get beyond that point, and we start breaking it
down smaller we're actually hindering comprehension.
--
Lucian
.
- Follow-Ups:
- Re: Taking a single large .cs file and making many smaller .cs fil
- From: Mark R. Dawson
- Re: Taking a single large .cs file and making many smaller .cs fil
- References:
- Re: Taking a single large .cs file and making many smaller .cs files
- From: Gabriel Lozano-Morán
- Re: Taking a single large .cs file and making many smaller .cs files
- Prev by Date: Re: Temporarily give the current user Local Admin rights
- Next by Date: Re: Temporarily give the current user Local Admin rights
- Previous by thread: Re: Taking a single large .cs file and making many smaller .cs files
- Next by thread: Re: Taking a single large .cs file and making many smaller .cs fil
- Index(es):
Relevant Pages
|