Created
December 7, 2019 20:41
-
-
Save heimeshoff/7019be2ab8e8e20c3dffc848b47252f0 to your computer and use it in GitHub Desktop.
Ubiquituous language tradeoff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Which do you prefer and why? | |
Alternative ideas? | |
public Tickettransaction Buy_ticket(Attendee attendee) | |
{ | |
if (tickets_available) | |
return Issue_Ticket(attendee); | |
else | |
return Not_Issued.Because("Box office should not allow to buy tickets, when there are none available."); | |
} | |
public Tickettransaction Buy_ticket(Attendee attendee) | |
{ | |
return | |
tickets_available | |
? Issue_Ticket(attendee) | |
: Not_Issued.Because("Box office should not allow to buy tickets, when there are none available."); | |
} |
I prefer early returns for these things
public Tickettransaction Buy_ticket(Attendee attendee) {
if (no_tickets_available) {
return Not_Issued.Because("Box office should not allow to buy tickets, when there are none available.");
}
return Issue_Ticket(attendee);
}
...but it's probably a matter of taste
@bwaidelich I would be happy with Guard Clause here, too, but I tend towards ternary operator for clearly a simple binary decision. Similarly, I see it has merely a preference.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very clearly a binary decision. Both branches are very simple. For these reasons, ternary operator is perfect.