Number of lines before confusion

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Number of lines before confusion

Post 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 :)
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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!).
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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 :)
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: Number of lines before confusion

Post 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.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

Of course, breaking up large files into several smaller is better solution.
But line bookmarks helps a lot in large files.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post 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.
Last edited by Buddha443556 on Thu Nov 24, 2005 10:02 am, edited 2 times in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
AngusL
Forum Contributor
Posts: 155
Joined: Fri Aug 20, 2004 4:28 am
Location: Falkirk, Scotland

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Number of lines before confusion

Post 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 :)
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Agreed: source-folding only temporarily hides the issue. Of course, lots of files means you should definitely get an opcode cache.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
Post Reply