Re: Taking a single large .cs file and making many smaller .cs files

Tech-Archive recommends: Fix windows errors by optimizing your registry



"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
.



Relevant Pages

  • Re: Taking a single large .cs file and making many smaller .cs fil
    ... If this were true why have any indirection at all, ... Oriented even if written in an OO language, functionality and code is ... "Adding a layer of indirection always creates more ... if there are multiple files then it's harder to keep ...
    (microsoft.public.dotnet.languages.csharp)
  • concatenating in a macro
    ... c++ faq lite writes: ... However you need a double layer of indirection when you use ##. ... Basically you need to create a special macro for "token pasting" such ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Refactoring all the time
    ... and then implement yet another object-handling system ... Are you suggesting that there is something wrong with indirection? ... The most perfect game would have layer upon layer of abstraction, ... description of what a roguelike is. ...
    (rec.games.roguelike.development)
  • Re: OffTopic: Wie kann ich am besten Source (formatiert) posten?
    ... Thomas ... Any problem in computer science can be solved with another layer ... of indirection. ...
    (microsoft.public.de.vb)