You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When passing null arguments to functions returning status, in general intended behaviour is to either cancel or condone the task; sometimes the function itself can make an informed decision; sometimes it makes more sense for the caller to decide.
A good implementation of Equip should not fail silently. Then, assuming a bare-handed attack is acceptable, let's use the ? unary operator:
# Will condone Equip (do not invoke; return true) if 'weapon' is null
task Attack(target, weapon) => Equip(weapon?) && Strike(target);
Meanwhile the above function wouldn't be good if it made an agent equip a weapon while no target is defined; in this case, use the ! operator to fail early if a null is passed as target:
# Fail and do not run the task if 'target' is null
task Attack(target!, weapon) => Equip(weapon?) && Strike(target);
The text was updated successfully, but these errors were encountered:
When passing null arguments to functions returning status, in general intended behaviour is to either cancel or condone the task; sometimes the function itself can make an informed decision; sometimes it makes more sense for the caller to decide.
Example:
A good implementation of
Equip
should not fail silently. Then, assuming a bare-handed attack is acceptable, let's use the?
unary operator:Meanwhile the above function wouldn't be good if it made an agent equip a weapon while no target is defined; in this case, use the
!
operator to fail early if a null is passed as target:The text was updated successfully, but these errors were encountered: