-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ex 1.4 solution #22
Comments
Like you, I also tried to do the exercises without using concepts and libraries that hadn't been introduced yet, since that seems to be the intent of the exercises in a lot of books, but I decided not to be a purist about it once I realized doing so would make many of my solutions awkward or less idiomatic. It's been a while since I went through the book but I feel like a lot of the exercises in GOPL were intended to make you research and think about different solutions instead of merely applying the material that was just learned. Also, on page 12, a couple paragraphs before Exercise 1.4 is given, it says:
which seems like a nudge towards reading ahead and using string and slice related functions that haven't been introduced yet. Also, in the preface they say they assume the reader has programmed before and that they won't "spell everything out as if for a total beginner", which I think gives them some latitude in specifying less guided exercises. What was your solution? If I wanted to avoid using |
When I spoke to a colleague who is also going through the book, he indicated that he thought that the intent of the author is to have the reader solve the problems with the concepts already given and not to "look ahead", so I'm not sure. Maybe it is mentioned in the "how to use this book" section. How I ended up solving it is to only use maps because, although slices were introduced, the author indicated that it was to be covered in detail later. So I created a structure like this: map[string]map[string]int Where I track the number of occurrences of a line per file, then for filename, counts := range names {
if counts[line] > 0 {
fmt.Printf("\t%s\n", filename)
}
} My thinking was "well they want us to use maps, but I don't think they want us to use slices yet", but then, as you say, I walk away from my solution feeling awkward. |
So I just started reading the book and got to Exercise 1.4. I thought I knew a few "obvious" solutions to the problem, but all of them involved logic or data structures that were not yet prior to the exercise, so I thought that those solutions were "cheating". Finally I came up with a solution that I think only uses things that were taught so far in the chapter, but it was kinda hacky. Finally I decided to Google the solution and found this repo. The solution in this repo, however, used concepts that are not yet introduced (e.g.
in
,append
, etc.) so I wonder whether or not that's valid.This isn't really a bug report, just something to discuss.
The text was updated successfully, but these errors were encountered: