AW: AW: O$ - why not use #F

Rudolf Bargholz rudolf at bargholz.ch
Tue Jul 26 12:33:19 UTC 2022


Hi Martin,

As programmers we are all lazy I some manner. I use global variables, but do not rely on them for productive code. A “Calculate #S2 as sys(23)” is something I use often, just to get a sys() value into a readable variable, but for important stuff I do not rely on global variables at all. Also, using different flag variables allows you more options to structure your code. Some FlagFalse cases are fatal, others are not, just as an example, so using local variables here allow you to differentiate these cases with a variable having a sensible name, implying the specific need for the variable. This makes your code and its intention clearer for the guy who is going to read your code in a few months and has no idea what it really does (more often than not this will be you). Local variable names can be more descriptive than a couple of #F sprinkled in your code that force you to read the actual code to find out why there might be a problem in each case. What is no issue is if you use the flags implicitly, e.g.

If oFileOps.$doesfileexist(lPath)
  Do some stuff if the path exists
End If

You could rewrite this to

Do oFileOps.$doesfileexist(lPath) Returns #F
If flag true
  Do some stuff if the path exists
End If

but the above code is a lot clearer in its intention than the latter method.

Also, most methods that I write start with

Calculate FlagOK as kTrue

so the flag variable I in variably need in my code is copied from the previous method to the new method, created automatically, and available for use with minimal fuss.

Regards

Rudolf Bargholz

Von: Martin Obongita <martin.obongita at yahoo.com>
Gesendet: Dienstag, 26. Juli 2022 14:19
An: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com>; Rudolf Bargholz <rudolf at bargholz.ch>
Betreff: Re: AW: O$ - why not use #F

Hi Rudolf,

I feel lazy to keep declaring variables every time that I could instead just use the global ones.
Is this a really good reason enough to use global states?

Rgds,
Martin.

On Tuesday, July 26, 2022 at 03:07:28 PM GMT+3, Rudolf Bargholz <rudolf at bargholz.ch<mailto:rudolf at bargholz.ch>> wrote:


Hi Martin,

As Mike mentions indirectly, there are workarounds to some of the pitfalls when using global state, but you really should only use global state if there is no other option, or if there is a really, really good reason.

You can use reversible blocks, or use critical blocks, or use

If sys(90)=1
The do some stuff in the timer that might affect the flag #F
End If

in a $timer method to prevent the timer from changing the flag while other code is running, but long term it is a lot easier avoiding problems than it is trying to debug them. The use of variables of the smallest scope is just one tool to help in this regard.

I, for example, still use the old "For each line in list" for code that needs really fast loop processing in Studio, and this uses a "current list", which can be messed up by other methods setting their own "current list". You just have to be aware of possible pitfalls in these cases and code appropriately.

Regards

Rudolf Bargholz

-----Ursprüngliche Nachricht-----
Von: omnisdev-en <omnisdev-en-bounces at lists.omnis-dev.com<mailto:omnisdev-en-bounces at lists.omnis-dev.com>> Im Auftrag von Martin Obongita via omnisdev-en
Gesendet: Dienstag, 26. Juli 2022 13:38
An: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com<mailto:omnisdev-en at lists.omnis-dev.com>>; Phil (OmnisList) <phil at pgpotter.co.uk<mailto:phil at pgpotter.co.uk>>
Cc: Martin Obongita <martin.obongita at yahoo.com<mailto:martin.obongita at yahoo.com>>
Betreff: Re: O$ - why not use #F

Thank you Phil and Rudolf.Does this phenomenon of unpredictability also apply to other global variables such as #1,#2, #L1, #L2 as used in a For loop: For #1 from 1 to #LN step 1 ?
Kind regards,Martin O.

Sent from Yahoo Mail on Android

  On Tue, 26 Jul 2022 at 12:46, Phil (OmnisList)<phil at pgpotter.co.uk<mailto:phil at pgpotter.co.uk>> wrote:  Martin,

Most developers will of moved away from relying on #F, mainly due to things like timers, which may pop in and do something when you least expect it, and maybe change the #F flag unexpectedly.

So using your own variable to hold any flag or status is a much safer way to go.

--
regards
Phil Potter
Based in Chester in the UK.
On 26/07/2022 09:57, Martin Obongita via omnisdev-en wrote:
>  Hi Paul,
> Sorry, I don't wish to be rude, but could I interject and ask why you use vbOK variable instead of using the inbuild #F variable to return the status of a flag?
> Kind regards, Martin.
_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com <https://lists.omnis-dev.com%20> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com<mailto:omnisdev-en at lists.omnis-dev.com>

_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com <https://lists.omnis-dev.com%20> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com<mailto:omnisdev-en at lists.omnis-dev.com>


More information about the omnisdev-en mailing list