Re: coercing a list
Re: coercing a list
- Subject: Re: coercing a list
- From: email@hidden
- Date: Sat, 1 Sep 2001 16:40:56 -0400
On Fri, 31 Aug 2001 10:29:09 +1000, Ric Phillips <email@hidden>
noted,
>
> Didn't it used to have to be a list of strings? (well, I mean, a list of
>
> string)
>
>
>
Yes. and Richard made some excellent points in his post. But I learned
>
programming in the era of Knut's "Mythical Man Month" and I guess my
>
tendency is to simplicity, and readability.
That's Frederick P. Brooks as the author of "The Mythical Man-Month" (ISBN:
0201835959). That book is a classic, and describes how programming is a human,
social, and communications effort. He provided the notable quotes, "It takes
nine months to make a baby, no matter how many women you assign to the task,"
and
"Adding personnel to a late project will make it later" (because the
experienced, knowledgable people will now be explaining to the new folk rather
than working with what they know).
The book is well worth reading. Brooks states the problems clearly, and they
are perennial problems. But readers should realize that the solutions he
proposes are just early attempts, and modern methodology has provided many more
tools. (Its like Galileo, who described the problems of dynamics, but Newton
provided the tools of calculus to solve them.)
>
I also wanted the script object
>
I posted to make my code more readable (hence 'with' over 'given') and
>
intuitive (hence forcing a string). I always optimise my code for
>
maintainability-at-a-later-date over execution efficiency. It's a matter of
>
philosophical preference, and my approach certainly discards some of the
>
functionality of TIDs by accepting only strings, but in 99.9% of cases, a
>
single character string is what I intend a TID to be.
Good software engineering practices are something I think most scripters need to
know, even if they don't work in teams, and work within a formal development
environment. Maintenance should be very important to a scripter. Even if no
one else will read the script, the author will, probably six months or two years
later, when all those implementation details have been forgotten.
In this specific case, there is an issue of style, which is part a scripting
thing, and part a dynamic-typing thing. Strongly-typed ("bondage and
discipline") languages would make you say, "It should be a string. Give a
string as the input. Don't argue." But the AppleScript way would be more like,
"Give a string or something that can be meaningfully coerced into a string."
Maybe in a large software project, catching an error where a list is used when a
string was intended is a valuable thing, but here its more of an unnecessary
exposure of details about the internals of a module, and thus bad.
(Historically, this represents the issues structured programming tried to
address, versus the issues object-oriented programming addressed.)
Of course, "Real programmers can write FORTRAN in any language," and everyone's
experience colors their individual style.
>
As for anyone unfamiliar with or learning about Text Item Delimiters - even
>
if you use the code I posted - do read the other posts in this thread
>
because there is some good info there.
TIDs are powerful, but always smell like software trickery to me. (Kind of like
my favorite APL one-liners.) Usually, scripters use them when trying to avoid
using a Scripting Addition command like Akua Sweet's "decompose" command or one
of the regular expressions commands. As if using a third-party osax was the
sign of moral decay, like having machine-sewn fabric in your Civil War
re-enactor uniform, or serving vinigrette salad dressing at a wine tasting.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden