Variable names (was: How to do a goto with Applescript?)
Variable names (was: How to do a goto with Applescript?)
- Subject: Variable names (was: How to do a goto with Applescript?)
- From: BareFeetWare <email@hidden>
- Date: Wed, 12 Jan 2011 12:47:05 +1100
On 11/1/11 3:48 PM, "BareFeetWare" <email@hidden>
wrote:
>> I don't care whether you're writing a 10 line script, a 10MB application, writing a shopping list or telling a story. Good communication is an art and shows value on time, value for others, and value for the artform. Bad communication is inconsiderate, short sighted and lazy or ill informed.
On 11/01/2011, at 5:25 PM, Shane Stanley wrote:
> So you'd abuse someone in the supermarket for having a sloppy shopping list? You're a hard task-master.
LOL, no, I wouldn't abuse them. But if someone gave me a shopping list that was not descriptive enough, I would waste time trying to guess "what do they mean by 'drink' and which 'snack' do they want?" OK, I might abuse them under my breath ;-) Sure, it might have been clear to the author when they wrote it, but why not take the extra second to describe the item in the shopping list or the variable? It will save minutes or hours later. If I was both the author and the reader, the advantage of clear (non ambiguous) instructions would increase with the time between the writing and reading (eg "I can't remember what type/brand of 'pasta' we need. I wish I had written more info").
> No-one is arguing with the motherhood statements about writing good, clear code. But one size doesn't fit all: you *can* write a decent, serviceable
> shopping list without following the rules required to tell a story.
True. Obviously there are different rules or conventions or requirements for a story vs shopping list vs script vs program. But don't get too caught up in my analogy ;-) The one universal guideline I'm advocating is to make the instructions as unambiguous and elegant as you can, where the writing effort is less than the saved interpretation effort.
You *can* write whatever you like, but that doesn't mean you *should*.
> More, I suspect people are more likely to learn good habits by experience than by being hectored and called inconsiderate, short sighted and lazy.
No offence intended. OK, I'll call myself inconsiderate, short sighted and lazy. A long time ago, I used short non-descriptive variable names. I wasted a lot of time trying to debug or understand a script some time after I wrote it. I exclaimed "what inconsiderate, short sighted and lazy person wrote this?... oh, it was me. Gee, I wish someone had told me early on what a bad habit it is so I could save wasted time." I also changed my habit because it was easier to explain to coworkers what my scripts did.
> Applying the appropriate amount of intellectual force to a project doesn't seem such a bad approach to me...
Communication is an intellectual process. I'm advocating applying small intellectual force to the writing of the communication, rather than requiring unnecessary and far greater intellectual force to interpret it.
I've just now looked at the "setBounds" script that seemed to spark this conversation. It seems that it actually uses descriptive variable names in most cases, which makes it much easier to read. For instance, I know immediately the purpose of this:
set TwentySevenInchMonitor to true
but I had no idea what triggers this beep:
if x = "" then
my makeBeep(currentVolume)
return
end if
So I had to look back for the definition of x and then try to figure out what it did:
set x to (info for (path to frontmost application))'s short name
By contrast, it would have taken the author a few seconds to simply use a descriptive variable name such as: applicationName.
Thanks,
Tom
BareFeetWare
_______________________________________________
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