1. Best Practices Issue

Okay, time for everybody to express their opinion...

In what circumstances, if any, might you allow controls to take the place of
variables? In what circumstances, if any, might you not?

Simple Example:

I have a window with a single edit text control. A user types '3' into it.
There are two ways to deal with this value: 1) Assign it to a variable and
use it that way, or 2) use it directly from the control (no variable
required).

So, what do you do and why?

new topic     » topic index » view message » categorize

2. Re: Best Practices Issue

> I will typically use the value directly from the control if I only need
> to reference the value 1 or 2 times top.
>
> If I need to reference the value in another routine (maybe with a global
> variable) or need to reference the value more than 2 times within a
> function I'll assign to a variable.  This reduces clutter, makes the
> code easier to read and also allows me to ? the value of the variable in
> debug.  It also helps with performance as you're not having to call
> getText() multiple times.

Hey, Jonas, thanks for the response. Here's a follow-up for you (and anybody
else who wants to chime in): what do you do if a value changes in your
variable, but not as a result of the control itself? For example, let's say
we have txt_Total (a text box that is uneditable by the user and whose value
is equal to the sum of four other text boxes). Let's say you've decided to
use variables to track your control values (or rather, control values are
determined by certain variables). When do you check for and update the
control value? Basically, how do you update control values based on
variables that have no onChange() event?

new topic     » goto parent     » topic index » view message » categorize

3. Re: Best Practices Issue

On Fri, 7 Feb 2003 12:29:48 -0600, "C. K. Lester" <cklester at yahoo.com>
wrote:

>Hey, Jonas, thanks for the response. Here's a follow-up for you (and =
anybody
>else who wants to chime in): what do you do if a value changes in your
>variable, but not as a result of the control itself?
Umm.... shades of pondering that come back to haunt me. I hang my head
in shame to remember I once expected this to be someone else's
responsibility.....

If you have for example say:

integer txt_Total

	txt_Total=3D3
--[1]
	...
	txt_Total=3D5
--[2]
	...
	txt_Total=3D7
--[3]

You cannot (would not and do not) expect an "event" to be generated at
points [1], [2], and [3].  You quite obviously just code it yourself.

The point is, anywhere you do a setText() or similar, you must have
all the code to handle the changes *your* program just made, sorry.

Embarrassingly obvious once you think it through smile

Pete

new topic     » goto parent     » topic index » view message » categorize

4. Re: Best Practices Issue

> On Fri, 7 Feb 2003 12:29:48 -0600, "C. K. Lester" <cklester at yahoo.com>
> wrote:
> 
> >Hey, Jonas, thanks for the response. Here's a follow-up for you (and anybody
> >else who wants to chime in): what do you do if a value changes in your
> >variable, but not as a result of the control itself?


Isn't that what OOP was all about? If you accessed a variable, and it had an 
associated method, which was inherited, code was run to automagically do 
these things among all the sub-objects that were inheriting the same 
method?

o = object
.setmethod = o = a + b + c

a = descendant of o
b = descendant of o
c = descendant of o

a = 1
b = 1 
c = 1
-- o = 3
a = 2
-- o = 4

I know my terms are wrong, i stopped oop'ing about a decade ago. Oop can 
be handy, but simulated where it's not available.

Kat

new topic     » goto parent     » topic index » view message » categorize

5. Re: Best Practices Issue

Unless you use a custom type and use side effects that is ...
... but even that is not recommended (not to mention, messy coding). :/

jbrown

On Fri, Feb 07, 2003 at 11:46:40PM +0000, Pete Lomax wrote:
> 
> On Fri, 7 Feb 2003 12:29:48 -0600, "C. K. Lester" <cklester at yahoo.com>
> wrote:
> 
> >Hey, Jonas, thanks for the response. Here's a follow-up for you (and anybody
> >else who wants to chime in): what do you do if a value changes in your
> >variable, but not as a result of the control itself?
> Umm.... shades of pondering that come back to haunt me. I hang my head
> in shame to remember I once expected this to be someone else's
> responsibility.....
> 
> If you have for example say:
> 
> integer txt_Total
> 
> 	txt_Total=3
> --[1]
> 	...
> 	txt_Total=5
> --[2]
> 	...
> 	txt_Total=7
> --[3]
> 
> You cannot (would not and do not) expect an "event" to be generated at
> points [1], [2], and [3].  You quite obviously just code it yourself.
> 
> The point is, anywhere you do a setText() or similar, you must have
> all the code to handle the changes *your* program just made, sorry.
> 
> Embarrassingly obvious once you think it through smile
> 
> Pete
> 
> ==^^===============================================================
> This email was sent to: jbrown1050 at hotpop.com
> 
> 
> TOPICA - Start your own email discussion group. FREE!

-- 
 /"\  ASCII ribbon              | 
 \ /  campain against           | Linux User:190064
  X   HTML in e-mail and        | Linux Machine:84163
 /*\  news, and unneeded MIME   |

new topic     » goto parent     » topic index » view message » categorize

6. Re: Best Practices Issue

C.K.,

You could set a timer to check the variables?  But I'd check first to be
*sure* there's no event you could trap.

Dan Moyer

----- Original Message -----
From: "C. K. Lester" <cklester at yahoo.com>
To: "EUforum" <EUforum at topica.com>
Subject: Re: Best Practices Issue


>
> > I will typically use the value directly from the control if I only need
> > to reference the value 1 or 2 times top.
> >
> > If I need to reference the value in another routine (maybe with a global
> > variable) or need to reference the value more than 2 times within a
> > function I'll assign to a variable.  This reduces clutter, makes the
> > code easier to read and also allows me to ? the value of the variable in
> > debug.  It also helps with performance as you're not having to call
> > getText() multiple times.
>
> Hey, Jonas, thanks for the response. Here's a follow-up for you (and
anybody
> else who wants to chime in): what do you do if a value changes in your
> variable, but not as a result of the control itself? For example, let's
say
> we have txt_Total (a text box that is uneditable by the user and whose
value
> is equal to the sum of four other text boxes). Let's say you've decided to
> use variables to track your control values (or rather, control values are
> determined by certain variables). When do you check for and update the
> control value? Basically, how do you update control values based on
> variables that have no onChange() event?
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>

new topic     » goto parent     » topic index » view message » categorize

7. Re: Best Practices Issue

On 7 Feb 2003, at 18:21, Dan Moyer wrote:

> 
> C.K.,
> 
> You could set a timer to check the variables?  But I'd check first to be
> *sure* there's no event you could trap.

In mirc, i trap /msg and /set 

In this way, and with mirc's ability to know the names of the vars (see the Eu 
associated lists in the Eu archives), i can know what the code sent to 
channels or people, and decide what to do to other vars when any one var is 
set. I pulled off some programming tricks that stunned Khaled (i know this 
because he asked me how i did it, because it alledgedly wasn't possible). 
That was without disclosing any self-modifying scripts. I know people will 
reject this suggestion again, but haveing mirc and Eu features in one 
language would be dynamite. I can keep on doing things like that in mirc tho, 
and use Eu only when hitting a mirc shortcoming.

Kat

> 
> Dan Moyer
> 
> ----- Original Message -----
> From: "C. K. Lester" <cklester at yahoo.com>
> To: "EUforum" <EUforum at topica.com>
> Sent: Friday, February 07, 2003 10:29 AM
> Subject: Re: Best Practices Issue
> 
> 
> > > I will typically use the value directly from the control if I only need to
> > > reference the value 1 or 2 times top.
> > >
> > > If I need to reference the value in another routine (maybe with a global
> > > variable) or need to reference the value more than 2 times within a
> > > function
> > > I'll assign to a variable.  This reduces clutter, makes the code easier to
> > > read and also allows me to ? the value of the variable in debug.  It also
> > > helps with performance as you're not having to call getText() multiple
> > > times.
> >
> > Hey, Jonas, thanks for the response. Here's a follow-up for you (and
> anybody
> > else who wants to chime in): what do you do if a value changes in your
> > variable, but not as a result of the control itself? For example, let's
> say
> > we have txt_Total (a text box that is uneditable by the user and whose
> value
> > is equal to the sum of four other text boxes). Let's say you've decided to
> > use
> > variables to track your control values (or rather, control values are
> > determined by certain variables). When do you check for and update the
> > control
> > value? Basically, how do you update control values based on variables that
> > have no onChange() event?
> >
> >
> > TOPICA - Start your own email discussion group. FREE!
> >
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
>

new topic     » goto parent     » topic index » view message » categorize

8. Re: Best Practices Issue

Ok,

Thinking about Kat's observation, maybe you could create an "invisible"
(off-screen?) check-box control, and *change* that whenever your variable
changes; then you could use an "onChange" event trap for the check-box to
re-set the text to what the variable has?

Dan Moyer

----- Original Message -----
From: <gertie at visionsix.com>
To: "EUforum" <EUforum at topica.com>
Subject: Re: Best Practices Issue


>
> On 7 Feb 2003, at 18:21, Dan Moyer wrote:
>
> >
> > C.K.,
> >
> > You could set a timer to check the variables?  But I'd check first to be
> > *sure* there's no event you could trap.
>
> In mirc, i trap /msg and /set
>
> In this way, and with mirc's ability to know the names of the vars (see
the Eu
> associated lists in the Eu archives), i can know what the code sent to
> channels or people, and decide what to do to other vars when any one var
is
> set. I pulled off some programming tricks that stunned Khaled (i know this
> because he asked me how i did it, because it alledgedly wasn't possible).
> That was without disclosing any self-modifying scripts. I know people will
> reject this suggestion again, but haveing mirc and Eu features in one
> language would be dynamite. I can keep on doing things like that in mirc
tho,
> and use Eu only when hitting a mirc shortcoming.
>
> Kat
>
> >
> > Dan Moyer
> >
> > ----- Original Message -----
> > From: "C. K. Lester" <cklester at yahoo.com>
> > To: "EUforum" <EUforum at topica.com>
> > Sent: Friday, February 07, 2003 10:29 AM
> > Subject: Re: Best Practices Issue
> >
> >
> > > > I will typically use the value directly from the control if I only
need to
> > > > reference the value 1 or 2 times top.
> > > >
> > > > If I need to reference the value in another routine (maybe with a
global
> > > > variable) or need to reference the value more than 2 times within a
function
> > > > I'll assign to a variable.  This reduces clutter, makes the code
easier to
> > > > read and also allows me to ? the value of the variable in debug.  It
also
> > > > helps with performance as you're not having to call getText()
multiple
> > > > times.
> > >
> > > Hey, Jonas, thanks for the response. Here's a follow-up for you (and
> > anybody
> > > else who wants to chime in): what do you do if a value changes in your
> > > variable, but not as a result of the control itself? For example,
let's
> > say
> > > we have txt_Total (a text box that is uneditable by the user and whose
> > value
> > > is equal to the sum of four other text boxes). Let's say you've
decided to use
> > > variables to track your control values (or rather, control values are
> > > determined by certain variables). When do you check for and update the
control
> > > value? Basically, how do you update control values based on variables
that
> > > have no onChange() event?
> > >
> > >
> > > TOPICA - Start your own email discussion group. FREE!
> > >
> >
> > TOPICA - Start your own email discussion group. FREE!
> >
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>

new topic     » goto parent     » topic index » view message » categorize

9. Re: Best Practices Issue

On Friday 07 February 2003 08:59 pm, you wrote:
>
> Thinking about Kat's observation, maybe you could create an "invisible"
> (off-screen?) check-box control, and *change* that whenever your variab=
le
> changes; then you could use an "onChange" event trap for the check-box =
to
> re-set the text to what the variable has?

If I've already detected the change enough to change the checkbox, I don'=
t=20
need the checkbox! Instead of changing the checkbox, I just change the=20
control/variable.

Ultimately what is needed is an onChange() event for a variable, but that=
's=20
unlikely (maybe preposterous or something like that!).

Two (three?) ways to do it:

1. intermittently check the values and update all dependencies
2. use onChange() events for controls and either
=09a. call a global watcher procedure that makes sure ALL variables/contr=
ols are=20
up-to-date
=09b. use code in the onChange() event to only update SPECIFIC other cont=
rols

For example:

s =3D { 1, 2, 3, 4 }
-- assign values to controls
-- txtN represents an edit box
-- txt1..txt4 are editable, txt5 is not
txt1 =3D s[1]
txt2 =3D s[2]
txt3 =3D s[3]
txt4 =3D s[4]
-- now, in each edit box control, when the value
-- of the edit box changes, I have to update txt5
txt5 =3D sum( s ) -- this line probably not needed
-- because onChange() events in txt1..txt4

This was just a brain exercise for me when I realized that there were two=
 ways=20
to go about it, and one didn't involve actual variables. That weirded me =
out,=20
but now I just envision that the controls are really just dynamic variabl=
e=20
holders that really do respond to onChange() events... hehehe. The negati=
ve=20
aspect is you can't do any sequence operations with them!!! That's why th=
e=20
variables are so valuable to me... for instance, the sum() function above=
=2E..

txt5 =3D sum( s ) -- with a variable, can be nice and clean
-- versus...
-- this is condensed, 'cuz you prolly have to extract a value() also...
txt5 =3D getText(txt1) + getText(txt2) + getText(txt3) + getText(txt4) --=
 yuck!!

Modularity is also compromised when you don't use variables. I wonder if =
speed=20
is compromised if you use variables... for instance, if you have the sequ=
ence=20
s above, and in each onChange() event for each txt1...txt4 control you si=
mply=20
change the variable s as required... then call a global updater. You at l=
east=20
have your variable in tact, but is this way going to be slower than anyth=
ing=20
else? Maybe you can just use your variables at some point and not at othe=
r=20
points, but then you've got coordination issues, which might never really=
=20
become a big deal anyway...

new topic     » goto parent     » topic index » view message » categorize

10. Re: Best Practices Issue

On Friday 07 February 2003 08:21 pm, you wrote:
>
> C.K.,
>
> You could set a timer to check the variables?  But I'd check first to b=
e
> *sure* there's no event you could trap.

Well, if I don't use variables (that is, if I depend on the controls to=20
functionally be the variables), then that's not a problem, because the=20
onChange() event will fire when the control's value changes...

But what if I have to add six control values together? What if in the fut=
ure=20
that changes? What if it's dynamic?

Actually, as I think about it I can see ways to do that stuff... but it w=
asn't=20
obvious to me at first. And, as anybody who has seen my sample code, I li=
ke=20
to program for the future as much as I do for the present. That means, wh=
en I=20
want to make changes in functionality in my programs in the future, it's=20
going to be easy- not a lot of code upheaval...

new topic     » goto parent     » topic index » view message » categorize

11. Re: Best Practices Issue

On Friday 07 February 2003 06:13 pm, you wrote:
>
> > On Fri, 7 Feb 2003 12:29:48 -0600, "C. K. Lester" <cklester at yahoo.com=
>
> >
> > wrote:
> > > anybody else who wants to chime in): what do you do if a value chan=
ges
> > > in your variable, but not as a result of the control itself?
>
> Isn't that what OOP was all about? If you accessed a variable, and it h=
ad
> an associated method, which was inherited, code was run to automagicall=
y do
> these things among all the sub-objects that were inheriting the same
> method?

I dunno, Kat... I don't do OOP. But are you suggesting that OOP allows an=
=20
onChange() event for a variable?! That'd be interesting.

> o =3D object
> .setmethod =3D o =3D a + b + c
>
> a =3D descendant of o
> b =3D descendant of o
> c =3D descendant of o
>
> a =3D 1
> b =3D 1
> c =3D 1
> -- o =3D 3
> a =3D 2
> -- o =3D 4

I wonder if Diamond does something like this... except you'd have to do=20
something like

define object o
o.setmethod( o.value , sum( a,b,c ) )
set(a,1)
-- o =3D 1
set(b,1)
-- o =3D 2
set(c,1)
-- o =3D 3

The set() procedure can either call all variables to run their onChange()=
=20
code, or it knows the dependencies and runs only the applicable onChange(=
)=20
events.

new topic     » goto parent     » topic index » view message » categorize

12. Re: Best Practices Issue

C.K. wrote:
<snip>
This was just a brain exercise for me when I realized that there were two
ways
to go about it, and one didn't involve actual variables. That weirded me
out,
but now I just envision that the controls are really just dynamic variable
holders that really do respond to onChange() events... hehehe. The negative
aspect is you can't do any sequence operations with them!!! That's why the
variables are so valuable to me... for instance, the sum() function above...

txt5 = sum( s ) -- with a variable, can be nice and clean
-- versus...
-- this is condensed, 'cuz you prolly have to extract a value() also...
txt5 = getText(txt1) + getText(txt2) + getText(txt3) + getText(txt4) --
yuck!!

<snip>

and I note:
Actually, I think you *can* do sequence operations on them, if you create
them as sequences in the first place:
sequence SomeControls
SomeControls = {}
SomeControls &= create (whatever)
SomeControls &= create (something else)
SomeControls &= create (yet another control)

Dan Moyer

new topic     » goto parent     » topic index » view message » categorize

13. Re: Best Practices Issue

On Friday 07 February 2003 09:42 pm, you wrote:
>
>
> Actually, I think you *can* do sequence operations on them, if you crea=
te
> them as sequences in the first place:
> sequence SomeControls
> SomeControls =3D {}
> SomeControls &=3D create (whatever)
> SomeControls &=3D create (something else)
> SomeControls &=3D create (yet another control)

In this case, the SomeControls sequence holds pointers, not the actual=20
values... Any functions that work with sequences of control pointers woul=
d=20
have to know that, obviously...

function sums( sequence vals ) -- add up a sequence of values
atom total
=09total =3D 0
=09for t=3D 1 to length(vals) do
=09=09total +=3D vals[t]
=09end for
return total
end function

function sumc( sequence controlIDs ) -- add up a sequence of control IDs
-- get values of all passed controls
=09for t=3D1 to length(controlIDs) do
=09=09s &=3D getValue( getText( controlIDs[t] ) )
=09end for
-- add 'em all together
return sums( s )
end function

Something like that... It's an extra step when using no variables associa=
ted=20
with the controls, but definitely doable.

new topic     » goto parent     » topic index » view message » categorize

14. Re: Best Practices Issue

Try associated lists.
<pseudocode> 

procedure set(varname,value)
 if wildmatch(this is one you wanna sum up_*,varname) then
   place = match(listnames,varname.*,count)
   while place do
     somevar += listvalues[place]
     place = match(list,varname.*,count)
   end while 
   do_something_with_somevar
  end if
end procedure

Kat

new topic     » goto parent     » topic index » view message » categorize

15. Re: Best Practices Issue

>I wonder if Diamond does something like this...

C.K.

Diamond 2.0 can do it without even using subclasses.  I'm in fact writing a
class that would handle just this sort of problem as an addition to the
Standard Class Library. (This is not coincidence, this thread has
demonstrated how useful this facility will be.)

If you are interested, I can send you and advance copy sometime this weekend
as soon as the code is finished (email me at
MichaelANelson at worldnet.att.net). Very little knowledge of Diamond will be
needed to use it.

-- Mike Nelson

new topic     » goto parent     » topic index » view message » categorize

16. Re: Best Practices Issue

----- Original Message -----
>From: "C. K. Lester" <cklester at yahoo.com>
>To: "EUforum" <EUforum at topica.com>
>Subject: Re: Best Practices Issue
>

>
>On Friday 07 February 2003 06:13 pm, you wrote:
>>
>> > On Fri, 7 Feb 2003 12:29:48 -0600, "C. K. Lester" <cklester at yahoo.com>
>> >
>> > wrote:
>> > > anybody else who wants to chime in): what do you do if a value
changes
>> > > in your variable, but not as a result of the control itself?
>>
>> Isn't that what OOP was all about? If you accessed a variable, and it had
>> an associated method, which was inherited, code was run to automagically
do
>> these things among all the sub-objects that were inheriting the same
>> method?
>
>I dunno, Kat... I don't do OOP. But are you suggesting that OOP allows an
>onChange() event for a variable?! That'd be interesting.

Yes. OO does enable this type of thing, but on for classes that you create,
not for  built-in types such as integer.

----------------
cheers,
Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

17. Re: Best Practices Issue

I come a little late to this topic, but what about LostFocus? I'm assuming 
you're all talking about text boxes here. I have a project with about 8 
textboxes, and a submit button.

I have an onLostFocus proc for each of them (If you want it to update in 
real-time as the user types, then hook in w32HKeyPress as well as 
w32HLostFocus.) In each proc, it calls getText and assigns it to the 
relevant variable.

When the submit button is pressed, it will call each of those lostFocus 
procs, just to be sure that the information is correct.

Is that the sort of thing you're looking for?
=====================================================
.______<-------------------\__
/ _____<--------------------__|===
||_    <-------------------/
\__| Mr Trick

>From: "C. K. Lester" <cklester at yahoo.com>
>Reply-To: EUforum at topica.com
>To: EUforum <EUforum at topica.com>
>Subject: Re: Best Practices Issue
>Date: Fri, 7 Feb 2003 21:39:31 -0600
>
>
>On Friday 07 February 2003 08:21 pm, you wrote:
> >
> > C.K.,
> >
> > You could set a timer to check the variables?  But I'd check first to be
> > *sure* there's no event you could trap.
>
>Well, if I don't use variables (that is, if I depend on the controls to
>functionally be the variables), then that's not a problem, because the
>onChange() event will fire when the control's value changes...
>
>But what if I have to add six control values together? What if in the 
>future
>that changes? What if it's dynamic?
>
>Actually, as I think about it I can see ways to do that stuff... but it 
>wasn't
>obvious to me at first. And, as anybody who has seen my sample code, I like
>to program for the future as much as I do for the present. That means, when 
>I
>want to make changes in functionality in my programs in the future, it's
>going to be easy- not a lot of code upheaval...
>
>==^^===============================================================
>This email was sent to: mistertrik at hotmail.com
>
>
>TOPICA - Start your own email discussion group. FREE!

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu