Page 1 of 2

Number of lines before confusion

Posted: Wed Nov 23, 2005 10:19 pm
by alex.barylski
Just a personal preferance, but...

I generally don't get along with files who have more than 500 lines...

I've alwasy been a strong supporter of modularization...mostly cause when files have more than 500 lines I tend to loose myself in my own code :oops:

Back in the day when I programmed in VBasic 3.0 I remember a neat feature where you could display ONLY the function you were interested in working on and the rest of you code wasn't shown...

Then I switched to C++ and Visual Studio where it's editor can and WILL display tens of thousands of lines of code :? 8O

Now I use UltraEdit for PHP and it's no better...

p.s-I hate source folding...so I turn that feature off... :) It's not the same

So, I ask, how many lines do you find confusing...or atleast your personal MAX....what techniques do you use for keeping all that code organized in your head? Do you keep your functions small? Do you use verbose documentation???

Cheers :)

Posted: Thu Nov 24, 2005 3:41 am
by Grim...
Actually, I'm quite a fan of big pages when I'm developing, and Textpad handles pages with over 5,000 flawlessly.
When I'm done I split them off into several smaller pages for the benefit of my colleagues.

Posted: Thu Nov 24, 2005 6:17 am
by Maugrim_The_Reaper
When using OOP at least, even large files I create are generally broken down into small specific methods. Not the same thing as small *files* but with OOP you start moving towards small methods that are easier to cope with than 1000 lines of spaghetti code...

The main confusion I get from really large files is when they are legacy code; procedural, full of globals, and with register_globals enabled (no superglobals!).

Posted: Thu Nov 24, 2005 8:21 am
by n00b Saibot
Maugrim wrote:When using OOP at least, even large files I create are generally broken down into small specific methods. Not the same thing as small *files* but with OOP you start moving towards small methods that are easier to cope with than 1000 lines of spaghetti code...
second that :) what we should look to achieve is modularity in the code itself rather than to chunk out portions of code in order to make them look small... :wink:

Posted: Thu Nov 24, 2005 8:31 am
by twigletmac
Maugrim_The_Reaper wrote:The main confusion I get from really large files is when they are legacy code; procedural, full of globals, and with register_globals enabled (no superglobals!).
and a bunch of includes so that you can't quite work out where various variables are set - they just appear, ugh.

Mac

Posted: Thu Nov 24, 2005 8:49 am
by fastfingertips
Usually the largest files, in my case, have somewere between 300-350 files. Greater files make me to wonder if i made mistakes in analisys :)

Re: Number of lines before confusion

Posted: Thu Nov 24, 2005 9:03 am
by Roja
Hockey wrote:I generally don't get along with files who have more than 500 lines...

So, I ask, how many lines do you find confusing...
For me, the top limit is about 1,000 lines. If its that long, the file almost definitely needs to be broken up.

I used to use functions and classes to break that up, but lately, I've been able to refactor large files into several smaller files by rethinking their purpose. In most cases, I was trying to do too many different things in a single file.

Posted: Thu Nov 24, 2005 9:07 am
by jmut
Of course, breaking up large files into several smaller is better solution.
But line bookmarks helps a lot in large files.

Posted: Thu Nov 24, 2005 9:59 am
by Buddha443556
So, I ask, how many lines do you find confusing...or atleast your personal MAX....what techniques do you use for keeping all that code organized in your head? Do you keep your functions small? Do you use verbose documentation???
500 line is pretty confusing. On the development end, I usually have one item (class/function/snippet) per file and these files are usually less than a 100 lines. These files form a code base that is use to build the production scripts. On the production end, all these little files come together and can get rather large (some larger than 500 line). The production end is optimized for speed/memory and is not meant to be directly maintained ... especially since I strip all my very verbose comments and whitespace.

Posted: Thu Nov 24, 2005 10:00 am
by onion2k
So long as it's organised reasonably well I don't care. I've been throughly annoyed by scripts that are 15,000 lines long, but equally I've been annoyed by scripts that are spread out amoungst 30 different include files. I don't think there's a simple answer to the problem of code organisation.

Posted: Thu Nov 24, 2005 11:05 am
by AngusL
Visual Studio 2005 you can shrink functions, classes etc. Can't remember if you can do this in previous versions. What you can do though, remember, is

Code: Select all

#define region "Region name"
which will let you shrink a part of your code.

Re: Number of lines before confusion

Posted: Thu Nov 24, 2005 7:37 pm
by alex.barylski
Roja wrote:
Hockey wrote:I generally don't get along with files who have more than 500 lines...

So, I ask, how many lines do you find confusing...
For me, the top limit is about 1,000 lines. If its that long, the file almost definitely needs to be broken up.

I used to use functions and classes to break that up, but lately, I've been able to refactor large files into several smaller files by rethinking their purpose. In most cases, I was trying to do too many different things in a single file.
Common pitfall of many programmers :)

Just look at source code available on the internet...especially old timer C programmers....their horrible :)

When I program in PHP I try and cut the files down in size from the get go...just for the sake of reducing parsing...and I find smaller files much easier to maintain :)

Cheers :)

Posted: Thu Nov 24, 2005 9:05 pm
by evilmonkey
AngusL wrote:Visual Studio 2005 you can shrink functions, classes etc. Can't remember if you can do this in previous versions. What you can do though, remember, is

Code: Select all

#define region "Region name"
which will let you shrink a part of your code.
Ditto for VS2003,

Code: Select all

#region "name"
'code
#End Region

Posted: Thu Nov 24, 2005 10:16 pm
by Ambush Commander
Agreed: source-folding only temporarily hides the issue. Of course, lots of files means you should definitely get an opcode cache.

Posted: Fri Nov 25, 2005 1:21 am
by josh
In dreamweaver 8 there is code collapsing, just highlight the code and hit collapse. Useful for things like:

Code: Select all

for ($i=0; $i<$count; $i++) {
     // 600 lines of code here
    
     // line you need to work on
}
when you want to look at the beginning of the loop and a line way down. Other then that, OOP design keeps file length to a minimum, each class def gets its own file, at the highest level all you see is the API