Re: Variable names
Re: Variable names
- Subject: Re: Variable names
- From: BareFeetWare <email@hidden>
- Date: Thu, 13 Jan 2011 17:01:21 +1100
> On 13/1/11 9:38 AM, "BareFeetWare" <email@hidden>
> wrote:
>
>> 1. Yes, if you live in a vacuum and noone is EVER likely to read your script ... then communication doesn't matter, and you could call all of your variable and handler names x1, x2, x3, x4 etc. I still think it's unnecessarily obfuscated, but no harm done since noone will ever have to understand what you wrote.
On 13/01/2011, at 10:51 AM, Shane Stanley wrote:
> You're attacking a straw man. You're describing an extreme that no-one has advocated.
Oh, my mistake. I did think it was an extreme, but I thought that's the situation your were describing, with statements like:
>>> You keep assuming that every script will be revisited, but I'd say only a small percentage of the small ones I write are.
In my experience, almost every script is revisited, a few seconds, minutes, days or months later. But your experience seemed to differ. I interpreted your experience as mostly being never revisited, in which case clarity doesn't matter. Sorry if I misunderstood.
> I'm merely suggesting that things like "repeat with i ..." often do no harm
Agreed. No harm... if no one else not in that exact head space has to understand it. If the author or anyone else has to understand it without the cached variable descriptions in their head, then I think it's just an unnecessary waste of total time. I wouldn't condemn anyone for it, indeed I've done it myself, but ideally I suggest it's better to take a few seconds to use descriptive variable names, structure loops and if/then elegantly etc.
> and that not every project needs to be approached with the same discipline.
Obviously the requirement scales according to the need, but even small scripts benefit from thoughtful design.
> He does quite a good job with x, y and even the occasional L.
Ed's earlier post with sample loop variables also does "quite a nice job" with x, y etc. I've also published AppleScript educational pieces. In the case of just teaching the syntax (such as a repeat loop), it is usually without context, so you can't really use a descriptive variable name. But as soon as you have context I suggest describing the variable's meaning within that context.
>> 2. Yes, the goal is TOTAL minimized time. If it truly takes you precious
>> minutes to think of a meaningful variable name and there is no time saving for
>> you or anyone else to understand it later, then use whatever short names you
>> like. But I expect that in almost all cases a more clearly written script will
>> pay for itself 100 or 1000 fold.
>
> This is religious talk. 1000 fold? So a script that took, say, 15 minutes to write from scratch will be understandable in 1/1000th the time solely because of variable names?
No, I'm saying that in a script that takes 15 minutes to write, the extra five seconds it takes to write descriptive variable names will save cumulative time that is 100 or 1000 fold (ie 500 or 5000 seconds). That saved time can accumulate though less programming errors since it's more clear to the author what's going on, or saved debugging time or saved interpretation time when you post a script to a mail list with 100 readers.
>> 3. Most arguments for short non-desriptive variable names seem to quote a line
>> and say that in that context it's perfectly clear what the variable does. But
>> my point is that a descriptive variable name makes it clear on EVERY line what
>> the variable does.
>
> No, it (hopefully) makes it clear what the variable contains. And sometimes
> it can actually add to the confusion: a variable with an obvious meaning to
> one person can have a totally different meaning to another. This happens
> enough in English. And that ignores the cases where perhaps the name was
> ill-advised -- but of course that never happens in real life.
Um, I totally agree with you. You seem to be arguing my point. If a variable name creates confusion or isn't descriptive enough, then it's a bad choice. But I would advocate choosing more descriptive and clear variable names rather than resorting to no description at all (ie single letter).
Others have retorted more eloquently and entertainingly than I. I've spent too much time on this already, but thank you for the debate.
Gotta get back to finishing my app in Cocoa, calling libraries that use quite verbose but thankfully very descriptive variable and method names. God bless the Apple engineers for their forward thinking ;-)
Thanks,
Tom
BareFeetWare
--
Comparison of SQLite GUI tools:
http://www.barefeetware.com/sqlite/compare/?ml
_______________________________________________
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