Intermezzo: Explicitly calling INSERT(FALSE), MODIFY(FALSE), DELETE(FALSE)
January 26th, 2012
Normally, I try to write the minimal amount of code: e.g. I don’t think you’ll ever see me write NEXT(1) when a simple call to NEXT suffices. In some cases, however, I do write INSERT(FALSE), MODIFY(FALSE) or DELETE(FALSE) in order to show future maintainers of my code that I explicitly chose not to call OnInsert, OnModify or OnDelete (instead of having forgotten to even consider calling the trigger in question).
Makes sense? ![]()
January 26th, 2012 at 5:42 pm
It absolutely makes sense!
But it\’s easier for the ones dealing with your code afterwards to know WHY you choose that way.
So adding a short comment aside would be even nicer.
January 26th, 2012 at 6:30 pm
Hmmm… As much as I hate comments (because they are so often used for the wrong reasons), you may be right…
Then again, when you write INSERT/MODIFY/DELETE without any parameters, do you normally add a comment explaining why you’re not calling OnInsert/OnModify/OnDelete?
(Thanks for your response!
)
January 30th, 2012 at 5:24 pm
I hate default values. A lot of times (especially if something doesn’t work and you have to fix it), it is not clear if the programmer forgot to put MODIFY(TRUE) or he meant MODIFY(FALSE). So I use MODIFY(FALSE). (And I also always initialize local variables in functions even if they are initialized by default.
January 30th, 2012 at 6:51 pm
@kriki: We seem to agree about the first point - indicating explicitly if you don’t want to call OnInsert, OnModify etc.
I’m not sure about the second part, though. When calling e.g. FINDSET, or even NEXT, do you always specify all parameters, even if they have their default value?
January 31st, 2012 at 6:32 pm
FINDSET: yes.
NEXT: I have to admit that I don’t use it in this case, because 99.999% of the time it is the default. And if you don’t use the default and forget to put the value, you see immediately that it doesn’t work (at least if you do a bare minimum of testing your code).