Categories
Review

“Two Suns at Sunset”

Gene Doucette

I really, truly, had no idea what I was in for with this book. And I absolutely loved it — devoured the whole thing in an evening, and promptly added the sequel to my wish list. I desperately want to know where the whole series is going, because it’s a wonderful mystery.

The setting feels near-feature, and has some things that are very clearly influenced by what’s going on in current events.1 Except for the whole “this isn’t Earth” thing, which combines with some of the linguistics and a few mentions of a distant-past Collapse, to have me think that it’s actually far-future, and we’re looking at a colony that’s building itself back up towards interstellar travel after a galactic-scale human civilization… well, collapsed. Which means that the founding mythology, and some of the hand-wavey end of the world prophecy stuff going on could, in fact, be leading up to some large-scale science fiction things. Hey, look at that, we’ve looped back around to “I desperately want to know where the whole series is going,” how about that.

Sitting on top of this wonderfully rich setting, though, is a very fun police procedural/murder mystery thing, and that is also a delight. A murdered monk, a cynical cop, his new upbeat rookie partner, it’s a hodgepodge of well-worn tropes and new twists, and it works so very, very well.

If any of this sounds interesting, please read the book — I greatly enjoyed it, and hope you will as well.2

  1. There’s a two-page interjection explaining a cryptocurrency that’s Definitely Not Bitcoin. To my knowledge, it’s fairly accurate, and highlights one of the key potential failings of the technology, while leaving out the primary failing of it. That said, this world apparently has nuclear power pretty figured out, which mitigates the energy concerns, so, I’ll allow it.
  2. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

“When You Had Power”

Susan Kaye Quinn

The author bills this book as ‘hopepunk,’ but the term I’m more familiar with is ‘solarpunk.’ Either works, though — the vibe is that of a hopeful future, where we make our way through the energy transition and wind up not, y’know, climate changing ourselves into extinction. Which is a future I sincerely hope we wind up in, because I like not being extinct!

To put it shortly, I adore the setting of this book. It’s near-future, with technology that all feels very believable for a near future, and a very fitting backdrop of the global energy transition. And I’m always here for a found-family story — Tamora Pierce really established that archetype for me with the Circle of Magic, so I can’t help but love it.

The only failing of this book is that it isn’t finished. We see the B plot through, but the A plot is left entirely hanging, and having just skimmed over the descriptions of the other books in the series, it looks like that thread won’t get tied up until the fourth book, which is due for release nearly a year from now. I want to know what the bad guys are up to! I’m not nearly patient enough for this.

If you, like me, are impatient, wait until September 2022, then read all four books at once. If you’d like to get started now, go check it out.1

  1. This is an Amazon affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I prefer Bookshop affiliate links to Amazon when possible, but in this case, the book wasn’t available there, so it’ll have to do.
Categories
Review

“The Hammer Falls”

Travis Heermann

I’m of mixed feelings about this book. It’s a fun setting — a little post-apocalyptic in places, but mostly it’s that ‘megacorporation rule’ that feels closer to cyberpunk than any other genre. And while I hate that as a possible future, I do think that this book handled it better than I could’ve expected, so that’s a positive.

But then the negatives: the protagonist is only occasionally likable, and the way women are treated feels almost like someone set out to deliberately flunk the Bechdel Test. Arguably, that’s on purpose, as it’s in keeping with the way said occasionally likable protagonist would think, and it’s told from his perspective, but it still grates somewhat.

In the end, though, I made it to the end of the book, which is the main test I have.1 If you’re interested, you can learn more about the book here. 2

  1. Somewhere, I have a graveyard of books I started and didn’t finish; I’m stubborn, but I won’t force my way through a book if it’s just not enjoyable. Life’s too short for that.
  2. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

“Cloud Permutations”

Lavie Tidhar

It took me a while to come up with it, but the best description I have for this novella is “impressionistic.” It varies from being told up close by the protagonist, and drifting outwards into discussion of how historians tried to piece together the events of the story years later. It’s a folk tale of the distant future, a Promethean moment as someone pulls this corner of humanity out of a localized Dark Age.

The setting does a great job in establishing a sense of scale. Because you have forgotten technology of the ancients on the scale of “this is a colony, we remember the part of our history where we got here via interstellar travel, but now our highest tech stuff is boat engines”… set against a backdrop of what I interpreted as mysterious nanotechnology and Kardashev tier 2-3-ish feats of engineering.

It’s a pretty quick read, and different enough from the usual fare of science fiction, and I do recommend it. Give it a read.1

  1. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

“The Stark Divide”

J. Scott Coatsworth

I absolutely adore hopeful science fiction; dystopian and post-apocalyptic is fine for when the world isn’t ending, but in the midst of a global pandemic and a climate disaster, I want something hopeful. And this, despite the future Earth being a climate-change-wracked disaster, is hopeful.

The world may be ending, but it’s the end of a world, not the end of humanity. In the three parts of this book we see someone plant the seed, encourage the growth, and launch a generation ship. Three of them, in fact, though we only ever see the first. And that’s hope, to me—a chance at a better future. (And hey, it doesn’t hurt that it’s a queer author, including queer characters; a well-rounded population is a necessity for a generation ship!)

So hey, give hope a chance.1

  1. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

“Becoming”

Michelle Obama

I really wasn’t sure what to expect, going in to this book. I’m not a big memoir person, and it did take me a while to really get into the book, but I’m glad I stuck with it.

I think the most useful takeaway for me, from this book, is that it humanized Michelle. It’s easy to look at the occupants of the White House and think of them as these far-off figures, something akin to demigods for how remote their lives are from mine. Which remains true—the experience of living in the White House is so different from any aspect of my life I can barely imagine it—but we are all only human.

What I enjoyed the most was hearing about the limitations that come with it. It’s one thing to fantasize about it: “imagine being part of the First Family, you get to meet so many interesting people and be so close to history as it’s happening!”1 But the reality is motorcades and secret service escorts. Knowing that any time you want to go out for dinner, you’re causing traffic jams and costing the taxpayers tens of thousands of dollars in additional security costs. Even something as simple as “I’m going to sit on the balcony to drink my morning tea” becomes a mess—because, as Michelle notes, sitting on the balcony for her meant the Secret Service closing off a nearby street from which the balcony was visible. You can’t use a portion of your home without it disrupting the lives of hundreds of other people.

Michelle’s story is inspiring, and tragic, and delightful; it is entirely, perfectly human. I absolutely loved this book, and highly recommend it—even to my fellow “not a big memoir” people. Give it a read.2

  1. I’ve long since abandoned the dream of the Presidency. Being responsible for the entirety of the United States sounds like a special circle of hell, and no amount of escapist fantasy can paper over the sheer, staggering, impossible weight that the President has to bear.
  2. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

“Ganymede”

Jason Taylor

I very nearly gave up on this book partway through. It felt like it was starting to fall into territory that I really don’t enjoy, with the author using the book to espouse their religious beliefs.1 I took a break, skimmed the leaf description again, an decided to give it another go, and managed to get hooked again.

While I can’t call it “hard” science fiction, because there’s some definite hand-waving about how things actually work, it’s certainly not “soft” science fiction, either. There’s clearly a system underlying all of the sci-fi elements, it just requires a bit of accepting “eh, it’s distant enough in the future that we’d probably have figured that out” and you can carry right along.

The setting is pretty interesting, overall – it’s a not-too-distant future, but the world has had some Busy Times in the interim. There’s a bit of the dystopian “the world is much worse than it looks, but our AR glasses make everything look fine, so who cares!” thing that I honestly despise, but underneath that grime there’s also a distinctly hopeful vibe to what’s actually going on. The best setpiece is definitely New Washington—rebuilding DC, following a nuclear bombing, as a network of bunkers buried below the continental shelf, with New Dulles as a floating airport/city above? Distinct Fallout vibes, in the best of ways.

Lastly, I’ll add that I can very clearly see one of the key influences for this book. What I won’t do is reference here what that is, because spoilers. If you’re curious, click through the footnote.2

All in all, I quite enjoyed this book. It takes it a while to really get going, but by the end it’s a delightful work of science fiction. Give it a read.3

  1. It’s okay for authors to do this in books! Just like it’s okay for me to not want to read those books as a direct result.
  2. Andy Weir’s “The Egg”
  3. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

“Innate Magic”

Shannon Fay

There’s… a lot going on in this book, and having given myself the chance to sleep on it, I’m still not sure how I feel about it. Even trying to make a pros and cons list hasn’t helped much. Pro – interesting system of magic. Con – weird theological angle. Pro – bisexual protagonist, yay for representation! Con – save for a single passing reference in the epilogue, all the homosexual relationships portrayed are various forms of abusive. Pro – several interesting female characters whose stories I’d like to learn more of; con – I can’t recall them, at any point, passing the Bechdel test.1

At very least, though, I can’t say the book wasn’t interesting. It took quite a while to really grip me, but by about halfway through I found myself loathe to put it down. Which, in retrospect, is the same way I tend to feel about Diana Wynne Jones, and she wrote some of my favorite books I’ve ever read, so… I suppose, by that metric at least, I enjoyed it.

A confused little review here, but as I said, it’s at very least an interesting read. Check it out.2

  1. Admittedly, I wasn’t keeping an eye out for it, and am now trying to recall from memory. I suppose there’s a scene where two of the aforementioned interesting female characters discuss one’s past, but it’s mostly in the context of her father, so…
  2. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

“The Planetbreaker’s Son”

Nick Mamatas

More ‘literary’ in feel than I usually go for, but it works. A time capsule, a billion people digitized and attempting to preserve what humanity was before we wiped ourselves out, held together by advanced technology and algorithms… it’s nice to imagine that we’d be able to retain every aspect of our humanity through a transition like that, but it also doesn’t seem that realistic. Things would have to change.

As I said, there’s more of a ‘literary’ style to this than what I usually read, and it definitely took me a while to really get into the story. But by the end, I found I quite enjoyed it, and a lot of what had been confusing me made more sense. The interview with the author also helped – provided some perspective, I suppose.

A fun little read; check it out.1

  1. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

“The Caledonian Gambit”

Dan Moren

If memory serves, Moren has just released the sequel to this book, and I may have to pick it up. I wouldn’t say that “The Caledonian Gambit” was, like, earth-shatteringly good, but it fit my mood just right. It’s been a while since I read some light science fiction, it’s been a while since I read an espionage thriller, it’s been a while since I read something doing something really fun in that space.

I’ll sound the spoiler horn here – if you want no hints whatsoever about the plot, just go read it now.1

Alright, spoilers ahead!

I think my favorite thing in this book was the perfect payoff, how every aspect of the prologue went on to be massively important to the remainder of the book. It did a great job of seeming like a throwaway moment, but kept coming back in little bits of “oh, you thought that didn’t matter? Surprise, it did!”

And, having myself paused for the spoiler break (because apparently that’s how my brain works), I realized why I’m excited for the sequel: because I’ve actually read this exact plot before. It’s an early arc of Schlock Mercenary, although definitely played differently than it was there, and I’d love to see what someone else does with that idea. (Although, if you’re at all interested in comics and space opera, I highly recommend Schlock Mercenary, as well — it starts off very “lol it’s the 90s and I’m making a webcomic!” but by the end, it’s one of the best pieces of large-scale science fiction I have ever read.)

  1. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

“Atomic Habits”

James Clear

My life is in flux at the moment. I’ve just recently started a new job, and as a very direct consequence, have to change up some of my outside-of-work doings as well. Happily, I decided to start my project list by going through some of my backlog of books, and alphabetical ordering landed me on this loan from a friend. It’s a good one for times of flux.

As a longtime fan of Cortex, I can’t say that there was anything groundbreaking in this book. Just about everything in it I’ve read or heard in some form or another before, but that isn’t necessarily a bad thing. It’s one thing to know this stuff, and another to have it all put together in one place, coherently summarized.

So as not to be taking bread out of the mouth of James Clear,1 I’m only going to reiterate one of the core ideas. If you want to encourage yourself to do something, make it easy to do; conversely, if you want to discourage yourself from doing something, make it hard to do. The single best example of this is eating healthy: if you want to eat less junk food, buy less junk food. It’s a simple concept, but it’s hiding something clever: if you buy the junk food, you have to have self control all the time to not eat it. And that, perceptibly, wears on you; by the end of a long work day, you may not have the mental energy left to resist.

On the other hand, if there’s no junk food in the house, there’s nothing to resist. Instead of resisting the urge to open a bag of chips, you’re resisting the urge to… drive to the store, buy a bag of chips, drive home, and open a bag of chips. That doesn’t take much resisting.

And meanwhile, the amount of self-control it takes to not buy it in the first place? Just make sure not to go grocery shopping while you’re hungry, and it’s not that hard at all. How much of your day do you spend in the grocery store, after all?

Atomic Habits is a very good executive summary of several thought technologies like this, and I highly recommend it. Check it out.2

  1. Or however that phrase goes.
  2. This is a Bookshop affiliate link – if you buy it from here, I get a little bit of commission. It won’t hurt my feelings if you buy it elsewhere; honestly, I’d rather you check it out from your local library, or go to a local book store. I use Bookshop affiliate links instead of Amazon because they distribute a significant chunk of their profits to small, local book stores.
Categories
Review

Star Trek: Lower Decks

I like the concept of Star Trek a lot — some of my favorite books growing up were optimistic science fiction, and the majority of Star Trek falls into that category. That said, I’ve mostly failed to actually get very much into Star Trek; without the nostalgia of having grown up watching it, I (watching in the ‘golden age of TV’) struggle to get past the date aesthetic of the older series.

All that said, Lower Decks feels like it was specifically targeted at me — I love the “adult animated television series” as a form of media, and it’s nice to have a clear entry point into the greater Star Trek universe.

The concept is pretty simple: instead of following around the bridge crew, what’s life like for the regular folks on a Starfleet ship? It feels more like a space opera: from this perspective you get glances into the crazy sci-fi goings-on, but half the time it’s just background dressing for interpersonal stories. It’s fun watching the characters shrug off a member of the bridge crew returning from the dead because “oh, they always do that. Probably they got Borg’d, or it’s a transporter clone, or something.”

Having it as animation also works quite well. It frees them to do ridiculous scenes without blowing through an entire season’s worth of special effects budget. It’s a lot easier to animate the aforementioned transporter clone scene when you just… draw the person twice and have them record two takes. No compositing shots together, no body-double in a green-screen suit. And, I hope, it will allow the animation to remain much more timeless than the live action shows can manage.

All told, I quite like Lower Decks, and do recommend it. As of this writing, we’re about halfway through the second season, with new episodes coming out every week, so go ahead and check it out. Each episode is around half an hour, and they work well as a palate cleanser between heavier series. Check it out.

Categories
Technology

Async/await in Vapor

Swift 5.5 with the new async/await features is going to be released quite soon, and I’m very excited. And while all the new async APIs in UIKit and SwiftUI are neat, they don’t actually catch my eye all that much. As of now, async/await will only be available on the fall-2021 Apple OS releases, and following the general pattern of “current iOS minus one” that means async/await will be available starting… fall of 2022.

However, that’s not the only place I use Swift! I also dabble in server-side Swift when I can, and over there, it’s ready-ish to use now.1

And hey, would you look at that, Vapor’s already got a PR open for adding async variants of the core APIs. Neat! Let’s see how this is implemented.

And, hey, it’s… pretty simple, really! All it takes is getting into the (pre-release!) _NIOConcurrency module, and suddenly any EventLoopFuture has a new function: public func get() async throws -> T. The implementation of that is also lovely and simple, thanks to Swift’s withUnsafeThrowingContinuation and the way SwiftNIO already works.

Now, where I’m more excited about this than Vapor is in Fluent — a lot of the server-side work I do is in C#, using the excellent Entity Framework Core. Database requests are straightforward: MyModel model = await db.MyModels.FirstOrDefaultAsync(m => m.id == id);

With the non-async version of Vapor and Fluent, this is… a bit more difficult to work with. MyModel.find(id, on: req.db).flatMap { model in ... }

At first glance it doesn’t look too bad, but notice the flatMap — we can’t just continue writing our code, we have to move into a new scope. Hello, pyramid of doom.

But now?2 Now, we can await things. Fluent looks more like Entity Framework all of a sudden: let model = try await MyModel.find(id, on: req.db)

That’s already a much nicer API to work with, and it delivers on the promise of async/await: much simpler flow of code. I’m excited to untangle some of my more complex flatMap pyramids.

What I’m still curious about, and will need to do some testing with, is to see how well it does with concurrency. It’s a known issue in Entity Framework that you can’t run multiple requests against a single DbContext; what I’m wondering is if Fluent has this same limitation, or if I can safely do something like:

async let model1 = try MyModel.find(id1, on: req.db)
async let model2 = try MyModel.find(id2, on: req.db)
let result = MyResult(model1: await model1, model2: await model2)

That, I don’t yet know! I’ll have to do some experimenting and try it — which may be a future blog post. Still, even if I have to immediately await everything, the improvements to my code’s legibility will be worth it.

  1. Disclaimer: Swift 5.5 is, as of this writing, pre-release; similarly, the versions of Swift-NIO and Vapor that provide async APIs are pre-release. Don’t use these in production.
  2. Well, soon: this as another draft PR as of this writing.
Categories
Programming

Islands.swift

Back in undergrad, I did a lot of programming challenges – the sort of thing that shows up as a somewhat-contrived question in an interview. Great way to learn about automated testing, though, as in a school environment it’s basically an automated test suite where you aren’t allowed to see the tests.1

I’ve been wanting to brush up on algorithms a bit, and figured this would be a good way to do it. This time around, though, I’m using Swift; C++ was a fine language to learn, but I have exactly no desire to use it anymore.

So, the first problem I found whilst aimlessly googling was “Islands”. Given a grid of some sort (could be [[Bool]], although in this case I’ve done one as [[Character]], with '1' and '0' being the inputs2), count the number of islands in it.

An island, in this case, is any contiguous collection of '1' is in the grid, while all the the '0's are ocean.

Step One: Ask Questions

First question: what does ‘contiguous’ mean? Can we move diagonally, or only in the four cardinal directions?

Only the four cardinal directions, in this example.

Alright. Next, what happens at the edges? Do we Asteroids-style loop around, or is it just ‘out of bounds == ocean’?

Out of bounds is ocean.

Excellent! Means we don’t have any literal edge cases.

Final question before I start actually digging into the problem, how are we hooking into the test case?

protocol Islands {
  func numIslands(_ grid: [[Character]]) -> Int
}

Alright, simple enough. Let’s get cracking.

Step Two: Brainstorm

My first thought upon seeing a grid is “flood fill.” Now, this isn’t quite a flood fill, because the whole point is that it’s not all interconnected, but that at least gives me a starting point – for a flood fill, you want recursion. And you want to remember where you’ve been, so you can make a base case – otherwise, you’ll just loop forever. O(infinity) isn’t really ideal.

So, what’s the actual algorithm here?

Simple enough: for each point on the grid, check if it’s part of a new island. If it is, add one to our count of islands; if it isn’t, don’t. Move on to the next point on the grid.

Now, how do we check if it’s a new island? Also pretty simple: check if we’ve been here before; if we have, it’s not a new island. Then check if it’s an island; if it isn’t, it’s also not a new island. And, now that we know it’s a new island, we go recursive – mark that we’ve been to this spot, and flood fill our way across the neighboring tiles on the grid until we run out of island.

Step Three: Code

class Solution: Islands {
    private var visited: [[Bool]] = [] // (1)
    private var grid: [[Character]] = [] // (2)
    
    @discardableResult
    private func isNewIsland(x: Int, y: Int) -> Bool { // (3)
        guard x >= 0 else { return false }
        guard y >= 0 else { return false }
        guard x < grid.count else { return false }
        guard y < grid[0].count else { return false }
        if (visited[x][y]) { return false } 
        visited[x][y] = true
        if (grid[x][y] == "1") {
            // visit all neighbors
            isNewIsland(x: x+1, y: y)
            isNewIsland(x: x-1, y: y)
            isNewIsland(x: x, y: y+1)
            isNewIsland(x: x, y: y-1)
            return true
        } else {
            return false
        }
    }
    
    func numIslands(_ grid: [[Character]]) -> Int { // (4) 
        // precondition checks
        guard grid.count > 0 else {
            return 0
        }
        guard grid[0].count > 0 else {
            return 0
        }
        // reset visited state
        let subItem = Array<Bool>(repeating: false, count: grid[0].count)
        self.visited = Array<Array<Bool>>(repeating: subItem, count: grid.count)
        self.grid = grid
        var islandCount = 0
        for i in 0..<grid.count {
            for j in 0..<grid[i].count {
                if isNewIsland(x: i, y: j) {
                    islandCount = islandCount + 1
                }
            }
        }
        return islandCount
    }
}

Let’s go through this bit by bit.

  1. visited is key – we need to know where we’ve been. Unlike the folks making the problem statement, I actually know what my data type is – [[Bool]]
  2. This… is mostly for ease of passing it around. While I could write up my isNewIsland function in a purely-functional sense, with it taking in the coordinates, visited state, and grid, and then outputting the result… well, that’s kinda silly, really.
  3. isNewIsland is the bulk of the work. Let’s go through it.
    • The first four lines are checking that we’ve got valid input. This saves us from needing to check the range every time we call the method; if we try to do something that we can’t, it’ll just return false. Admittedly, I’m not checking that the grid properly exists before using it, but that’s what private is for – this is an implementation detail.
    • Next, check if we’ve visited this spot before. If we have, we’re done – it’s not a new island!
    • Before we go any further, mark this spot as visited! Important, because we may be recursing shortly, and we don’t want to get caught in an infinite loop.
    • Check if this is an island at all. If it isn’t, we’re done – this wasn’t a new island. If it is, though, we recurse. This is where the @discardableResult comes in – since we’ve got an early bail-out for “we’ve already visited this spot”, we know we’ll never be checking the same island twice, so we actually don’t care about the result of checking the neighboring spaces, we just need it to happen… so that they get marked as visited. And after we’re done marking the whole island as visited, we can finally return true, telling the caller (if they’re listening!) that this was a new island.
  4. Finally, our implementation of numIslands. Mostly it’s just checking for valid inputs – Swift can enforce at compile-time that nobody tries to pass us anything completely the wrong type, but it can’t force people to give us a grid with dimensions greater than 0 in either direction, so we need to check that ourselves. After that, we set up our visited as all-false, copy the grid, and loop through it, counting up our islands.

Step Four: Test

This part, I will mostly leave to your imagination; for myself, I just hit ‘run’ and let the automated tests do their thing. In an interview, Step Two should also include coming up with some test cases and running through them on your pseudo code – and remember to include one or two invalid inputs!

After that, if your tests pass, you could talk about changes you might make. Given my numerous remarks about [[Character]] instead of [[Boolean]], my thought would be to make it generic – have a grid of [[T]] and take a (T) -> Bool closure that tells you whether or not a grid point is an island. I’d also want to comment up the code a bit more, which I’ve neglected to do in this case as I’m writing a blog post around it instead.

Now, having already spoiled the answer, I’ll go ahead and mention that I tried this out at LeetCode; while this one may not be the most fun for you in the immediate wake of my explainer, they’ve got plenty of other solutions you could take a crack at, and a variety of languages to use. Give it a go, it’s kinda fun!

  1. Basically, the inverse of an “opaque box” analysis, if you think about it.
  2. And by “I’ve done one” I mean “the site that gave the example,” because I… wouldn’t use [[Character]] to represent a [[Bool]].
Categories
Review

“Fine Structure”

Sam Hughes

I actually read this almost immediately after “Ed”, and it makes for a heck of contrast. Where “Ed” is mostly pretty light and quick, this is all kinds of convoluted in terms of what’s going on with the plot. But it also does that thing that Hughes does really well—it spans a massive amount of time and space, and covers a staggering amount of ground.

The basic concept is truly excellent, though: what if, every time you tried some Cool Science Fiction Thing, it worked—once. And then never again.

It’s a really interesting constraint for a work of science fiction, as well: how can you do enough Cool Science Fiction Things for a full book, when the core concept is that those concepts are consumable? It makes for, as I said, a sprawling world that must be built out—larger than “Ed” or “Ra” had to be, and bringing in some definite “higher-dimensional beings would look a lot like Cthulhu, wouldn’t they?” energy.

The end result is, I can’t recommend this as readily as I did “Ed”, because it’s boggling at times. But it’s a great payoff, and ties together things you wouldn’t at all expect, much better than you’d expect. If that sounds good to you, give it a read.