This is more of a style question than a technical one. I am experimenting with value types by building a simple poker card system.
I have a 'Deck' struct which consists of two UInt64 (one for the cards in the deck, and the other for the discard) and has various functions for drawing cards, discarding, shuffling, etc.... There is, of course, also a 'Card' struct with sub-enums for rank and suit.
The issue arose when I made a 'Hand' struct (which is basically just an array of Card structs + helper functions). As I was adding functions to discard a hand, I found I had a few options:
- discardHand(hand:Hand) on the 'Deck' - This discards the hand, but the hand struct which is passed in will still contain the cards afterwards, which feels a bit weird to me (perhaps I am just too used to reference types). Could this lead to errors because someone expects the hand to be empty afterwards?
- discardHand(inout hand:Hand) on the 'Deck' - This discards the hand and updates the hand struct, but is called 'discardHand(&hand)' which is surprising to me because it isn't reflected in the name (is there a naming convension to let the caller know they need to use '&' besides the compiler error?)
- discardHand(hand:Hand)->Hand on the 'Deck' - This discards the hand and returns a new empty hand.
- discard(deck deck:Deck) on the 'Hand'- This results in an empty hand, but unchanged deck... which is a non-starter because things are out of sync
- discard(inout deck deck:Deck) on the 'Hand'- Similar to #2
- Make hand an object - This would give the reference behavior I am used to, but it seems strange to have one object be a reference type when all of the others are value types
- Make everything an object - This would somewhat defeat the purpose of my explorations, but perhaps value types are a bad fit for this problem (though I doubt it)
From the perspective of someone who would be calling this function to discard a poker hand, which of the above would give the behavior that you most expect? Do you expect the hand that you pass to discardHand() to be empty after the operation? Is there an option which I am missing?