Re: Getting elements of a list
Re: Getting elements of a list
- Subject: Re: Getting elements of a list
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 16 Apr 2008 16:02:51 -0400
On Wed, Apr 16, 2008 at 3:39 PM, Stockly, Ed <email@hidden> wrote:
> What have you got against repeat loops? Repeat loops are our friends!
I have nothing against repeat loops. I just prefer to do things in
the simplest way. I think you and I have had the argument before
about what that means, in terms of expressiveness vs. simplicity of
the individual statements.
I prefer this line:
tell theList to set {item 1, item 2} to {item 2, item 1}
over these three lines:
set temp to item 1 of theList
set item 1 of theList to item 2 of theList
set item 2 to temp
Because it's clearer (at least to me) what the first one is doing.
The second one makes me think like a computer for a few lines to
figure out what the actual end goal is.
Similarly, this code:
set firstItems to the first item of every item of theList
seems clearer to me than this code:
set firstItems to {}
repeat with subList in theList
set end of firstItems to the first item of subList
end repeat
That's all.. As I said, nothing against repeat loops, happy to use
them where needed, just always on the lookout for a shorter idiom.
Obviously, you can make things too terse and fall out the bottom of
the legibility scale(*), too - it's a balancing act.
(*) Of course, when you fall out the bottom of that scale, where you
land is in an Obfuscated Perl competition. Caveat coder.
--
Mark J. Reed <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