Re: Variable names
Re: Variable names
- Subject: Re: Variable names
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 12 Jan 2011 18:56:07 -0500
I think it's important to focus on the goals rather than the rules.
That means prioritizing and doing what's best in a given case, not
blindly following dogmatic prescriptions. As with the Pirate Code,
they're more what you might call guidelines. All things in
moderation, including single-character variable names and goto's.
On Wednesday, January 12, 2011, Stockly, Ed <email@hidden> wrote:
>> And that's all I have to say about that ;-)
>
> Oh goody, that means I get to have the last word!
>
>> 1. Yes, if you live in a vacuum and noone is EVER likely to read your script,
> you're not ever going to post it on this forum for help and you aren't going to
> read your script five minute, or five days or five months later, and you don't
> write anything complicated enough in which you might have to fix errors, 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.
>
> That is a good argument for following a disciplined approach to
> scripting/programming, but I've noticed that some of the most advanced and
> experienced scripters on this list will post quick solutions (shopping list)
> with non descriptive variable names, even single character names when not
> appropriate, to answer questions or make a point.
>
> I agree with Shane, no harm in that.
>
>> 2. Yes, the goal is TOTAL minimized time.
>
> That's a goal, not always the most important goal. There are often times
> when a scripter is working under a deadline and will have more time later to
> refine the script, but the immediate goal is to make something work before
> the presses run.
>
> Another goal is to make the script readable and easy to understand, and I
> believe using I or x or a, b, c properly helps more than descriptive
> variable names.
>
>> But I expect that in almost all cases a more clearly written script will pay
> for itself 100 or 1000 fold.
>
> That might be overstating it. Plus, many of the "shopping list" type scripts
> could be just a few lines long, and don't take any great effort to decipher,
> no matter what the variable names are.
>
> But the issue goes beyond whether clearly written scripts are more valuable.
> The other issue is whether following the guidelines on single digit variable
> names make a script less clear.
>
>
>> 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.
>
> But that's not always needed, and not always helpful.
>
> Tell page x of document 1
> Set text of paragraph y to myData
> End
>
> In most cases where I use the single digit name I use the variable at the
> start of the loop and never again. But even if it is used deeper in the
> loop I know it will always be an integer and used to reference a particular
> class of object.
>
> However, if I were doing a workflow and paragraph x of a document would get
> the value from row x of a spread sheet, and field x from a database, or some
> similar complexity, then yes I would use a more descriptive variable name.
>
> ES
>
>
>
>
> _______________________________________________
> 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
>
--
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