3 ms·
I am not sure I would agree that the deck example he gave represents the Scala idiom. I myself would probably start with something like ======================
by kailuowang 13y ago
I am not sure I would agree that the deck example he gave represents the Scala idiom.
I myself would probably start with something like
========================
object Cards {
type Deck = Seq[Card]
case class Card(r:Rank, s:Suite)
type Rank = Int
sealed trait Suite
case object Spade extends Suite
case object Heart extends Suite
case object Diamond extends Suite
case object Club extends Suite
}
==================================
Granted, all this code is unnecessary in Clojure but there are two benefits of writing them:
1) compilation type check
2) for developers who have no context of playing cards, this provides a clearer picture, while in the Clojure code they will have to browse more code to get the full picture of the data domain.
- wpietri 13y agoI think that last part can be especially important. I'm perfectly comfortable with both approaches, but as things get bigger, I value explicit structure more than convenience. When I'm dealing with implicit structure, I definitely notice the increased cognitive load. That's fine for something small, short-lived, and personal. But if I'm doing something large, long-lived, and shared across many people, I think implicit structure gets more and more dangerous. It's hard to keep everybody's mental models aligned over time, which makes it easy to end up with a code base whose coherency declines.