Thanks Kirk, that really puts things in perspective! Regards,
Rudy Mortier Two Way Communications bvba > On 29 Apr 2018, at 19:56, Kirk Brooks via 4D_Tech <[email protected]> > wrote: > > This is one of those cases where a long time 4D programmer (me) noticed my > long time approach to coding needed a refresh to take advantage of new > tools. New tools require new techniques. > > From the start 4D has managed variables so they are never “empty”. When a > new variable was created or declared it was always initialized to the > equivalent of zero for its data type. I think this was part of the effort, > back in the early days of consumer database apps, to make “scripting”, as > it was called then, easy for non programmers. You never had to worry about > a variable having no value. It always had a value of zero at least and you > could use it right away. > > Most other languages have Null. Null indicates something has no value. In > the case of numbers zero is a perfectly good value and different from not > having any value. > > 4D objects support Null. > 4D developers for the most part do not. > > Because we’ve never had to. You still don’t have to. There are work around > methods such as OB is defined. There’s nothing really wrong with using it > except it forestalls getting familiar with using Null and is more limited > in some cases. Consider this block of code: > > C_OBJECT($obj) > $ok:=($obj=Null) // $ok = true > $ok:=Not(OB Is defined($obj)) // $ok = true > $ok:=OB Is empty($obj) // $ok = true > > $obj:=New object > $ok:=($obj=Null) // $ok = false > $ok:=Not(OB Is defined($obj)) // $ok = false > $ok:=OB Is empty($obj) // $ok = true > > $obj.a:=123 // any key:value > $ok:=($obj=Null) // $ok = false > $ok:=Not(OB Is defined($obj)) // $ok = false > $ok:=OB Is empty($obj) // $ok = false > > OB is empty is the most restrictive test because empty can be Null or empty > can be undefined but Not(OB is empty) can only mean something is there. > Testing $obj=Null is equivalent to the longer command test in every > instance. I find it easier to type and easier to comprehend reading the > code. > > Here are the equivalent statements for clearing $obj: > > CLEAR VARIABLE($obj) > $obj:=Null > > The results are the same. A ‘cleared’ object variable is a Null object > variable. > > There is one more really compelling use case where testing for Null is > superior: > > C_OBJECT($obj) > $ok:=($obj.a.b.c[2]=Null) // $ok = true > $ok:=Not(OB Is defined($obj.a.b.c[2])) // error > > > This works compiled as well as interpreted and fill a big void (as it were) > in being able to test for valid objects. Testing an object path against > Null tells you if the path is valid or not. It does not tell you anything > about what part of the path fails, however. > > HTH > -- > Kirk Brooks > San Francisco, CA > ======================= > > *We go vote - they go home* > ********************************************************************** > 4D Internet Users Group (4D iNUG) > FAQ: http://lists.4d.com/faqnug.html > Archive: http://lists.4d.com/archives.html > Options: https://lists.4d.com/mailman/options/4d_tech > Unsub: mailto:[email protected] > ********************************************************************** ********************************************************************** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:[email protected] **********************************************************************

