Re: can't get it to work
Re: can't get it to work
- Subject: Re: can't get it to work
- From: Malcolm Fitzgerald <email@hidden>
- Date: Thu, 10 Apr 2003 10:51:19 +1000
On 4/9/03 1:02 PM, "John Delacour" <email@hidden> wrote:
theResult is a
very bad label for a variable. No variable should begin with "the"
and and the name of the variable should bear some close semantic
relationship to its contents. (the result) has a special meaning
While I understand the special relevance of "the result" in AppleScript, I
don't understand your first statement.
Do you have any basis for not using 'the' as a prefix for a variable name,
other than your own personal coding style/preference?
As far as I can see, the only reason would be to avoid confusion with
variable names and AppleScript's ability to ignore definite articles in
scripts, e.g. "theSelection" (a variable name, presumably related in some
way to a selected item) vs. "the selection" (AppleScript command that
returns the selection)
There are lots of good reasons - none of them laws. Here are a few
that you've already mentioned.
Using "the" as a prefix for a variable name:
* Interferes with your use of "the" as a part of the language - in
practical effect
* Displays a lack of clarity - not a big deal if you write perfect code
* Generates potential ambiguities - not a big deal until you want to
rework the code
Using "the" as a prefix is a particularly poor habit to adopt. Not
because it is wrong but because the penalties, when you make
mistakes, are so great.
Try these examples, the first few lines are set in single line
spacing for no other reason than to make the point that style does
matter: poor style makes hard work.
Feel free to add some line spacing to make it legible. :-)
-- well spaced code is not a law and the machine doesn't care. Why bother?
set the_reference to a reference to second item of {"a", "b","c"}
-- silly typo or deliberate code? It compiles.
-- Did I mean to change the_reference or to set a new variable?
set the _reference to a reference to third item of {"a", "b","c"}
(* line spacing is ONLY a matter of style *)
-- Problem: awkward syntax
-- the "the" prefix interferes with ordinary language use
-- using the article "the" is correct language use. Should it be avoided?
-- Which "the" would you remove to make it clear?
get the the_reference --> item 2 of {"a", "b","c"}
get the contents of the the_reference --> "b"
-- Problem: Typing errors, ambiguous code
-- what clues do we have to determine which code snippet contains a
typing error in the examples below?
-- example A
get the contents of the reference --> reference
get the contents of the_reference --> "b"
-- example B
get the reference --> reference
get the_reference --> item 2 of {"a", "b","c"}
--
More descriptive variable names help to overcome the potential
ambiguities and allow for full use of the language. The following
code becomes clearer without the benefits of syntax coloring. I've
used another element of the language as a prefix to show that the
stylistic rules aren't ever hard and fast, but some can be broken
with a smaller penalty.
set second_item to a reference to the second item of {"a","b","c"}
-- silly typo no longer compiles.
set second _item to a reference to third item of {"a", "b","c"} -->
expects class name
-- potential conflict with the correct use of the language disappears
get the second_item --> item 2 of {"a", "b","c"}
get the contents of the second_item --> "b"
-- typing errors generate compilation errors
-- this makes coding errors easier to discover and correct
-- example A
get the contents of second _item --> doesn't compile
get the contents of second item --> doesn't compile
get the contents of second_item --> "b"
-- example B
get second _list_item --> doesn't compile
get second_list_item -- item 2 of {"a", "b","c"}
--
Malcolm Fitzgerald
Database Manager
The Australian Society of Authors
phone: 02 9318 0877 fax: 02 9318 0530
http://www.asauthors.org mailto:email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.