Naming conventions for optional parameters
Ken Ray
kray at sonsothunder.com
Mon May 26 14:01:00 EDT 2003
Dar,
Good question. In things like Visual Basic, these are specifically
spelled out:
Public Sub Toast(Toaster as String, Optional Temp as Integer, Optional
Butter as Boolean)
I don't necessarily see the need to have different prefixes based on
whether they are "tail-optional" or "empty-means-default", since usually
"empty-means-default" params are handled right at the top of the
handler, like:
on toast pToaster,pTemp,pButter
if pTemp = "" then put "95" into pTemp
...
end toast
So perhaps a single character prefix, like "o" for "optional":
on toast pToaster,oTemp,oButter
if oTemp = "" then put "95" into oTemp
...
end toast
I've also seen it where underscores are used:
on toast pToaster,_Temp,_Butter
if _Temp = "" then put "95" into _Temp
...
end toast
Either way, I think it would be a good addition to the "hungarian
notation" scripting style guidelines...
Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
> -----Original Message-----
> From: use-revolution-admin at lists.runrev.com
> [mailto:use-revolution-admin at lists.runrev.com] On Behalf Of Dar Scott
> Sent: Monday, May 26, 2003 1:11 PM
> To: use-revolution at lists.runrev.com
> Subject: Naming conventions for optional parameters
>
>
> I noticed at here...
>
> http://www.fourthworld.com/embassy/articles/scriptstyle.html
>
> ... a naming convention in which parameters are named as such:
>
> pLength
>
>
> I wonder if folks use an alternate prefix for optional parameters.
>
> These usually fall into two classes.
>
> The first is the tail-optional group. These are dropped from the
> right. They may contain empty which is distinct from being missing.
> These are tested with paramCount().
>
> The second is the empty-means-default group. These may be replaced
> with empty at any place in the parameter list and also may be dropped
> from the right. These are tested with "is empty".
>
> I'm considering using an alternate prefix for these. Will
> this help or
> will it muddy the waters?
>
> Maybe, to comply with the above, they can be "pt" and "pe".
>
> Example:
>
> on toast pToaster, peTemperature, pBread, peNumber, ptProfile,
> ptAnnouncement, ptReport
>
> An alternative that doesn't use prefixes is this (which
> limits classes
> to one):
>
> on toast pToaster, pBread, /* optional: */ pTemperature, pNumber,
> pProfile, pAnnouncement, pReport
>
> Dar
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-> revolution
>
More information about the use-livecode
mailing list