Peter: From my email in the thread entitled "Building a Selection to array statement in v13.6" from July 2016:
"John/Neil: Couldn't agree more about passing an Object. I've been using ObjectTools and programmatically creating accessor methods for "base classes" for almost 20 years. That has allowed me to avoid the complexities of variable parameter lists, a technique that's been adopted, as best I can tell, primarily to work around the limitations of a procedural language. In addition, it allows me to almost eliminate the use of process data. The consequence has been code that is very maintainable, very loosely coupled, high extensible, easily debugged, and having a low defect rate. Rather than deal with a frozen parameter list or adding more and more internal complexity to existing code, creating objects/structs and using accessor methods essentially ensures that you won't introduce bugs because the object/struct + accessor methods enforces data hiding. Insofar as type checking, accessor methods handles that just fine. PROPRPT_NewItem_Set ($h_;$newItem_F) and C_Boolean($newItem_F) $newItem_F:=PROPRPT_NewItem_Get ($h_) are as strongly typed as 4D can be. One issue is the concern that having to "write a bunch of extra code to build the object" and that is a valid concern. In addition to boring, it's error prone. When I first started creating ObjectTools-based "base classes", I copied and pasted a template. Ugh. Short answer - don't do it. Carbon-based life forms do not do those sorts of things well. Don't the write code, let 4D do it for you. 4D has allowed us to create methods programmatically since the 1990's. My first pass at automation posted events into the event queue. It worked but it was "slow". Next iteration was to use API Pack and it now uses 4D's built in commands. The concept is simple - type the name of a local variable in a method, copy it, and click the "Create Code" button. 4D parses the variable name (to determine the type), does tag replacement in the "_Set" template and creates the _Set method, does tag replacement in the "_Get" template and creates the _Get method, and then beeps to let me know that it's done so I press Ctrl-V to paste the method names into the "base class method". The code it template based, it can be modified to suit, and it writes code for unary variables or arrays for either Object Tools or C_Object. Total time is about two seconds from the time I type the local to the time I paste the method names into my base class method. And the code is consistently syntactically perfect. This is, I accept, a radical departure from how 4D is normally coded but it has tremendous benefits. " -- Douglas von Roeder 949-336-2902 On Fri, Sep 30, 2016 at 10:53 AM, Neil Dennis <npden...@greatext.com> wrote: > > So, informal poll - who’s using objects for parameter passing ? > > I’m using object and love them… > > Example 1 > For example the program which I’m working on creates reports in different > formats but use the same data. So I put my code to load the data in one > method then use another method to format the data, I have multiple methods, > one for each format, but only one data method. > > I could use process variables, but then I couldn’t use execute on server > if I found a particular reports load code needed extra speed by being run > on the server. I could use parameters and this would solve the option of > optionally executing the load code on the server, but some of the reports > need to load dozens of arrays/variables. > > Objects solve this… I pass an object to the load method with any values > needed, it passes back all of the report data in a single object. I can > change it to execute on server with no issues, all of the objects and > variables are local which makes debugging a lot nicer. It also separates > the gathering and presenting logic nicely. > > > Example 2 > Formatting address, sometimes I have a country sometimes I have 1, 2, 3, 4 > lines of address etc. Adding a parameter and not with objects makes things > really easy > > > I love objects, I think if you start using them and get to know them you > will love them too :) > > > Neil > > -- > Neil Dennis > 4D Developer since 1990 > > GreaText - Designing Software for the Way You Work > 716 East 1850 N > North Ogden, UT 84414 > > mailto:npden...@greatext.com > http://www.greatext.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 > ********************************************************************** > ********************************************************************** 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 **********************************************************************