Objects tend to confuse me some. In understand the concept and use, certainly, but I feel like the functional paradigm is somewhat restricting my use of them.
At the moment, I'm creating a simple code for a game of cards. Each player might have a simple object, like this:
object player {
name = "Steve";
score = 0;
hand = [/*...contains seven cards...*/];
}
and a object for a deck:
object deck {
cards = [/*...contains the other 45 cards...*/]
}
So for dealing new cards, the simplest way would just be to mutate the this.hand and the this.cards. But... mutation.
I can think of other ways to do it, but the purely functional ways I can think of feel messy.
At what point do you draw the line between mutable and immutable data, or what am I missing?
this
? If these are functions, why not pass them arguments? You don't need mutability here. With the small amount of data in a card game, you can easily simply generate entire new hands and decks and keep everything immutable, right?