|
Posted by n_macpherson on June 17, 2008, 8:25 am
Please log in for more thread options >
> First of all a proper indentation will provide even better guidance as
> to where the loop ends. And second a single block spanning 100 lines is
> just plain nuts. A classic rule of thumb used to be that if the code for
> a sub doesn't fit on VT220 screen, then it was too long and you should
> think about splitting it. There ware two reasons for this:
> - you don't want to keep scrolling up and down while thinking about this
> sub
> - anyting much longer becomes too complex for a single sub
>
> Granted, times have changed and typically you can display many more
> lines on modern terminals. But the second reason is still very sound.
> Many people will probably consider 30-50 lines of code to be the maximum
> length of code that can still be easily viewed and recognized without
> too much mental scrolling.
>
One of the reasons I am writing this script is because we have
introduced coding standards which specify a maximum of 300 lines per
function and 70 lines for a while/if/else/for loop and I need to
highlight places in our scripts where this occurs. I agree 300 lines
for a function is probably too long but in the language concerned
anything less than 200 would be completely impractical unfortunately.
The indentation is a good point - our developers mostly develop on
site which means a variety of editors ( UltraEdit, Visual Studio,
Notepad++, our own proprietary editor ) are used. This means
indentation across scripts becomes inconsistent. One of the functions
of the script I am writing will be to make sure the indentation
conforms to the coding standards.
> Why? Sounds like a perfect job for splice().
Yes - I'd forgotten splice() will allow me to insert into the middle
of an array (as I said I have been away from Perl for a little
while) . That should work fine for my purposes.
|