• 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: Can someone explain this?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can someone explain this?


  • Subject: Re: Can someone explain this?
  • From: Bruce Brown <email@hidden>
  • Date: Fri, 20 Mar 2009 18:29:10 -0700

If you'll all permit a list newbie and computer "old-timer" to jump in here ...

I've been following this thread from the start, with much interest.

I'm a long-time (and long ago) programmer, and long-time Mac person, but I'm relatively new to AS, and very new to this list.

I can't comment on excluding/including the "the," except to say that, any language that depends on an English article being used or not used to determine the interpretation is lacking in clarity of language design. Moreover, if the "the" MUST be used in some places, MUST NOT be used in other places, and is OPTIONAL in still other places, well--that's a recipe for disaster, in my book. Ideally, the "the" should be optional everywhere, even if removing it everywhere makes the program read like it's been written in some kind of broken, Pidgin English. Broken English or not, it should still do what it's supposed to do, and what the programmer expected it to do.

I'm not sure if the above is the case with AS, but, if it is, well, then, I'd call it a design deficiency in the language, which is worse (to me) than just a simple bug that only affects one statement, verb, noun, or other construction of the language.

I WILL, though, comment on the arithmetic expression, "-2^3" and its expected or unexpected result in a computer program:

As we've seen, there are many languages that interpret this in one way, and several others that interpret this in the exact opposite way. Thus, there's no apparent consensus among programming language designers on this point.

Regardless of how ANY specific language interprets this expression, though, I think the overarching lesson here is never to rely on the compiler to get something like this the way you want it! Even if you *know* how a given compiler interprets it (because you've run some simple test cases, perhaps), doing so should be considered bad programming practice! Here's why: Even if the compiler gets it right NOW, what happens when that compiler is revised in the future? Suppose Apple (or whomever) revises their language, perhaps in response to a bug report; then what? Will your script still work correctly? Or, will it "break" under the new version of the compiler?

Here's another question: Even if you get lucky and your program happens to work correctly NOW, as well as working correctly with current and future versions of the compiler, how would another programmer reading your code interpret the expression "-2^3" ? Could you be certain that he/she will interpret that expression the same way you did?

And, even if you're the only one who will be reading your code, don't forget that, in 2 to 6 months, you're a different person! By that, I mean, you might not be sure of what your own intention was, a few months hence!

So, one should write either

(-2)^3 [if that's what you want; -2 raised to the third power]

or

-(2^3) [if this is what you want; the negation of 2 cubed]

and never write

-2^3

In sum, it's always good to write code that's clear and unambiguous, both to the compiler and to another human reading it. For arithmetic expressions, that includes adding parentheses to improve readability even in places where they might not be required.


Looking forward to following many more threads on this list,

-B.

Bruce Brown
Mac Computer Consultant

On Mar 15, 2009, at 10:04 AM, email@hidden wrote:


As previously noted, the only documented exception for the non- optionality of 'the' is 'the clipboard' and all other documented usage is optional. All in all, I think it would be better if 'the clipboard' migrated to 'pasteboard' and 'the' is always optional. Then there will be zero exceptions to remember and more time to concentrate on the scripting task at hand.

That is not accurate. The "the" is optional. The command works just fine without it, it is not required, so it is optional. The issue is that using it changes the behavior of the command in an unexpected way. There are many cases where inserting the word "the" will interfere with a command.


choose file
choose the file

One compiles and one doesn't. This case is very much the same. "end of [a list]" is the command used to get the value of the last item of the list, but in Michelle's script she was using it to provide an index for the last item. It's kind of cool it works that way at all and when it doesn't work it's usually pretty clear, but if the list is formatted this way:

set myList to {"a", "b", "c", pi as text, 3}
items 1 through the end of myList

The command compiles and runs without an error but provides an incorrect result. So, in my book, that makes it a bug.

The work around is to use "-1" rather than 'the end" for index. For example:

This syntax:

items 2 through last item  of myList

Compiles as this:

items 2 through -1 of myList

But this syntax:

items 2 through the last item of myList

Compiles as is, but has the same behavior at runtime as Michelle's version.



ES

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript- email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com
Archives: http://lists.apple.com/archives/applescript-users


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: Can someone explain this?
      • From: "email@hidden" <email@hidden>
    • Re: Can someone explain this?
      • From: Michelle Steiner <email@hidden>
References: 
 >Re: Can someone explain this? (From: "Nigel Garvey" <email@hidden>)
 >Re: Can someone explain this? (From: Philip Aker <email@hidden>)
 >Re: Can someone explain this? (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: Removing iPhoto 08 Keywords with Applescript
  • Next by Date: Re: Can someone explain this?
  • Previous by thread: Re: Can someone explain this?
  • Next by thread: Re: Can someone explain this?
  • Index(es):
    • Date
    • Thread