nonconsuming choice Follow: ContractId User with
userToFollow: Party
controller username
do
assertMsg "You cannot follow yourself" (userToFollow /= username)
assertMsg "You cannot follow the same user twice" (notElem userToFollow following)
archive self
create this with following = userToFollow :: following
Why is a nonconsuming choice used if this choice archives itself? How does this functionality differ from a regular (consuming) choice?
We need nonconsuming choices in the getting started guide anyway (SendMessage needs to be nonconsuming) so we decided to use them consistently to only introduce one concept.
There is however a difference in general: A nonconsuming choice is only seen by signatories and the actor. A consuming choice on the other hand is seen by stakeholders and actors so observers see a consuming choice while they do not see a nonconsuming choice. For the Follow choice this is not really important since all observers of the current User contract are also observers of the User contract created at the end of Follow so while they see it. But if you have a choice where this is not the case you avoid accidentally leaking more information to observers than you might have intended.
IMHO using the controller syntax would be more intuitive as the first piece of DAML code new users see, even if it comes at the expense of needing to explain another concept a bit later
controller username can
Follow: ContractId User with
userToFollow: Party
do
assertMsg "You cannot follow yourself" (userToFollow /= username)
assertMsg "You cannot follow the same user twice" (notElem userToFollow following)
create this with following = userToFollow :: following
Hello!
Finding this issue as I was going to ask the exact same question.
I’d also be inclined that it would be more user friendly to use a consuming choice and explain later the difference.