-
Notifications
You must be signed in to change notification settings - Fork 3
11-interfaces review #8
Comments
Thanks for the note on slide 4 James, I've fixed it now. Thoughts? |
I'd suggest starting with a stringer because it's quick and easy, so they can feel a sense of accomplishment (and the ah-ha moment of seeing the stringer called automatically by printf). Since they've already written a method for this in the last two exercises, it will be as simple as changing the signature of the function. It's also a pretty important interface. But even if you include a stringer exercise, I agree there should be something more challenging. I'm concerned that posting might take too long. But my exercise for the preceding talk is extremely short, so we could probably assume that my exercise will take half as long as scheduled, which would give you extra time (about 10 minutes total). It makes sense to group the exercise for methods and interfaces. I like the idea of leading into the capstone, as long as it's not too difficult. @boersn has emphasized that the exercises shouldn't be too difficult, but he knows a lot better than me how to judge that, so perhaps he can comment. |
@mckayb24's idea of an exercise that leads into the capstone is great, but I'm also a little concerned that it'll take too long. Do they have any exposure to the "http" package at this point? I wonder whether the exercise could be broken up into two parts. First, they write a stringer (and we expect everyone to finish). Second, they extend that program with the posting (and we expect ~50% to finish). |
In the interfaces lecture I finish by describing how different structs can be used as Readers which is used as the body for calls to Post. I describe how files and bytebuffers both already satisfy a Reader. In order to Post something the call is similar to: I plan to meet with Matthias tonight to piggy back off the work he already did setting up the capstone server unless of course the consensus is I should make it simpler and use Stringer instead. I'm actually conflicted now because James is right and seeing how adding a String method to a struct is used by fmt.Println is cool and useful. Thoughts? |
What type of data does Matthias's server accept? Can it have an API that accepts a string, returning status code success if it got a string?
However, the problem with step 2 is that the Perhaps this:
But I think that's too many steps, and the io.Reader stuff is still magic. I think the problem is that with But I can't find any other good options in the standard library. (List of interfaces: http://blog.fraixed.es/post/a-walk-through-golang-package-interfaces/) Perhaps Since it's very common to convert between types using built-in functions to implement interfaces, perhaps this is still a good example question, but we should be prepared for more questions than usual. Any time we spend addressing this here is time we would have spent during the capstone, anyway. This could get slightly simpler if we just ask the students to post a known byte slice to the server, instead, but that doesn't explain the magic any better. EDIT: to improve wording of exercises |
I suppose, Brett, that since you're explaining |
I think we differ on what we think the take away from the interface talk is. What I think the take away should be is that interfaces can accept different underlying types. Until we get to interfaces we drive home the fact that Go has a very strong type system. Interfaces allows code to be re-used by different data structures. By my way of thinking I don't actually care if they write the method as long as they understand that they can use different data structures. However, you're right that it will be more understandable if they were to implement the methods themselves. So I'll change my talk to look at fmt.PrintLn instead and have them print their struct with and without a String method. Thanks for the help. |
I am not sure of a better way to provide this feedback to Brett.
(c Complex) ToString()
a line is too long to fit on the screen.My slides refer to some types I've defined in my talk, but since your talk comes right after mine, I think people will remember well enough that it could work.
You could also use one of the exercises that I've now dropped: Write a stringer for the struct that was created for the exercises in talk 9. (This assumes that @torbiak adds an exercise to get the students to write a struct.)
The text was updated successfully, but these errors were encountered: