Re: Re: Function size

From: Date: Sun, 03 Jun 2012 14:32:41 +0000
Subject: Re: Re: Function size
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-318116@lists.php.net to get a copy of this message
"Tim Streater" wrote in message news:D0.7C.45755.25A3BCF4@pb1.pair.com...
On 03 Jun 2012 at 10:02, Tony Marston <TonyMarston@hotmail.com> wrote:
"tamouse mailing lists" wrote in message news:CAHUC_t__sW-_YHRw4n4UQR-fA46+CeBuNzGeHboaaTrafLA-2g@mail.gmail.com...
There is a point: if you are unfamiliar with code, wading through screens and screens of a function to find things like block beginning/ends makes for difficult time finding places where changes need to be made.
I *never* have huge numbers of lines between a block beginning and end. Even if I did my IDE can quickly find the other end of the block for me.
E.g. TextWrangler does this easily enough: just double-click immediately after an opening brace, and everything is highlighted to the closing brace.
- all those functions should be arranged in alphabetical order within their containing file - having them in a random sequence makes it difficult to find the one you want.
Also correct; this is a key point in making sure your scripts are maintainable.
Ah-ha! So someone agrees with me on that point after all.
+1
- when browsing through the code you have to keep jumping to another function, and then returning to where you came from. I don't know about you, but I would rather use the scroll wheel on my mouse than keep jumping from one position in the file to another.
May I suggest an editor/IDE that lets you navigate to functions directly, then?
I am *NOT* going to change my IDE just to suit *YOUR* preferences.
TW provided a popup list of your functions. It still helps to have them in alpha order though, for ease of navigation in the popup list. [snip arguments] I write functions to do specific things. E.g. I have a function (actually in JavaScript) called switchTab() which switches from one user view to another. It's just over 200 lines long and is mostly a giant case statement - and it's already loaded with function calls. I suppose I could break it up into five separate functions, more or less one for each case value, but then I'd have lots of unimportant local variables to pass around as argument values, and, what's worse, lots of unimportant functions cluttering the place up.
Exactly! That's one good reason *NOT* to break up a large function into artificially small pieces. You generate a lot of useless code just to handle the small pieces, and wading through lots of useless code makes it less readable. In my opinion it takes less effort to use the scroll wheel on my mouse than it does to jump/return from different parts of the file. There are times when it makes sense to split a large function into smaller pieces, but I'm afraid that doing so for no other reason than to satisfy someone's personal line limit is just not good enough. -- Tony Marston http://www.tonymarston.net http://www.radicore.org

« previous php.general (#318116) next »