Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-22 Thread David Adams via 4D_Tech
Hey again John,

Here's a fun thought experiment: Imagine a computer language that doesn't
have globals at all. (Eiffel.)

P.S. To those following along at home:
Yes, you can always create globals my misusing a singleton.
No, not all singletons are following an "anti-pattern."
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-22 Thread John Baughman via 4D_Tech
David… reminiscent of old times, you can feel ignored once again ;-)

Seriously though, I am not disagreeing here with you or any one else with 
regard to the problems that global variables can create. I am just once again 
saying, don’t throw the baby out with the bath water. Globals, in my opinion, 
do have valid uses. If used judiciously, with emphasis on judiciously, they 
should not create any problems for me now or others inheriting my code in the 
future.

One thing that I do for my own benefit is to always insure that  my global 
variable names clearly describe the global's intended use, scope, and in some 
cases longevity.

John

> On Jul 21, 2017, at 5:10 PM, David Adams via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> On Sat, Jul 22, 2017 at 12:56 PM, John Baughman via 4D_Tech 
> 4d_tech@lists.4d.com> wrote:
> 
>> Lacking a computer science background
> 
> 
> ...me too.
> 
> 
>> My point is that none of the hammers are evil nor should any “be avoided
>> like the plague”. Each has a place in my tool shed. I have a very basic
>> understanding as to why a global variable can be problematic. For this
>> simpleton it is all in one’s overall approach to the task at hand… less is
>> best.
>> 
> 
> Most of you won't know this, but I used to live in the same town as John
> and we would go to lunch regularly. Coding would come up a lot. I have to
> say, John and I tended to disagree about pretty much everything, top to
> bottom. And, for what it's worth, I can't think of a person I've met who
> more easily took up new tools and languages and managed to come up with
> novel solutions that were good for his customers. He's also taken over Flex
> and 4D projects I started, so he knows where I've buried the bodies ;-)
> Anyone that enjoyed John's popular "Tips & Tricks" presentations years back
> at the Summit should remember that John is, above all, pragmatic, not
> dogmatic.
> 
> So, I know perfectly well that when I tell John he's "wrong", he'll ignore
> me ;-)
> 
> The evils of globals come up faster when you have messy code and/or
> multiple coders. Same with bad parameter passing, etc. You can put up a ton
> of scaffolding to trap and handle coding mistakes. Or you can just not make
> mistakes and strip out all of the guardrails.
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **

**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-22 Thread Jeremy Roussak via 4D_Tech
Pretty much. And the gaps are filled by Dilbert.

Jeremy


Jeremy Roussak
j...@mac.com



> On 22 Jul 2017, at 09:17, Jeremy Roussak via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> Someone has thought of that, Chip: https://xkcd.com/1205/ 
> 
> 
> Jeremy
> 
> 
> Jeremy Roussak
> j...@mac.com
> 
> 
> 
>> On 21 Jul 2017, at 14:47, Chip Scheide via 4D_Tech <4d_tech@lists.4d.com> 
>> wrote:
>> 
>> On Fri, 21 Jul 2017 23:01:56 +1000, David Adams via 4D_Tech wrote:
>>> let's take a moment to
>>> remember that speed only matters when things are slow.
>> true.
>> BUT...
>> if you have 3 ways to do something
>> 
>> 1 - this works, but takes X time
>> 2 - this works too, take a bit more coding, but takes X/2 time
>> 3 - this works, takes X/n time, and takes no more additional time to 
>> code then 2
>> (where n = some number larger then or equal to 2)
>> 
>> Which should you use?
>> 
>> 
>> Chip
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **

**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-22 Thread Chip Scheide via 4D_Tech
there is an XKCD for *everything*  :)

> Someone has thought of that, Chip: https://xkcd.com/1205/ 
> 
> 
> Jeremy
> 
> 
> Jeremy Roussak
> j...@mac.com
> 
> 
> 
>> On 21 Jul 2017, at 14:47, Chip Scheide via 4D_Tech 
>> <4d_tech@lists.4d.com> wrote:
>> 
>> On Fri, 21 Jul 2017 23:01:56 +1000, David Adams via 4D_Tech wrote:
>>> let's take a moment to
>>> remember that speed only matters when things are slow.
>> true.
>> BUT...
>> if you have 3 ways to do something
>> 
>> 1 - this works, but takes X time
>> 2 - this works too, take a bit more coding, but takes X/2 time
>> 3 - this works, takes X/n time, and takes no more additional time to 
>> code then 2
>> (where n = some number larger then or equal to 2)
>> 
>> Which should you use?
>> 
>> 
>> Chip
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **

Hell is other people 
 Jean-Paul Sartre
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-22 Thread Jeremy Roussak via 4D_Tech
Someone has thought of that, Chip: https://xkcd.com/1205/ 


Jeremy


Jeremy Roussak
j...@mac.com



> On 21 Jul 2017, at 14:47, Chip Scheide via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> On Fri, 21 Jul 2017 23:01:56 +1000, David Adams via 4D_Tech wrote:
>> let's take a moment to
>> remember that speed only matters when things are slow.
> true.
> BUT...
> if you have 3 ways to do something
> 
> 1 - this works, but takes X time
> 2 - this works too, take a bit more coding, but takes X/2 time
> 3 - this works, takes X/n time, and takes no more additional time to 
> code then 2
> (where n = some number larger then or equal to 2)
> 
> Which should you use?
> 
> 
> Chip
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread David Adams via 4D_Tech
On Sat, Jul 22, 2017 at 12:56 PM, John Baughman via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> Lacking a computer science background


...me too.


> My point is that none of the hammers are evil nor should any “be avoided
> like the plague”. Each has a place in my tool shed. I have a very basic
> understanding as to why a global variable can be problematic. For this
> simpleton it is all in one’s overall approach to the task at hand… less is
> best.
>

Most of you won't know this, but I used to live in the same town as John
and we would go to lunch regularly. Coding would come up a lot. I have to
say, John and I tended to disagree about pretty much everything, top to
bottom. And, for what it's worth, I can't think of a person I've met who
more easily took up new tools and languages and managed to come up with
novel solutions that were good for his customers. He's also taken over Flex
and 4D projects I started, so he knows where I've buried the bodies ;-)
Anyone that enjoyed John's popular "Tips & Tricks" presentations years back
at the Summit should remember that John is, above all, pragmatic, not
dogmatic.

So, I know perfectly well that when I tell John he's "wrong", he'll ignore
me ;-)

The evils of globals come up faster when you have messy code and/or
multiple coders. Same with bad parameter passing, etc. You can put up a ton
of scaffolding to trap and handle coding mistakes. Or you can just not make
mistakes and strip out all of the guardrails.
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread John Baughman via 4D_Tech
I always get amused whenever the discussion on the NUG turns to the evils of 
global variables. Lacking a computer science background most of the discussions 
in this vain go way over my head. I am a self taught 4D guy who over the years, 
for reasons I know not why, have taken a minimalist approach
to writing code. To me it is like going to the tool shed for a hammer. I always 
look for the smallest hammer that will get the job done...

No hammer = no variables
Finishing nail hammer = local variables
Regular hammer = Process variable
Sledge hammer = Global variable

The only reason I reach for the regular hammer is if for whatever reason I am 
unable to pass around my local variables either as parameter values or 
pointers. 

I rarely need to use the sledge hammer. I have found them useful for constants 
that are set at login, to provide a means for one process to report status back 
to the process that created it, or to store process numbers when multiple 
process are running at the same time and need to be aware of each other. 

As for globals used as constants, they are like that great set of tools hanging 
on my peg board. Rarely used but are always there in the same place should I 
need them. 

My point is that none of the hammers are evil nor should any “be avoided like 
the plague”. Each has a place in my tool shed. I have a very basic 
understanding as to why a global variable can be problematic. For this 
simpleton it is all in one’s overall approach to the task at hand… less is 
best. 

My 2 cents

John

> On Jul 20, 2017, at 10:22 PM, Nigel Greenlee via 4D_Tech 
> <4d_tech@lists.4d.com> wrote:
> 
> Global Variables.
> 
> Regardless of the relative merits of Arrays vs Object. I would like to relay 
> my dislike in general of Glol variables. I have been work with 4D since 
> before the concept existed-since 4D V2(Globals came in with V3). Yes i am one 
> of the old boys.
> 
> Back then we did not have multiple processes and when V3 arrived we were all 
> amazed and in awe of the abilityich to have multiple processes and I think we 
> all went mad for interprocess(global) variables.(i think we all had singing 
> dancing palettes on the screen doing fancy things to update themselves from 
> other processes). 
> 
> Now if we were working in Javascript the concept of a global variable would 
> very much be considered something to be avoided like the plague. Global 
> variables are extremely useful but also extremely prone to problems, and over 
> the past couple of years-any javascript tutorial tells you to try and avoid 
> them, in 4D  I  have really cut down on my use of them.
> 
> In my opinion a global variable should in general only be used for two things.
> 1) You want to set a value(or group of values) and through the life of the 
> programme they do not change once set(so here you are using them like a 
> constant)
> 2) You want to maintain an array that will be written to by multiple 
> processes.
> 
> With point 2 you must protect the arrays with semaphores so only one process 
> alters the arrays at any one time-and often where these are used there might 
> be other ways to do it.
> 
> I have just this week been dealing with 2 different structures where the 
> liberal use of interprocess arrays has lead to problems. Problems that do not 
> show up in testing and probably show that that the way the routines has been 
> used has changed over time. In both cases-different companies-different 
> programmers-different stuff an error shows up just occasionally. In one of 
> those systems discussion with the client shows that the usage of interprocess 
> variables has caused ‘strange’ unexplained un-investigated things to happen 
> where process A is changing the contents of <>Variable just at the point when 
> process B is about to send the contents of <>Variable that process B had set 
> to a document (‘sometimes we get a situation where the same order document is 
> created twice’!!)..and they have just restarted the machine to get rid of the 
> problem in the past(a practice that means you think the problem is 4D not the 
> way the code is written).
> 
> Simply protecting the handling so only one process at a time can modify the 
> interprocess variables and arrays would have avoided all this. I suspect the 
> original programmer never intended the functionality to be running in 
> multiple processes at the same time and used interprocess arrays to (I think) 
> make it easier to display the data on a form that is in a different process. 
> Beyond the idea of a form in a different process i don’t see any purpose in 
> the arrays in this case being interprocess-they are being constantly changed 
> and as such should at best have been process arrays, In fact in a modern 
> context(this was written way before that) where we have been able to pass 
> pointers to local variables since 4D V11(??-maybe it was before that) I would 
> generally argue that programming using locals is much better-and 

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread Robert McKeever via 4D_Tech
I doubt that they would let you through customs, David.

> On Jul 21, 2017, at 6:01 AM, David Adams via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> On Fri, Jul 21, 2017 at 10:35 PM, Pat Bensky via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
> 
>> My 2 cents:
>> 
>> According to a recent 4D blog entry, using the new object notation option
>> will speed up your objects significantly:
>> 
> 
> Sounds great!
> 
> Before this becomes the new "for loops are faster", let's take a moment to
> remember that speed only matters when things are slow. And mostly, things
> aren't slow now. Heck, you can do silly things that would have hurt a lot
> years ago and never notice now. So, yeah, speed is sometimes interesting,
> but it's only important when it's important. That's not that often for most
> programs.
> 
> It's always easy to lose track of proportion too:
> 
> "Such and so makes you twice as likely to get attacked by a bear!"
> 
> What does that mean? Does that mean your risk rises from 1/1,000,000 to
> 1/500,000 or from 1/10 to 1/5? Same proportion, pretty big difference in a
> day-to-day sense.
> 
> Tip: Don't go to BC covered in salmon guts. Just saying.
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **

_
Bob McKeever  http://www.mswl.com 
McKeever's Software Wizardry
Port Coquitlam, B.C.
bobmckee...@mac.com




**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread Kirk Brooks via 4D_Tech
Nigel,
Nice post. I very much agree with pretty much all your points. A few things
I'll add:

Functions: yes! A lot of IP vars I see in old code are used to make values
available that used to take measurable time to derive. Lots of them can be
replaced with a short function to just go get the current value of
whatever. This is a fine solution for user entry situations. In a tight
loop I'd collect all that data first into local vars prior to starting the
loop.



On Fri, Jul 21, 2017 at 1:22 AM, Nigel Greenlee via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> I suspect the original programmer never intended the functionality to be
> running in multiple processes at the same time and used interprocess arrays
> to (I think) make it easier to display the data on a form that is in a
> different process.

​Triggers also. I find IP vars in triggers which are generally useless, or
worse, on 4D server because the trigger code always runs on the server
which has no knowledge of the client IP vars.

Same problem with using IP vars as semaphores. It worked way back in the
day and doesn't break noticeably when running. ​



> Most code i write now is ‘self contained’ -I attempt to set all values
> used in the method is passed in to the code -either as parameters or an
> object or a pointer to something so that i end up with something more like
> a javascript function. Myreturn:=MyMethod(something;something;something).
> Using this style of coding means i am far more likely to get an error if
> there is one EVERY TIME rather than a head scratching randomly appearing
> one and my code does not rely on the perceived value of a variable.
>
​I find this very true. The time spent writing the method to manage its own
variables may be a little more up front but you never have to come back to
it unless you are actually changing the method. It also makes it easier to
test code. ​

-- 
Kirk Brooks
San Francisco, CA
===

*The only thing necessary for the triumph of evil is for good men to do
nothing.*

*- Edmund Burke*
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread David Adams via 4D_Tech
> if you have 3 ways to do something

I'd go with the way I found easiest and, ideally, made the simplest to
understand code. If one of the choices was obviously stupid or inefficient,
I'd probably skip it. But, honestly, clear code is super important. I'll
leave the fancy stuff for when it's needed. And even then, it usually
smells wrong to me. I was writing something last week that was just *crazy*
complicated. It was making my head hurt, tons of 2D arrays...nuts. I added
what amounts to a temporary table and then queried against it. Boom! The
task of preparing the summary data is now a nice clean task. The task of
analyzing the data is now a distinct task, also nice and clean. The overall
brain power required to sort through this stuff is way, way lower. It's
just better. It actually runs faster, but that wasn't a factor. It didn't
matter it took five minutes or all night.

When stuff is getting so complicated that I can't follow it easily or
figure out how to test it, I'm bound to screw it up. That's usually a time
to look at the problem again and come up with a different line of attack.
Breaking things into smaller pieces, trying a different approach, figuring
out what I don't understand so that I can simplify things, etc.

Speed per se? I don't think about it much. Until I have to. Which isn't
often. And fancy code tricks are not even in my top five approaches to
speed problems these days.
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread Peter Jakobsson via 4D_Tech

On 21 Jul 2017, at 16:48, David Adams via 4D_Tech <4d_tech@lists.4d.com> wrote:

> * No. You do not need classes. Modules do not require OOP, OO came out of
> earlier work and embraced modules and extended them. I'm just talking about
> module-level scope and data hiding, not OO

Ok, you could be onto something there. 4D often find ways to implement greater 
degrees of articulation in a unique “4D way” that doesn’t come with a whole lot 
of productivity baggage. I’ll suspend judgement till I see the killer feature - 
I might like it ;)

> Don't really know what you mean by 3G and 4G languages


Basically: statefull vs stateless, high level vs low level, integrated 
(language/DB/UI) vs dis-integrated.

Regards

Peter

**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread David Adams via 4D_Tech
Hey Peter, just a quick response to a couple of things:

* Don't really know what you mean by 3G and 4G languages. If memory serves
me, this was more of a marketing term from the 1980s or so than any kind of
real technical distinction.

* No. You do not need classes. Modules do not require OOP, OO came out of
earlier work and embraced modules and extended them. I'm just talking about
module-level scope and data hiding, not OO.  (I'm being far less ambitious
than you give me credit for!) Sadly, 4D's components don't really fill this
role well and are, for most of us, pretty hard to work with.
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread Peter Jakobsson via 4D_Tech

Well, I’m afraid I’ll have to take the pariah role here and politely disagree 
with you all :-)) - or at least present an alternative perspective in which 
“globals” play a very powerful and unique part.

Lets think this all through for a moment. As is relevant to this topic, we can 
notionally consider the data that an application ‘consumes’ in 2 distinct 
aspects:

 • persistent data structures
 • non-persistent data structures

The first of these are basically represented by pre-prepared classes which we 
call “tables". We can instantiate an instance of that class and manipulate that 
instance implicitly using commands like CREATE RECORD, QUERY and SAVE RECORD. 
The second are represented - on the one hand - by a library of pre-prepared 
classes that the ID gives us like forms, form controls, etc and on the other 
hand by the data oriented language elements, i.e. locals, interprocess globals 
and process globals (of which 4D data objects are a subset of each).

Now, if 4D gave us the facility to scope a process level global variable to an 
arbitrary set of methods (or even forced us to do so) then it would have 
effectively have re-invented the concept of the language class as appears in OO 
languages. You’d have to formally define the class, formally define its 
properties and methods, formally instantiate it and maintain a reference to the 
particular instance you’re using at a given moment. You would not be able to 
support user interface elements implicitly with the class’s data (as we can 
with native 4D), you’d have to either give your class its own UI and all the 
supporting methods it needed to drive it (which would only work from within 
that class) OR create the plumbing to connect an independent form class so that 
it can be driven by the data in your “tightly scoped” business logic module.

Remember, we already have ‘modules’ in 4D which have their own privately scoped 
variable space in the form of 4D components. So if - on top of that - 4D 
supported “components within components” I suggest we’d have an unmitigated 
architectural clutter who’s language structure became increasingly ambiguous 
and unwieldy. The “living hell” of globals being broadly scoped might actually 
seem like an attractive problem to have by comparison (for many of us anyway).

On 21 Jul 2017, at 14:32, David Adams via 4D_Tech <4d_tech@lists.4d.com> wrote:

> But, yeah, globals are bad. They make your life a living hell because
> someone changes something and now "unrelated" parts of the program break

David, I think you may be impacted by this ‘scoping issue’ disproportionately 
compared to many developers since you appear to do a lot of “Red Adair” type 
troubleshooting work where you’re parachuted into a crisis situation and have 
to start stabilising, refactoring and growing an existing codebase 'back to 
health’. (Just an observation from your posts - I may be completely wrong on 
that of course !). I can definitely see how a more formal modular environment 
would help in that situation. But how many of those databases would have 
existed in the first place if their original developers had been forced down 
the more formalised route ? In my own experience of visiting customer sites, 
not many. Also, I’d posit that your problem isn’t a lack of language support, 
it’s simply deficient design (by your predecessors) which would in fact have an 
even more adverse impact in an environment of the complexity you’re promoting.

On 21 Jul 2017, at 10:22, Nigel Greenlee via 4D_Tech <4d_tech@lists.4d.com> 
wrote:

> Most code i write now is ‘self contained’ -I attempt to set all values used 
> in the method is passed in to the code -either as parameters or an object or 
> a pointer to something so that i end up with something more like a javascript 
> function

Nigel - this would be an admirable objective for the most part if it weren’t 
for the one big elephant in the room that separates 4D’s “4GL” heritage from 
its 3GL contemporaries and that is its huge dependence on and leverage 
of……statefulness ! I urge people not to dismiss it because it’s where we get 
all our productivity from in the first place.

Having thought about this a great deal over the years, I came to the conclusion 
that we could split our entire codebase into 2 distinct types of method: 
stateless and stateful. In the case of the former, yes it is a good idea to do 
as you say and make the code as “self contained” as possible. However in the 
case of the latter, it’s positively counterproductive because we are dealing 
with an implicit non-persistent data structure and it’s more efficient just to 
make that data structure explicit to maintain state between methods. There are 
also other benefits:

 • the business logic more auditable because we’re decoupled the data from the 
code that manages it
 • we don’t need a myriad of parameters everywhere or random properties buried 
away in an object
 • the compiler sees it and can assist with formal 

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread Chip Scheide via 4D_Tech
On Fri, 21 Jul 2017 23:01:56 +1000, David Adams via 4D_Tech wrote:
> let's take a moment to
> remember that speed only matters when things are slow.
true.
BUT...
if you have 3 ways to do something

1 - this works, but takes X time
2 - this works too, take a bit more coding, but takes X/2 time
3 - this works, takes X/n time, and takes no more additional time to 
code then 2
(where n = some number larger then or equal to 2)

Which should you use?


Chip

---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread David Adams via 4D_Tech
On Fri, Jul 21, 2017 at 10:35 PM, Pat Bensky via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> My 2 cents:
>
> According to a recent 4D blog entry, using the new object notation option
> will speed up your objects significantly:
>

Sounds great!

Before this becomes the new "for loops are faster", let's take a moment to
remember that speed only matters when things are slow. And mostly, things
aren't slow now. Heck, you can do silly things that would have hurt a lot
years ago and never notice now. So, yeah, speed is sometimes interesting,
but it's only important when it's important. That's not that often for most
programs.

It's always easy to lose track of proportion too:

"Such and so makes you twice as likely to get attacked by a bear!"

What does that mean? Does that mean your risk rises from 1/1,000,000 to
1/500,000 or from 1/10 to 1/5? Same proportion, pretty big difference in a
day-to-day sense.

Tip: Don't go to BC covered in salmon guts. Just saying.
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-21 Thread Pat Bensky via 4D_Tech
My 2 cents:

According to a recent 4D blog entry, using the new object notation option
will speed up your objects significantly:

"Good news, now you have a mean to get rid of all those OB Get
 and OB SET
 in your
code! And you know what? The code execution is *10 times faster with the
object notation* compared to OB Get
/OB SET
 usage!"

See http://blog.4d.com/another-way-of-coding-object-notation/?

You'll need to be using v16r4 I believe. But even if you're not on v16 yet,
it's worth keeping in mind.

Pat

On 21 July 2017 at 09:22, Nigel Greenlee via 4D_Tech <4d_tech@lists.4d.com>
wrote:

> Global Variables.
>
> Regardless of the relative merits of Arrays vs Object. I would like to
> relay my dislike in general of Global variables. I have been working with
> 4D since before the concept existed-since 4D V2(Globals came in with V3).
> Yes i am one of the old boys.
>
> Back then we did not have multiple processes and when V3 arrived we were
> all amazed and in awe of the ability to have multiple processes and I think
> we all went mad for interprocess(global) variables.(i think we all had
> singing dancing palettes on the screen doing fancy things to update
> themselves from other processes).
>
> Now if we were working in Javascript the concept of a global variable
> would very much be considered something to be avoided like the plague.
> Global variables are extremely useful but also extremely prone to problems,
> and over the past couple of years-any javascript tutorial tells you to try
> and avoid them, in 4D  I  have really cut down on my use of them.
>
> In my opinion a global variable should in general only be used for two
> things.
> 1) You want to set a value(or group of values) and through the life of the
> programme they do not change once set(so here you are using them like a
> constant)
> 2) You want to maintain an array that will be written to by multiple
> processes.
>
> With point 2 you must protect the arrays with semaphores so only one
> process alters the arrays at any one time-and often where these are used
> there might be other ways to do it.
>
> I have just this week been dealing with 2 different structures where the
> liberal use of interprocess arrays has lead to problems. Problems that do
> not show up in testing and probably show that that the way the routines has
> been used has changed over time. In both cases-different
> companies-different programmers-different stuff an error shows up just
> occasionally. In one of those systems discussion with the client shows that
> the usage of interprocess variables has caused ‘strange’ unexplained
> un-investigated things to happen where process A is changing the contents
> of <>Variable just at the point when process B is about to send the
> contents of <>Variable that process B had set to a document (‘sometimes we
> get a situation where the same order document is created twice’!!)..and
> they have just restarted the machine to get rid of the problem in the
> past(a practice that means you think the problem is 4D not the way the code
> is written).
>
> Simply protecting the handling so only one process at a time can modify
> the interprocess variables and arrays would have avoided all this. I
> suspect the original programmer never intended the functionality to be
> running in multiple processes at the same time and used interprocess arrays
> to (I think) make it easier to display the data on a form that is in a
> different process. Beyond the idea of a form in a different process i don’t
> see any purpose in the arrays in this case being interprocess-they are
> being constantly changed and as such should at best have been process
> arrays, In fact in a modern context(this was written way before that) where
> we have been able to pass pointers to local variables since 4D V11(??-maybe
> it was before that) I would generally argue that programming using locals
> is much better-and that could be local objects or local arrays. These
> really show that an interprocess array was used for convenience where it
> was not really needed and changes to code did not include a proper
> assessment of the impact-just because you can do something and it works
> once does not mean it is tested or fit for purpose.
>
> In most of my code over the past few years I have moved so far away from
> <> variables that if i have more than a few-maybe a variable holding the
> user name or something like that which does not change(and even there I use
> a function ..UTIL_GetUser(“Name”)..). I have even moved largely away from
> process variables and arguable could move further from them by not using
> variable names on screen objects. Convincing clients to let me change their
> code and actually changing it is not 

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-18 Thread Chip Scheide via 4D_Tech
Long ago - and I am pretty sure the code has been lost to time -
in v2.2.3 (I think) I wrote code to do binary searching on a selection, 
as at that time Search Selection (the old command name) was sequential, 
but sorting the selection was indexed.

Even with the overhead of managing the pointers, and stepping through 
records to find all matching records in the selection, as memory 
serves, it was faster (interpretedly) to use the binary search on a 
selection size of beginning at 6-8 records.

For those who care, an outline of a binary search (on records in 
selection)
The following was written off the stop of my head, in the email editor,
BUT it gets to the basics of a binary search on a selection in 4D.

- get size of selection ($Selection_Size).
- make sure it is sorted on the field you want to search on.

repeat
 $Current_record:= int($Selection_Size/2)

   repeat
goto selected record([table];$Current_record)
 case of
  :($Current_record>=$Selection_Size) or ($Current_record<=1)
  $Not_Found:=true
  :([table]field = Value)  // found it create collection of 
matching records
   add to set([table];"Matching")
   $previous:=$Current_record
   $Next:=$Current_record

repeat
  $previous:= previous-1
  goto selected record([table];$previous)
 
  if ([table]field = Value)  // found it create collection of 
matching records
add to set([table];"Matching")
  else
$previous:=0
  end if
until($previous=0)

repeat
  $$Next:= $Next+1
  goto selected record([table];$Next)
 
  if ([table]field = Value)  // found it create collection of 
matching records
add to set([table];"Matching")
  else
$Next:=Selection_Size
  end if
until($Next= Selection_Size)
$Mo_More_Matches = true
  :([table]field > Value)  // Not found current record value > 
search value
   $Current_record:=int((1+$Current_record)/2)
  :([table]field < Value)  // Not found current record value < 
search value
   $Current_record:=int((Selection_Size+1+$Current_record)/2)
  end case
until ($Not_Found)) or ($No_More_Mathes)

At this point the set "Matching" contains all records matching the 
criteria, or nothing.

On Tue, 18 Jul 2017 22:16:18 +1000, David Adams via 4D_Tech wrote:
> 
> And, lest anyone forget, you can use binary search logic on sorted
> selections with GOTO SELECTED RECORD. Why not?
---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Use of Objects vs Global Variables (Was 'Arrays vs Objects...)

2017-07-18 Thread David Adams via 4D_Tech
> The original thread on "Arrays vs Object for Key/Value pair lookups” is a
good case in point. Yes there is a huge
> performance boost in using objects (I hold my hands up - I’m doing it !
LoL), but I’m retaining the use of ‘parallel arrays’
> for much of the code simply because they’re so nice and trackable
everywhere. As David Adam’s say, the performance
> gain is huge but has to be weighed against other priorities.

Hey Peter, my point was arguably the opposite - the performance gains for
using an object instead of a sorted array are *trivial* (best case) and
negative (worst case.) Object setup/teardown is more time-consuming and a
binary search is fast and remains fast even with billions of items. (In
theory.)

Unsorted array searches are just slower by nature...they're sequential so
the pain only gets worse with larger arrays and when you're searching for
elements to the end of the array.

I'm very pleased that 4D now has a native binary search on arrays, and I'm
happy with how it's implemented. It's perfect for everything I needed it
for. Indeed such a thing earlier this year, rewrote an old Dave Terry tech
note, posted the code here and...someone quickly said, "U, have you
seen the Language Reference lately?"

If anyone out there doesn't understand why binary searches are faster (so
much faster) than standard sequential scans, and why they depend on sorted
values, it's easy to understand. Google it and you should be able to figure
it out in a few minutes.

And, lest anyone forget, you can use binary search logic on sorted
selections with GOTO SELECTED RECORD. Why not?
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**