On 14/04/2019 22:08, Ryan Joseph wrote:
        function FindThing: TThing; optional;

means you MUST check for nil. If the value is nil that’s not an error. 
“optional” is probably a bad name for this I know.

        function MakeThing: TThing;

this means maybe check for nil or maybe not check for nil. We don’t know what 
the programmer intended because no extra information was given (at least in the 
declaration). Because of the name we probably assume this is going to return a 
new object which is safe so checking for nil would be a waste.

I would actually argue that it is infinitely more important to check for nil after MakeThing. (Unless I know for sure it is not needed: proof, docs)

Assuming (taking the danger of doing so) both do what there name indicates, then: - If I forget to check after FindThing, it is likely to cause an error very soon, and most probably while I am testing myself. - If I forget it after MakeThing, it may be very rare to cause an error. It will likely pass my tests, and cause a customer of mine some stress.


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to