Value & parentheses when doing math

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Value & parentheses when doing math

dunbarx via use-livecode
I have a tab delimited list where item 4 is a number and I'm adding things up. What is considered best practice when doing this?

add item 4 of line x of tList to tRunningTotal
or
add (item 4 of line x of tList) to tRunningTotal
or
add value(item 4 of line x of tList) to tRunningTotal

Marty
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Value & parentheses when doing math

dunbarx via use-livecode
The second one is more readable. The third is unnecessary. The first works just fine. It just depends on how readable you want to make your code for others. I always take the time to put values into their own variables so I can point at them in the debugger and see their current values in the stepper. So:

put item 4 of line x of tList into tValue
add tValue to tRunningTotal

seems to me to be more readable, at the expense of a little extra typing.

Bob S


> On Apr 2, 2018, at 14:48 , Knapp Martin via use-livecode <[hidden email]> wrote:
>
> I have a tab delimited list where item 4 is a number and I'm adding things up. What is considered best practice when doing this?
>
> add item 4 of line x of tList to tRunningTotal
> or
> add (item 4 of line x of tList) to tRunningTotal
> or
> add value(item 4 of line x of tList) to tRunningTotal
>
> Marty
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Value & parentheses when doing math

dunbarx via use-livecode
In reply to this post by dunbarx via use-livecode
Knapp Martin wrote:
 > I have a tab delimited list where item 4 is a number and I'm adding
 > things up. What is considered best practice when doing this?
 >
 > add item 4 of line x of tList to tRunningTotal
 > or
 > add (item 4 of line x of tList) to tRunningTotal
 > or
 > add value(item 4 of line x of tList) to tRunningTotal
 >
 > Marty

IMO whatever is the easiest to write and read that gets the job done is
the best option.

The first example above seems simplest to me.

The second one isn't bad, but the third one should be avoided unless you
have something in the data that requires the overhead of adding a call
to the value function.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Value & parentheses when doing math

dunbarx via use-livecode
the 2nd one is the one most readable to me so thats the one i would use

On Mon, Apr 2, 2018 at 6:08 PM, Richard Gaskin via use-livecode <
[hidden email]> wrote:

> Knapp Martin wrote:
> > I have a tab delimited list where item 4 is a number and I'm adding
> > things up. What is considered best practice when doing this?
> >
> > add item 4 of line x of tList to tRunningTotal
> > or
> > add (item 4 of line x of tList) to tRunningTotal
> > or
> > add value(item 4 of line x of tList) to tRunningTotal
> >
> > Marty
>
> IMO whatever is the easiest to write and read that gets the job done is
> the best option.
>
> The first example above seems simplest to me.
>
> The second one isn't bad, but the third one should be avoided unless you
> have something in the data that requires the overhead of adding a call to
> the value function.
>
> --
>  Richard Gaskin
>  Fourth World Systems
>  Software Design and Development for the Desktop, Mobile, and the Web
>  ____________________________________________________________________
>  [hidden email]                http://www.FourthWorld.com
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode