This Forum is Dedicated For all The Object Oriented PIC Lovers .......... The concept behind OOPic is straight forward. Use preprogrammed multitasking Objects from a library of highly optimized Objects to do all the work of interacting with the hardware. Then write small scripts in Basic, C, or Java syntax styles to control the Objects. During operation, the Objects run continuously and simultaneously in the background while the scripts run in the foreground telling the objects what to do.

Sunday, July 20, 2008

Re: [oopic] Re: Optimizing code

On Jul 20, 2008, at 1:47 PM, rtstofer wrote:

>> I read somewhere in the docs that use of constants can save variable
>> memory, but if it ain't working I'll go with whatever is easier.
>
> THAT is true! To assign a constant to a variable and use it as a
> constant wastes the storage space of a Byte or oByte (Word or oWord,
> also).
>
> Dim MyNamedConstantInAVariable as new oByte
>
> sub main()
> MyNamedConstantInAVariable = 3 'and I will NEVER change it!
> end sub
>
>
> But whether you use a named constant (const MyConstant = 3) or a
> literal (3) in an expression would probably not make any difference at
> all:
>
> a = MyConstant
> versus
> a = 3

Unless you use it in multiple places and plan to tune that constant.
Invariably you use that constant in 6 places and then end up changing
it in 5, forgetting the 6th, which results in "anomalous behavior." :-)

> Named constants are nice because they help document the code. At
> least they should! Literals are to be avoided as a matter of
> practice. Many consider them 'magic numbers' and really hate to see
> them in code. It's often impossible to determine what they mean.
> Well, sometimes it is obvious but not always.

Yes. I try to get all my students to use variable and constant names
that help make the code self-documenting.

--

73 de Brian, WB6RQN
Brian Lloyd - brian HYPHEN wb6rqn AT lloyd DOT com


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/oopic/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/oopic/join
(Yahoo! ID required)

<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/

No comments: