Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #18876
| Path | csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Best strategy to follow a state transition? |
| Date | Fri, 21 Sep 2012 09:51:54 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 55 |
| Message-ID | <k3hrdu$97b$1@dont-email.me> (permalink) |
| References | <505c4afc$0$6941$e4fe514c@news2.news.xs4all.nl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Fri, 21 Sep 2012 13:51:58 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="ffb8f7085759b339c1002252b48331a4"; logging-data="9451"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wxk/nC4XbvhnhU1EPseg4" |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 |
| In-Reply-To | <505c4afc$0$6941$e4fe514c@news2.news.xs4all.nl> |
| Cancel-Lock | sha1:YX7udZ7km9s1plFME/PoybaZ2vM= |
| Xref | csiph.com comp.lang.java.programmer:18876 |
Show key headers only | View raw
On 9/21/2012 7:09 AM, Ben Engbers wrote:
> Hi,
>
> In my program, I know that at some moment the value of a variable X will
> change from value 1 to value 2. I am not interested in the value of X
> itself but the transition should trigger an event. Example, if the value
> of a stock will reach a certain value, I want to sell but after that I'm
> not interested in the value anymore (until it might reach another
> break-value).
>
> Of course I could program this as:
> if oldvalue <= testvalue and newvalue > testvalue then
> do something;
> oldvalue = newvalue;
> end
> But suppose that there are a lot of variables that I need to watch and I
> don't want to write a test for every one.
If the program does not test whether a transition occurred
for some variable, then the program follows the same path whether
the transition occurs or not -- that is, in the absence of a test
the program is oblivious to the transition.
There are probably a gazillion ways to arrange the pieces of
the tests, but no way to avoid making them.
> Wat is the best strategy to watch the transition?
Insufficient information. A few issues that would probably
matter a lot in the choice of an approach:
- Are the variables "related" or "independent?" For example,
if X and Y have the same threshold and you know X is always
greater than Y, then if X is below the threshold you can
infer that Y is, too, and needn't make a separate test.
- How many transitions do you care about? If X rises above
its threshold, do you care whether it then falls below it
and rises again?
- If you care about multiple transitions, how do you want to
behave when X jiggles insanely in a narrow region containing
its threshold? Do you want a notification for every crossing,
or only the first until a "significant" later excursion, or
only the first until T seconds have elapsed, or ...?
- How is the overall program structured? Would you like to
write `if(var.transitioned())' at points of interest, or
would you like to "register an observer" to be notified of
transition events, or would you like transition events to
be queued when they occur and handled later, or what?
--
Eric Sosman
esosman@ieee-dot-org.invalid
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Best strategy to follow a state transition? Ben Engbers <Ben.dot.Engbers@Be-Logical.dot.nl> - 2012-09-21 13:09 +0200
Re: Best strategy to follow a state transition? "John B. Matthews" <nospam@nospam.invalid> - 2012-09-21 07:36 -0400
Re: Best strategy to follow a state transition? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-21 09:51 -0400
Re: Best strategy to follow a state transition? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-09-21 10:26 -0700
Re: Best strategy to follow a state transition? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-09-22 00:08 +0200
csiph-web