Programing style
Dar Scott
dsc at swcp.com
Thu Nov 16 16:47:03 EST 2006
On Nov 16, 2006, at 2:01 PM, Hershel Fisch wrote:
> Hi all, I'd like to know how others write a function like this.
That looks pretty good.
As far as style, I'd only do a couple things differently.
First I'd use a parameter name like this
function fNumericToMoney n
or this
function fNumericToMoney pUnformattedNumber
and then use the parameter all places where you now use tParam and
get rid of the param() line.
(I don't use the hungarian prefixes, but they are OK.)
I wouldn't use f for a function prefix. There is a precedence for
names like numberToMoney(), numToChar() for example. I do that.
However, when I can, I try use a name that describes the result such
as money() or formattedAsMoney.
Names like tC and tTs are a little short to understand but are OK in
this case. I would might use slightly larger names.
(I assume the 'add 3 tC' is a typo.)
I would sometimes check whether the parameter is a number in the
right range and maybe even give it a default value if it is empty or
missing. That is less important for private functions.
Is that what you were looking for.
Over all this looks good. And the indenting is pretty clever; how'd
you think of that?! :)
(This is no comment on whether all that works.)
Dar
More information about the use-livecode
mailing list