Hands-on Rust: How simple is simple? (pg. 107)

On pg. 107, there’s a prompting to remove some code from tick to leave it a “simple stub”:

impl GameState for State {
  fn tick(&mut self, ctx: &mut BTerm) {
    ctx.set_active_console(0);
    ctx.cls();
    ctx.set_active_console(1);
    ctx.cls();
  }
}

That is simple enough, it’s true. But by the page 112 rolls around, there is a new implementation.

impl GameState for State {
  fn tick(&mut self, ctx: &mut BTerm) {
    ctx.cls();
    self.resources.insert(ctx.key);
    self.systems.execute(&mut self.ecs, &mut self.resources);
  }
}

Since the user hasn’t been asked to run in the interim, it would seem that the simple stub could be even simpler.

impl GameState for State {
  fn tick(&mut self, ctx: &mut BTerm) {
    ctx.cls();
  }
}

This makes the pg. 112 addition additive only. In this reader’s experience, I’ve worked a lot with ctx.cls(); at this point, but only had one touch point with the active console idea, which I’m now asked to replace without that same comfort level. If the idea is only to have a simple stub, perhaps it can be simpler!

Thanks!

1 Like

Thank you - I think you’re right. I’ll re-read that section in detail this afternoon and see if I can simplify that. I think the bug goes the other way - the second tick function really should be clearing all the layers.

2 Likes

Having completed the exercise, I think it’s reasonable to guide the reader to leave a comment in during stubbing.

// TODO: manage our draw buffer 

Then the instructions naturally enough return to replace the comment with render_draw_buffer.

3 Likes

Thanks! I’ve added that to the issue tracker, it’ll make beta 3. I think instructing the user to make comments is generally a good idea; there would be more of them if I wasn’t in danger of running out of pages!

2 Likes