Little has options. Little can stay with Petey. Little can pull Pedro and bring in a lefty (Alan Embree). He can bring in knuckleballer Tim Wakefield who owned Matsui that year (.167/.167/.167) and had good numbers against Posada as a starter. Or he can bring in right-handed reliever Mike Timlin who he had warming up.
After talking with his ace, Little opts to stay with Pedro.
Matsui proceeds to hit a ground rule double putting Williams on third with the score 5-3 Boston.
Up next, switch hitter, Jorge Posada.
Again, Little has options. He can stay with Martinez who has struck out Posada more than any other pitcher so far in Posada's career (30 Ks). He can pull Martinez for Wakefield who had good numbers against Jorge (.235/.325/.619). Maybe he summons a Mets fan from River Avenue (Where's Sidd Finch when you need him?). And then this happens:
In our last post we talked about Booleans and how they are particularly helpful when you need to write a function that only has two outcomes: If something is True then do this; if something is False then do that. Did Babe Ruth make more than the president? True, he had a better year. Did Steve Lyons inadvertently drop his drawers at first base? True, they did call him Psycho after all. Did Sidd Finch throw 138mph? False! He threw 168.
But as we see with Grady Little, sometimes there are more than two options. This is when we use switch statements. Let's take a look at this scenario played out in code:

To make it all flow a little better, try reading the code as, "In the case of Alan Embree, then Grady has a pitcher who's fresh. It's lefty versus left. But Matsui is .375/.333/.708 against him...In the case of Mike Timlin, then Grady has..." And so on.
Something to note here: See the "default" option at the end? Switch statements require a default. Why? Because they must be exhaustive. They must account for every possibility even ones you haven't thought of. The default offers a catch-all option in case none of the cases you laid out occur. If you try to write a switch statement without a default option the program won't run. Here's a better example of the default:

In this case, despite the efforts of Woody English, Bill Serena, Larry Bowa, Rick Wrona, Doug Strange, and Kosuke Fukudome (to name a few), no Cub who ever wore #1 has ever had their number retired.
Challenge 1: Can you re-create a favorite what-if pitching change moment with switch statements? If so, take a screen shot and tweet it at me (@randallmardus).
Challenge 2: Can you create switch statements for the retired numbers of the players on your favorite team? If so, take a screen shot and tweet it at me (@randallmardus).
On Deck: Understanding String Interpolation Thanks To Your PA Announcer
No comments:
Post a Comment