Re: OO Theory misconceptions (was Re: can I make a list of
Re: OO Theory misconceptions (was Re: can I make a list of
- Subject: Re: OO Theory misconceptions (was Re: can I make a list of
- From: "Jason W. Bruce" <email@hidden>
- Date: Sat, 02 Feb 2002 18:05:35 +0000
has wrote:
>
> I think this feature is present in the language. If you load a script as a
>
> parent to the current script, the loaded script's implicit run handler will
>
> execute:
>
>
>
> property parent: load script file.lib
>
>
Not so - "load script" merely returns a specified script object; it does
>
not invoke its run handler. Maybe you're getting confused with the
>
operation of AS's inheritance scheme: where if your child script has no run
>
handler of its own (either implicit or explicit) then it will call its
>
parent's run handler (if any) at runtime.
We may be talking semantics here, but did you know that all scripts (and
script objects) have run handlers? If a script doesn't define an explicit
run handler, it has an implicit run handler -- meaning that its top level
commands will execute when it is told to run.
What Tim Bates wanted was a mechanism which caused a loaded script to
initialized itself when loaded. If I write a script as follows -- set x to
10 -- and save it as a compiled script, and then create a new script which
loads that compiled script as a parent, the result window shows 10 when I
run the child script from Script Editor -- which I think means that the
child script called the parent script's implicit run handler and which I
think can be used to accomplish what Tim was wants.
>
You can take advantage of AS's OO foundations even when writing purely
>
procedural code. One of the nice things about AS is it's very flexible,
>
allowing you to use either procedural or OO programming techniques however
>
you see fit. AS provides scripters with a high level of "home comforts", if
>
you like.
Again, I think we're talking semantics. As I see it, people are always
doing OO in AppleScript -- they just don't realize it; nearly everything in
AppleScript follows the OO metaphor, but AppleScript tries to hide this so
that people aren't intimidated.
>
> So the next level of
>
> organization is to break these handlers into groups and put them into script
>
> objects.
>
>
There's nothing inherently OO in spreading your code across multiple files
>
to make it easier to manage. You can do the same in C (a non-OO language),
>
for example; the compiler simply pulls everything together at compile time.
No, no, you don't have to spread your code across multiple files. All your
script objects can be in one script file. If you've got a very long script
which runs for panes and panes of your script editor, and you've broken it
down into chunks of self-contained script objects, all you have to do to
make a change or add a feature is to copy that chunk of code into a new
script, modify and debug it until it does what you need, and then plop it
back in.
>
Well, what you have there is good-quality structured programming - you
>
might be exploiting some of the language's OO underpinnings in the process,
>
but your design is still procedural.
Damning me with faint praise, eh? : ) If you're a lone scripter who is
not working with a team of programmers on a large project (which is nearly
all of us), I predict that after you really explore all this OO stuff -- as
I have -- you'll see that there is no real magic to it, and that what we're
really dealing with here is a question of semantics and metaphor.
Jason Bruce