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 lab 4 - Numeronym #640

Merged
merged 3 commits into from
Nov 9, 2019
Merged

Add lab 4 - Numeronym #640

merged 3 commits into from
Nov 9, 2019

Conversation

alextmz
Copy link
Collaborator

@alextmz alextmz commented Sep 9, 2019

Fixes #639

Review of colleague's PR #461

Changes proposed in this PR:

  • Add lab 4 - numeronym and tests

@codecov
Copy link

codecov bot commented Sep 9, 2019

Codecov Report

Merging #640 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #640   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         280    281    +1     
  Lines        5754   5768   +14     
=====================================
+ Hits         5754   5768   +14
Impacted Files Coverage Δ
04_numeronym/alextmz/main.go 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 975d12b...a16818c. Read the comment docs.

n0npax
n0npax previously approved these changes Sep 11, 2019
Copy link
Contributor

@camscale camscale left a comment

Choose a reason for hiding this comment

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

Sorry I didn't get to this earlier, Alex. Please make sure you mark your PRs as "ready for review" if they still need a review. I do sometimes remember to look at [-label:"ready for review" label:"approved by colleague"] which is when I saw this one.

A couple of things to fix up here, but otherwise a good compact solution. You have made the classic mistake with this lab, which is good because you'll remember from now how exactly strings work WRT runes and bytes.

04_numeronym/alextmz/main.go Outdated Show resolved Hide resolved
04_numeronym/alextmz/main.go Outdated Show resolved Hide resolved
04_numeronym/alextmz/main.go Outdated Show resolved Hide resolved
04_numeronym/alextmz/main_test.go Outdated Show resolved Hide resolved
04_numeronym/alextmz/main_test.go Show resolved Hide resolved
04_numeronym/alextmz/main_test.go Show resolved Hide resolved
@camscale
Copy link
Contributor

Oh, also please fill out the issue you've linked to this PR. Have a read of https://github.com/anz-bank/go-course/wiki/Software-Engineering-with-Go for why we want this extra stuff.

04_numeronym/alextmz/main.go Show resolved Hide resolved
04_numeronym/alextmz/main.go Show resolved Hide resolved
04_numeronym/alextmz/main.go Outdated Show resolved Hide resolved
@alextmz
Copy link
Collaborator Author

alextmz commented Oct 6, 2019

Changes requested implemented. Golang-CI is acting weird.

juliaogris
juliaogris previously approved these changes Oct 16, 2019
Copy link
Contributor

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@camscale camscale left a comment

Choose a reason for hiding this comment

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

There is a bug in here which suggests some more test cases are needed.

04_numeronym/alextmz/main_test.go Show resolved Hide resolved
}

func numeronym(s string) string {
if len(s) < 4 {
Copy link
Contributor

Choose a reason for hiding this comment

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

This exhibits a similar problem mentioned in my earlier review, and is not doing what you think it's doing. See my comment on the test cases for some examples of where this will fail.

As described in https://blog.golang.org/strings, a string is effectively a read-only slice of bytes, not runes, so the length of a string is not the number of runes, but the number of bytes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I corrected this - the len usage was quite naive and the source of the issue.

}

func numeronym(s string) string {
if utf8.RuneCountInString(s) < 4 {

Choose a reason for hiding this comment

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

RuneCountInString not declared by package utf8 (from typecheck)

camscale
camscale previously approved these changes Nov 5, 2019
Copy link
Contributor

@camscale camscale left a comment

Choose a reason for hiding this comment

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

This looks like it works now.

I see you are using both RuneCountInString and RuneCount. This will possibly cause confusion as it is an unnecessary distinction. When I see something like that, I wonder "why?" and when there's no reason, it just makes it harder to understand.

Also, there's no need to call it twice. If you move the numrunes := ... to the top of the function, you can have your test be if numrunes < 4.

But this is general software engineering practices and not related directly to Go, so I'll approve this.

Thanks for your perseverance.

@alextmz
Copy link
Collaborator Author

alextmz commented Nov 7, 2019

Added the suggested changes... yes it looked too ugly the way it was, I should had paid more attention and not only done a quick-fix. Hey it's a software engineering course in Go, not programming in Go ;-)

Copy link
Contributor

@camscale camscale left a comment

Choose a reason for hiding this comment

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

LGTM

@alextmz alextmz merged commit 4e286f8 into anz-bank:master Nov 9, 2019
@alextmz alextmz deleted the lab4 branch November 9, 2019 11:24
jimbosoft pushed a commit to jimbosoft/go-course that referenced this pull request Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lab 4 - Numeronym
5 participants