Re: Variable names
Re: Variable names
- Subject: Re: Variable names
- From: Doug McNutt <email@hidden>
- Date: Wed, 12 Jan 2011 10:21:47 -0700
At 21:22 -0600 1/11/11, Stockly, Ed wrote:
>---------
>-- The tip calculation
>
>if serviceLevel is "outstanding" then
> set tipPercent to 20
>else
> set tipPercent to 20
>end if
>
>set tipAmount to billTotal mod tipPercent
>---------
Is " tipPercent" set to the integer 20, or does it become 0.20 as a float?
So you take the billTotal and divide it, in integer mode, by 20 and say the tip is the remainder of that calculation. I'm sorry but without some new definition of the "mod" operator that's just plain wrong.
Is billTotal the amount that goes to the credit card company. Or is it billTotal plus the calculated tip?
That choice is non-trivial and both procedures are used in trade and taxes.
I do believe that obfuscated C would be more readable. Or perl.
$VISA_charge = $billTotal * (1 + $tipPercent / 100); #What you probably mean.
$billTotal = $agreed_on_price / (1 - $tipPercent / 100); # The Fair Tax procedure.
Mantra. . . Define your variables in a comment and then be consistent. There are good reasons why older languages absolutely require declaration of variables before they can be used.
*****
And while I'm at it the use of i j k l m n to point compilers to index registers is long gone unless you're working with the likes of 8 or 16 bit microprocessors which are still pretty common - and more fun to work with than Applescript..
--
--> If you are presented a number as a percentage, and you do not clearly understand the numerator and the denominator involved, you are surely being lied to. <--
_______________________________________________
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