Skip to content
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

Add channels concept #2324

Closed
wants to merge 1 commit into from
Closed

Add channels concept #2324

wants to merge 1 commit into from

Conversation

RezaSi
Copy link

@RezaSi RezaSi commented Jul 14, 2022

for this #2182

@github-actions
Copy link
Contributor

Dear RezaSi

Thank you for contributing to the Go track on Exercism! 💙
You will see some automated feedback below 🤖. It would be great if you can make sure your PR covers those points. This will save your reviewer some time and your change can be merged quicker.

  • 📜 The following files usually contain very similar content.

    • concepts/<concept>/about.md
    • concepts/<concept>/introduction.md
    • exercises/concept/<exercise>/.docs/introduction.md

    Please check whether the changes you made to one of these also need to be applied to the others.

  • 🧦 If you changed the function signature or the function comment in the exemplar file or the stub file (<exercise>.go), make sure the change is applied to both files.

  • 🔗 If your PR fully fixes an issue, please include the text Fixes #issue_no in any line of the PR description. This will make the issue be automatically be closed when the PR is merged. If your PR is related to an existing issue but does not fix it completely, please link the issue anywhere in the description of the PR with #issue_no. You can read more about this in Github: Linking a pull request to an issue

  • ✍️ If your PR is not related to an existing issue (and is not self-explaining like a typo fix), please make sure the description explains why the change you made is necessary.

  • 🔤 If your PR fixes an easy to identify typo, if would be great if you could check for that typo in the whole repo. For example, if you found Unicdoe, use "replace all" in your editor (or command line magic) to fix it consistently.

Dear Reviewer/Maintainer

  • 📏 Make sure you set the appropriate x:size label for the PR. (This also works after merging, in case you forgot about it.)

  • 🔍 Don't be too nit-picky. If the PR is a clear improvement compared to the status quo, it should be approved as clear signal this is good to be merged even if the minor comments you might have are not addressed by the contributor. Further improvement ideas can be captured in issues (if important enough) and implemented via additional PRs.

  • 🤔 After reviewing the diff in the "Files changed" section, take a moment to think about whether there are changes missing from the diff. Does something need to be adjusted in other places so the code or content stays consistent?

Automated comment created by PR Commenter 🤖.

Copy link
Member

@junedev junedev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content you present here seems to be copied from https://www.golangbootcamp.com/book/concurrency. The book does not have any license file so we cannot know if the author allows copying without attribution. GoBootcamp/book#48 This is too risky for us.

The content needs to written in your own words, copied from places that explicitly allow copying without attribution (e.g. via an MIT license) or the sentences that are copied need to be quoted and the source needs to be added as a footnote (this is legally only allowed for short sections if not explicitly permitted otherwise).

I only looked at the first part so far. I don't know for how much of the total content this applies to. It's easier for you to know. In any case, please rework all the copied content so it follows the rules above. If you have any questions, let me know.

@junedev
Copy link
Member

junedev commented Jul 16, 2022

Did you invent the exercise from scratch? If yes, I could start reviewing that part.

@RezaSi
Copy link
Author

RezaSi commented Jul 16, 2022

The content you present here seems to be copied from https://www.golangbootcamp.com/book/concurrency. The book does not have any license file so we cannot know if the author allows copying without attribution. GoBootcamp/book#48 This is too risky for us.

The content needs to written in your own words, copied from places that explicitly allow copying without attribution (e.g. via an MIT license) or the sentences that are copied need to be quoted and the source needs to be added as a footnote (this is legally only allowed for short sections if not explicitly permitted otherwise).

I only looked at the first part so far. I don't know for how much of the total content this applies to. It's easier for you to know. In any case, please rework all the copied content so it follows the rules above. If you have any questions, let me know.

Yes, some part of the intro and about is copied from this site and golang tut, I don't know this, but it's ok, I will try to write it again with my words!

@RezaSi
Copy link
Author

RezaSi commented Jul 16, 2022

Did you invent the exercise from scratch? If yes, I could start reviewing that part.

Yes, it's not copied from somewhere or another exercise, tnx for the review.

Copy link
Member

@junedev junedev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at the about.md file. I will check out the exercise later on.

{
"blurb": "Channels are the pipes that connect concurrent goroutines.",
"authors": ["RezaSi"],
"contributors": ["RezaSi"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only need to add yourself as author. A contributor is someone who makes small adjustments later on (or the reviewer if you think they had substantial impact on the result).

@@ -0,0 +1,115 @@
# About
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please ensure some general points are taken care of throughout the content:

@@ -0,0 +1,115 @@
# About

As you know, goroutines are a way to execute concurrent code in golang.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Remove "as you know". It might be a long time since the student did that exercise and they might have forgotten.
  • On the word "goroutines" add a link to some document that explains goroutines. This helps students that forgot about them and it helps everyone as long as we don't have the goroutines concept on Exercism yet. Potential link: https://go.dev/tour/concurrency/1

value := <-ch // Receive from ch, and assign value to value variable.
```

Create a new channel with make(chan val-type). Channels are typed by the values they convey.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to first show how to create a channel and then how to send/receive data. That makes it easier to understand the comments you have above.

concepts/channels/about.md Show resolved Hide resolved
channel := make(chan bool)
go exist(slice[:len(slice)/2], lookForValue, channel)
go exist(slice[len(slice)/2:], lookForValue, channel)
x, y := <-channel, <-channel // receive from channel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x, y := <-channel, <-channel // receive from channel
x, y := <-channel, <-channel // receive 2 values from channel

slice := []int{1, 7, 8, -9, 12, -1, 13, -7}
lookForValue := 8

channel := make(chan bool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

results or resultCh might be a better name here

### Notes:
- Only the sender should close a channel, never the receiver. Sending on a closed channel will cause a panic.

- Channels aren't like files; you don't usually need to close them. Closing is only necessary when the receiver must be told there are no more values coming, such as to terminate a range loop.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a quote from Tour of Go and should be marked as such. You can quote with ">" in markdown and you can use a footnote to state the source. Their license only allows to use the material if you set the same license for the derived content which we don't have at the moment.

As discussed before, this applies to all the content in the PR. Please either write things yourself or quote with source. I am sorry but if your don't stick to those legal rules, I will be forced to reject the PR.

The rules also apply to code examples btw.

@RezaSi
Copy link
Author

RezaSi commented Jul 21, 2022

@junedev Tnx for all your advice, I think resolved all, and repair some other parts.
Yes, I'm not a native speaker, if you can help with grammar, it's very welcome.

@RezaSi RezaSi requested a review from junedev July 21, 2022 09:09
@RezaSi RezaSi force-pushed the channels branch 6 times, most recently from 03a8465 to 4649624 Compare July 22, 2022 08:39
@RezaSi
Copy link
Author

RezaSi commented Aug 7, 2022

@junedev Any update?

@junedev
Copy link
Member

junedev commented Aug 12, 2022

@RezaSi Sorry for the wait. I had to discuss with the Exercism leadership how to proceed with this PR. The problem is that the concept content still contains some sentences that are copied without attribution and some others were there were only slight changes made to the original content. This happened after I mentioned the issue twice already. It is too risky for us to merge content like this and it takes too much time for me to check and discuss every sentence. I will still consider the exercise part (without introduction.md) for merging but before I merge, I will remove the concept content from the PR and set the exercise status to "work in progress". Then there will be a follow up issue about writing the concept from scratch and once someone else worked on this, the exercise can go live.

Hopefully, I can find some time to review the exercise on the weekend but I can't promise. I'm sorry this all takes so long but keep in mind that all track maintainers on Exercism are volunteers that do this work in their free time.

Copy link
Member

@junedev junedev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned before, I reviewed the exercise. I like the general idea about fetching data concurrently. I did not review the test file yet as it might change as you make some other adjustments. I will take a closer look once the other comments are addressed.

"for-loops",
"range-iteration"
],
"status": "beta"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, please change the status to "wip" for now.

@@ -0,0 +1,33 @@
# Instructions

In this exercise you'll be writing code to handle multilayer cache with Go channels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say "multilayer cache", I imagine something like what is usually called "multi-level cache" which would mean you would check different cache levels in a fixed order and the deeper in the level you go the longer it takes to retrieve the data. The issue is that in such a scenario, you would always make the request sequentially and only proceed to the next level/layer when no result was returned. The word "layer" puts emphasis on this, layers are usually passed/pealed one by one. It might be less confusing to only say there are multiple caches available or talk about a cluster of caches (although the later also has its existing meaning which is different from the what you want to do in the exercise).

In any case, add one or two more sentences explaining what you mean by whatever term you decide to use to avoid misunderstandings.

Comment on lines +7 to +10
type Cache struct {
ResponseTime time.Duration
Data map[string]string
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why this is presented in the instructions. It feels like this an implementation detail of the tests and it would be enough if the instructions would only state what the cache interface looks like (has a Get and Set method). Then the tests can provide whatever implementation for that interface. The internals of the cache should not matter for solving the exercise. You only need to say something like "some caches are faster to respond than others".

Showing this cache structs might make the student think they can solve the exercise by simply checking the value of "ResponseTime".



```go
GetValueFromFastestLayer(cacheLayers []Cache, key string) (string, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here should not present the function signature, instead if should show an example of how the function is called/used (and a potential result). You don't have to include the definition of the cache structs in here though.

Same for the other code block below.


## 2. Set value to all layers
The key and value are given to you as `key` and `value` parameters.
You have to set the value to all `cacheLayers` as fast as possible, you have maximum `max(cacheLayers.ResponseTime)` to set the value to all layers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling with this sentence as using the channels will have some overhead so you won't exactly hit the max response time. Maybe you can rephrase it a bit to say something like "Try to get as close as possible to the response time of the slowest cache."

ch := make(chan string, len(cacheLayers))
for _, cache := range cacheLayers {
go func(cache Cache) {
value, _ := cache.Get(key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Get function should either not have an error return value or the error should be checked an if it is not nil, no value or an empty string should be send over the channel. It is good practice not to trust the result value in case the error is not nil.

Comment on lines +22 to +36
func SetValueToAllLayers(cacheLayers []Cache, key string, value string) error {
ch := make(chan error, len(cacheLayers))
for _, cache := range cacheLayers {
go func(cache Cache) {
err := cache.Set(key, value)
ch <- err
}(cache)
}

for range cacheLayers {
<-ch
}

return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of thoughts about this task (and the solution):

  • Currently, the function always returns nil so it could also just not have a return value at all.
  • The instructions should clarify what happens in case Set returns an error.
  • Overall, the required solution here is very similar to the one of the first task. Usually we try to bring up some new aspect in each task. Have another look at the learning objectives, maybe the task can be adjusted/re-written to cover something different. For example, currently your tasks don't cover ranging over a channel at all.

@@ -0,0 +1,9 @@
package cache

func GetValueFromFastestLayer(cacheLayers []Cache, key string) (value string, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the names from the return values. Those should only be used when really needed as they can lead to mistakes easily.

@@ -0,0 +1,31 @@
package cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you follow the suggestion mentioned above with the interface, the cache implementation can be part of the standard test file. If you want to keep it as a separate file, you can list it in the config under the "editor" key so it shows up when solving the exercise but cannot be edited on the website.

@@ -0,0 +1,31 @@
package cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of "cache_struct.go", "types.go" is a more common name for a file like this.

@junedev junedev added the status/awaiting-contributor This pull request is waiting on the contributor. label Aug 17, 2022
@junedev junedev linked an issue Aug 17, 2022 that may be closed by this pull request
@github-actions
Copy link
Contributor

Hello contributor and thank you for your contribution!
This pull request has been automatically marked as stale because it has not had recent activity. Please update the PR when you are able.
If this pull request is waiting on the maintainer, please apply the status/awaiting-maintainer label (and remove the status/awaiting-contributor label).
If no action is taken in the next week, this pull request will be automatically closed.

@junedev
Copy link
Member

junedev commented Oct 1, 2022

Closing this as it seems abandoned.

@junedev junedev closed this Oct 1, 2022
@junedev junedev added the abandoned The creator of this issue or PR does not respond anymore. label Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abandoned The creator of this issue or PR does not respond anymore. status/awaiting-contributor This pull request is waiting on the contributor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement New Concept Exercise: Channels and Select
2 participants