Those making use of triggers in AccuRev software configuration management (SCM) have probably found that it’s possible to get as granular as desired when deciding what operations to restrict/allow and for whom. The support of regular expressions to define business logic can be quite a powerful mechanism while still being as flexible as necessary.
Here’s a twist to the standard sample logic written in the examples provided by AccuRev. As you can see, the sample uses the logic (and pardon the pseudo-code) “IF condition NOT met THEN disallow action OTHERWISE allow action”.
This works for some situations and you can certainly add more scenarios where the action shouldn’t be allowed. But what may likely occur is that as your business grows or changes, you might find yourself inserting more and more “Hey, you can’t do this” rules. That’s where the twist comes in. This sample reverses the logic to “IF condition IS met THEN allow action OTHERWISE disallow action”.
As you can see, you have certain conditions that are going to sail through with the thumbs-up; if you get the thumbs-up, the trigger exits knowing you have the correct permissions regardless of what other factors may be involved, if not it keeps checking for a subsequent condition. If none are met, it will exit with the big ‘ol rejection. Contrast this with the first example, the “Glass Half Empty” way, where the trigger exits on the first failure and it doesn’t know that perhaps another condition was about to be met. The new way makes it a lot easier to maintain, order of the clauses becomes far less important, and I’d call it the “Glass Half Full” approach…
For extra credit, based on what was just discussed, can anyone point out the (perhaps) obvious optimization to the Glass Half Full snippet?

