• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Script Libraries
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script Libraries


  • Subject: Re: Script Libraries
  • From: Simon Forster <email@hidden>
  • Date: Tue, 9 Nov 2004 10:06:20 +0000


On 4 Nov 2004, at 18:07, has wrote:

Simon Forster wrote:

Grazing through the list I read one of HAS's posts concerning the
loading of libraries and making sure that they don't have cross
dependencies.

...

Look up the terms 'cohesion' and 'coupling' as they relate to programming, either in a textbook or online. Good code has high cohesion - each component (function/class/module) has a single, well-defined purpose - and low coupling - each component has few connections to other components. (There's absolutely no shortage of literature on this stuff, so you needn't rely on my hamfisted attempts at explaining it.;)

Having done a search on this, it seems that your description is pretty spot on!


I have a script which uses 4 different libraries - libFinder,
libString, libMisc and another which I've forgotten. So we have 3
libraries ;-)

I'd immediately be wary of any module named 'libMisc' - the name alone strongly suggests poor cohesion.

Hmm. You're right at the script library level but wrong at the function level. I've been treating script libraries as a collection of like minded functions - so libString deals with string (text) functions, libFinder with Finder functions etc. However, my main script (for this particular project) has minimal functions of its own - hence libMisc. Arguably, the functions defined in libMisc would be better placed in the main script - but they're not. So there ;-)


These libraries are loaded by the main script and assigned to globals.

Don't want to get sidetracked into implementation issues here, so please refer to the following posts to the Studio list for an explanation of why you should never use globals in modules:


http://lists.apple.com/archives/applescript-studio/2004//Nov/ msg00016.html
http://lists.apple.com/archives/applescript-studio/2004//Nov/ msg00018.html

Stuck. I'm assigning the script libraries to globals as in:

set libString to load script alias...

Arguably, comparable to include directives in other languages. As there is _some_ coupling (<--new word usage from Simon!!) between functions, the coupled functions reference the global variables containing the script libraries. The only alternative is to pass the library(s) as arguments to each of the functions. While possible, this is going to make the code less legible. As >50% of my time is spent on admin / maintenance, I like to keep my code as clean and as commented as possible.

What mechanism do you propose (barring the use of a third party app such as Loader written by someone nearby), to reference libraries of routines?

Some of the handlers in the libraries use functions defined in other
libraries.

Libraries having dependencies on other libraries is not in itself a bad thing. There is not a problem, for example, in library A using library B and your main script using both A and B. You can write and test library A in isolation first. Once you're happy with that, write and test library B, and when that's done finally write and test the main script. If, however, A is dependent on B *and* B on A, you can't test anything until A and B are both done. You've gained nothing over writing both as a single script.

<Nod \>

Couldn't agree more. Being lazy, I wanted to make sure that I was doing things which support this habit. Seems like I am with respect to coupling (twice. See. Twice).

Anyway, thank you very much for your time to date. I've learnt something new - which is always gratifying.

All the best

Simon Forster
_____________________________________________________
 LDML Ltd, 62 Pall Mall, London, SW1Y 5HZ, UK
 Tel: +44 (0)70 9230 5244   Fax: +44 (0)70 9230 5247
_____________________________________________________

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Script Libraries
      • From: has <email@hidden>
References: 
 >Re: Script Libraries (From: has <email@hidden>)

  • Prev by Date: Re: Can a handler return more than one result?
  • Next by Date: AppleScript and Safari
  • Previous by thread: Re: Script Libraries
  • Next by thread: Re: Script Libraries
  • Index(es):
    • Date
    • Thread