Opinions on style Please, Professionals welcome

Hi all,
I am looking for some opinions, so if you want to opine at length feel free. I am wondering what is the best way to build some script files. For example, I have an application that I’m building, it has about 21 functions. The MAIN function that really does the process (which involves exporting things from InDesign) runs about 240 lines. I now find myself needing to do some major refactoring to maybe break out some functions, that I once assumed would be contained in the main function, to be able to be separate and called by another function.

Soooo, my question is, how do you guys set up a large script/app? Do you try to break things down into very small functions with lots of return values or globals? Do you often have a large function that does the majority of the script’s work? As I’m learning Objective-C/Cocoa I see many very short functions, and this is coloring my Applescript now to lean towards smaller functions in general. But often I find that I need to employ tons of globals because 1 return value just doesn’t cut it.

TIA, Chris

When I started writing AppleScripts (seven years ago), I put everything in one script file containing a large main function. Of course this scripts were not easy to maintain and the code snippets not reusable in other projects.

Things got better over time, but I really changed my coding style when I started to learn other programming languages like Python/PHP/Perl. Once you get in touch with «real» OOP (classes, subclasses, etc.), you realize that it is way better to have small, reusable functions and convenient libraries.

So today my main functions are quite small, but almost all of my own scripts are importing custom libraries at startup, which makes things a lot easier for me. Development times are reduced and I can fix bad code in ONE place. Often when I am asked to provide a script, I can do it in minutes, as I already have a lot of ready-to-use building blocks around.

Nevertheless this approach is more work in the beginning, as you have to design and document routines for general use, but in my opinion it pays off quickly.