Chris B made the below statement about project methods.

from a 'classic' 4D pogromming view, IMHO - which may mean nothing :), 
this is not the approach I use or advocate.

I do use object methods - but - only to call project methods which do 
all of the actual work.
ex: accept button script
    // accept button script <[table].form.object>
tablename_entry_accept
   // end accept button script <[table].form.object>

the project method tablename_entry_accept will do data entry 
validation, messaging about entry failures, related record existence, 
calculations that need to be done etc. and usually an ACCEPT


Why?
Deduplication of code. Code should NOT be repeated. In the above 
example, the code to accept the form maybe reusable or be made more 
generic (with parameters). If the code for this accept button was 
placed in the object script - I might end up re-creating/repeating the 
code elsewhere (even to the point of copy/paste). 

At some point in the future I might need to change the logic/code. Then 
I would need to find all instances of the code through out the system, 
to make the change. If the system is NOT one I wrote, or it has been a 
long time (3 days?) since I worked on that section I would/might not 
know where all instances of the duplicated code are.

If the code is in a project method, I can make the changes needed in 
one place, done.
Also - code in scripts is harder to find/maintain.

Some people in the past have advocated for removal of all object 
scripts, placing the code instead into the form method (or better the 
project method called by the form method). I do not personally do this, 
as I looked at it once and, to me, the resulting code was too long and 
not clear -- of course maybe I was not implementing the idea correctly 
or completely :)

just my 2 cents

Chip


On Wed, 24 Apr 2019 22:37:51 -0600, Chris Belanger via 4D_Tech wrote:
> 
> Another use for it that I have not explored yet is to have a chunk of 
> code that gets run under several different circumstances, but which I 
> don’t want to make a dedicated Project Method for it.
> I prefer to reduce the number of Project Methods while, of course, 
> creating ones that make logical sense (as they can be called in 
> several places in my code). But you understand that as a programmer.
---------------
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to