Behind the Board

Behind the Board is a blog where we talk about the technical aspects of Scoreboard. If you're not a programmer, it might be a little dense for you—but if you are, this'll be hog heaven.

  • Valuable Models, Part V: Spreading the Word

    In Part I of this series, I discussed how my Apple TV app, Scoreboard, uses a model comprised entirely of value types, allowing me to centralize all view updates in a single property observer. In Part II, I discussed using an array diffing algorithm to figure out how to update the view. In Part III, I showed how you can give value types identities so you can tell an addition from an edit. In Part IV, I explained how this diff-based updating logic is shared by unrelated controllers.

    But there's still a significant problem with this approach. In a conventional object-based model, you can hand your own objects to other view controllers, and they can mutate them in ways that your code will see later. In a value-based model, other view controllers have their own copies of your models, and their changes don't affect your copies. How can you be sure to update the right part of your model?

    The answer comes back to the Identifiable protocol.

    Read More →

  • Valuable Models, Part IV: Sharing is Caring

    In Part I of this series, I discussed how my Apple TV app, Scoreboard, uses a model comprised entirely of value types, allowing me to centralize all view updates in a single property observer. In Part II, I discussed using an array diffing algorithm to figure out how to update the view. In Part III, I showed how you can give value types identities so you can tell an addition from an edit.

    We've made tremendous progress on supporting the list of Players in a given Scoreboard, but there's something else that needs doing. Scoreboard also has a list of Scoreboards that the user can switch between. Worse, the view controller that implements this list uses a table view, where the view controller for an individual scoreboard uses a collection view, so we can't use a common superclass. How can we avoid duplicating our diffing logic?

    Read More →

  • Valuable Models, Part III: Identity Crisis

    In Part I of this series, I discussed how my Apple TV app, Scoreboard, uses a model comprised entirely of value types, allowing me to centralize all view updates in a single property observer. In Part II, I discussed using an array diffing algorithm to figure out how to update the view. But when I left off, there was a major bug in that code: all changes were treated as adding or removing Players, not changing existing players.

    The basic problem is simple: When we ask ArrayDiff to compare two Players to see if they're the same, we tell it to use ==, the equality operator:

    self.scoreboard.players.diff(from: oldValue.players, match: ==)
    

    But two Player instances aren't equal unless all of their properties are equal. The result: any change to a Player is registered as removing the old Player and inserting a new one.

    What we really want is to compare identity, so changing the "same" Player is treated as an update, not a removal and addition. In other words, we want to use ===, the identity comparison operator:

    self.scoreboard.players.diff(from: oldValue.players, match: ===)
    

    But Swift won't compile that. What gives?

    It turns out we've made a mistake. In the move to value types, we've accidentally lost the ability to talk coherently about "which instances changed" at all.

    Read More →

  • Valuable Models, Part II: The Difference Engine

    In Part I of this series, I discussed how my Apple TV app, Scoreboard, uses a model comprised entirely of value types, allowing me to centralize all view updates in a single property observer. However, the updating code is pretty anemic at this point. It simply looks like this:

    var scoreboard: Scoreboard {
        didSet {
            collectionView?.reloadData()
        }
    }
    

    We would prefer it to instead insert, delete, and update cells as needed to match the new data. So let's make that happen.

    Read More →

  • Valuable Models, Part I: A Brief Introduction

    In the middle of developing my tvOS app, Scoreboard, I found myself tweeting ecstatically:

    Playing with my first serious project with an all-value-type model, and it just keeps getting more stunningly elegant.

    And then the next day, I added:

    You guys. I can’t even deal with how all of your updating logic *vanishes* when your models are value types.

    I thought I might explain these comments, because what I learned while writing Scoreboard will probably change how I write every app I ever make in the future.

    Read More →

  • Welcome to Behind the Board!

    Welcome to the Behind the Board blog! We'll occasionally use this area to post highly technical articles about the making of Scoreboard, starting with a six-part series on its unique model layer design. We hope you find it interesting!

    Read More →

subscribe via RSS