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 mentoring notes for go/pig-latin #2311

Merged
merged 3 commits into from
Jan 19, 2024
Merged

Conversation

bernot-dev
Copy link
Contributor

Add some mentoring notes for the Pig Latin exercise.

@github-actions github-actions bot added track/go Go track type/mentor-notes Mentor notes labels Jan 10, 2024
Copy link

@thekaranchauhan thekaranchauhan left a comment

Choose a reason for hiding this comment

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

This solution best practices, featuring clear and decoupled logic. It also effectively handles various cases, such as 'qu' combinations and leading 'y.'

@@ -0,0 +1,72 @@
# Pig Latin

### Reasonable solutions:
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be ## and not ### based on a spot check of other notes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the other notes in the Go track seem to disagree with the README for the repo, which suggests ### for headings. I wasn't sure which to follow.

func Sentence(sentence string) string {
words := strings.Fields(sentence)
pigWords := make([]string, 0, len(words))
for _, w := range words {
Copy link
Member

Choose a reason for hiding this comment

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

Are single-letter variables idiomatic Go code?

Choose a reason for hiding this comment

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

What my seniors says is, it is idiomatic for short lived variables and loops (in small snippets as well). However, for variables with broader scopes and long lifetimes, descriptive names are appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The greater the distance between a name's declaration and its uses, the longer the name should be. In this case, it is scoped to just a couple lines, so I consider this idiomatic.

tracks/go/exercises/pig-latin/mentoring.md Outdated Show resolved Hide resolved
if strings.HasPrefix(word, "xr") || strings.HasPrefix(word, "yt") {
return 0
}
for i, r := range word {
Copy link
Member

Choose a reason for hiding this comment

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

More readable var names might be good here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i is a well-accepted name for an index variable.

r is short for rune, and rune is a keyword. I'm open to suggestions here, but I wouldn't question this in code review, myself.

}
```

It is possible to combine parts 2 and 3, but this often leads to less readable code that repeats parts of the logic to form the pig latin word.
Copy link
Member

Choose a reason for hiding this comment

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

"often" sounds subjective. Why not leave it up to the mentors to notice if the code is readable or not and to call out repeated code?

Suggested change
It is possible to combine parts 2 and 3, but this often leads to less readable code that repeats parts of the logic to form the pig latin word.
It is possible to combine parts 2 and 3, though sometimes doing so is hard.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's ok to leave subjective suggestions for mentors in these notes. But maybe it needs a little more explanation about why the code is less readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the community solutions I saw that count consonants inline end up with more deeply logic and many returns at various levels of organization. It's not wrong and there may be marginal performance benefits, but it does reduce Clarity, which is the most important style goal of code, according to Google's Style Guide.

tracks/go/exercises/pig-latin/mentoring.md Outdated Show resolved Hide resolved
### Common suggestions:
* Avoid complex, deeply nested logic.
* Are all of the conditions treated as special cases in code actually special cases? For instance, does a leading vowel need to be treated differently than a first vowel in the middle of the word?
* Prefer switch/case to long if/else chains.
Copy link
Member

Choose a reason for hiding this comment

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

Is this personal preference or idiomatic Go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is normative, and has associated linter rules. For instance:

Comment on lines +66 to +67
* Add explanatory comments when the intent of the code might not be clear to the reader.
* `gofmt` ensures consistent formatting, and is standard across most of the Go community.
Copy link
Member

Choose a reason for hiding this comment

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

These two are general comments and not specific to this exercise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The note about adding comments is more likely to come up in this exercise than many others, because the logic is actually somewhat complex here.

Formatting is general, but comes up frequently for me. There are similar notes on other exercises on this track. I'm not sure what the right call is here.

### Talking points
* `rune` vs `byte` and why iterating over a string with `range` returns runes: [Strings, bytes, runes and characters in Go](https://blog.golang.org/strings)
* The test cases do not include uppercase letters. How would the student's solution have to change to handle uppercase letters?
* `fmt.Sprintf` and `strings.Builder` are more common than using the `+` operator to concatenate strings.
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
* `fmt.Sprintf` and `strings.Builder` are more common than using the `+` operator to concatenate strings.
* `strings.Builder` is the preferred tool for building large strings. `fmt.Sprint` can be useful in place of string concatenation for shorter strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not too familiar with using suggested changes in GitHub, but can you modify the suggest to clarify "in place of string concatenation with the + operator"?

I feel like that's ambiguous, otherwise.


### Reasonable solutions:

There is a (somewhat) reasonable solution using regular expressions, however most students are likely to use a combination of `strings` funtions or string slicing to solve this problem.
Copy link
Member

Choose a reason for hiding this comment

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

This section has a bunch of components but not a complete solution. You may want to present a complete solution here. If you want to explain it, you can use functions and comments and delve into details in following sections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The three parts/functions together form a complete solution. I can try to reorganize if you think that would help it flow better.

@iHiD
Copy link
Member

iHiD commented Jan 18, 2024

@bernot-dev Thank you for this! :)

@IsaacG IsaacG merged commit 58d4c59 into exercism:main Jan 19, 2024
1 check passed
@bernot-dev bernot-dev deleted the go-pig-latin branch January 19, 2024 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
track/go Go track type/mentor-notes Mentor notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants