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

Lab1 - Generate Fibonacci Series #625

Merged
merged 14 commits into from
Sep 24, 2019
Merged

Lab1 - Generate Fibonacci Series #625

merged 14 commits into from
Sep 24, 2019

Conversation

jimbosoft
Copy link
Collaborator

@jimbosoft jimbosoft commented Sep 3, 2019

Fixes #630

Review of colleague's PR #514

Changes proposed in this PR:

Submit lab1 Fibonacci from the go course

-

@codecov
Copy link

codecov bot commented Sep 3, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #625   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         209    210    +1     
  Lines        3952   3969   +17     
=====================================
+ Hits         3952   3969   +17
Impacted Files Coverage Δ
01_fib/jimbotech/ex-fibonacci.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 fa5b659...56f27df. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 3, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #625    +/-   ##
======================================
  Coverage     100%   100%            
======================================
  Files         239    235     -4     
  Lines        4757   4637   -120     
======================================
- Hits         4757   4637   -120
Impacted Files Coverage Δ
01_fib/jimbotech/ex_fibonacci.go 100% <100%> (ø)
10_rest/kasunfdo/pkg/puppy/store/mapstore.go
10_rest/kasunfdo/pkg/puppy/store/syncstore.go
10_rest/kasunfdo/pkg/puppy/error.go
10_rest/kasunfdo/pkg/puppy/puppy.go
10_rest/kasunfdo/pkg/puppy/rest.go

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 32d6a28...dbf2201. Read the comment docs.

Copy link
Collaborator

@willshen8 willshen8 left a comment

Choose a reason for hiding this comment

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

Apart from the comments below, I think the filename needs to be snakecase to align with convention:
https://stackoverflow.com/questions/35694137/file-name-convention-for-compound-words

@@ -0,0 +1,2 @@
/.vscode/*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Only source files should be committed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I usually check in the .gitignore and others also consider it normal practise as per https://stackoverflow.com/questions/5765645/should-you-commit-gitignore-into-the-git-repos, however in this context it might not add a lot, so I removed it.

01_fib/jimbotech/README.md Outdated Show resolved Hide resolved
01_fib/jimbotech/ex-fib_test.go Outdated Show resolved Hide resolved
01_fib/jimbotech/ex-fibonacci.go Outdated Show resolved Hide resolved
01_fib/jimbotech/ex-fibonacci.go Outdated Show resolved Hide resolved
01_fib/jimbotech/ex-fibonacci.go Outdated Show resolved Hide resolved
@willshen8
Copy link
Collaborator

Also please open an 'issue' and put the issue number inside Fixes # of the PR description. The go-course require commit messages to be squashed, so you might have to do an interactive rebase.

@willshen8
Copy link
Collaborator

I moved the issue number up in the PR description (into the first line), I think maybe I wasn't clear. Hope you see it now.

@willshen8 willshen8 self-requested a review September 4, 2019 10:12
willshen8
willshen8 previously approved these changes Sep 4, 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.

The file name ex_fib_test.go should be called ex_fibonacci_test.go - i.e. the same as the name as the file being tested but with _test appended before the extension. This is not something that is explicitly documented but is a convention I've never seen not followed.

My general approach to these reviews is to classify my comments into two types: Go-specific ones that need to be addressed to merge, and general software engineering practice ones which are advisory.

In this review, just the comments about error strings are Go-specific. So please at least fix those up (all instances - I did not leave a comment on every one, so look at all your error strings) before submitting for re-review. It is up to you as to whether you want to address the other comments, but it is good practice to at least respond to all comments with an acknowledgement or reason for ignoring.

Finally, a couple of comments on your commits and commit messages. Have a read of https://chris.beams.io/posts/git-commit/ (also linked from the slides) on what makes a good commit message. In particular, your first commit titled "INITIAL COMMIT" does not have a good title. It is shouty and non-descriptive. The initial split into five commits is fine and well done, but it does mean you need to take more action with your subsequent fixup commits - the should be squashed with the commits where the original code being fixed was written. We do not want to see fixup commits merged into master - the place to get your code and commits into order is the pull request. When merging it should look as though a series of commits was written "perfectly" the first time. If you started with one commit and intended to only keep one commit, you could do a "squash merge" when merging the PR to remove all evidence of the fix-ups. But if you want to retain your original split, you'll need to manually apply the fix-ups with git rebase. Remember, history is written by the victors. Be a victor!


if n < 0 {
for i := 0; i > n; i-- {
factor := int(math.Pow(-1, float64(i*-1)))
Copy link
Contributor

Choose a reason for hiding this comment

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

The computation of negative fibonacci numbers really belongs where the sequence is calculated. This function is responsible for printing n fib numbers. Instead you've split the computation over two separate functions for negative numbers. For instance, if you wanted to have another function return a slice of fib numbers instead of printing them, you would have to duplicate this negative number handling. But you've kind of backed yourself into a corner with your closure implementation of fib - it has no notion of which direction to go in so it cannot compute negative numbers.

Also the computation of -1 or 1 here is a bit obtuse. i*-1 is more simply expressed as -i and using floating point calculations just to alternate between -1 and 1 seems unnecessary. If it were possible to write it as -1^-i in simple mathematical notation, then it may be worth doing. But with the casts and math.Pow instead of ^ or similar, it becomes that much harder to mentally parse and understand. An alternative is to use a variable sign initialised to 1, and each time around the loop you just do sign *= -1 - that way it alternates but is a much simpler expression.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done ... however I feel hardly done by. I feel I am handling the negative numbers in the right place as the series is being generated there. So now I have separated the generation from the printing. Am I going to be criticised for inefficiency now? I was hoping for bonus points not bonus corrections. Secondly, as this is a exerciser I felt proud of my play with the math library and expected applause. Yes I did not like floating point either. When I re-wrote it I needed ABS, guess what, floating point again. So can I use any of the math library?

factor := int(math.Pow(-1, float64(i*-1)))
fmt.Fprintln(out, f()*factor)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: stray blank line. unnecessarily spaces out the code, which matters on real code that does not fit on one screen. blank lines to separate "paragraphs" of code are good, but do think about what your "code paragraphs" are.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done


for _, val := range fibResults {
if r := f(); r != val {
t.Errorf("Returned value %v does not match %v", r, val)
Copy link
Contributor

Choose a reason for hiding this comment

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

error messages in Go should start with lower case letters. This is because error messages are often wrapped as the propagate causing a SeQuEnCe of lower/upper case letters: https://github.com/golang/go/wiki/CodeReviewComments#error-strings

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,15 @@
# Fibonacci Number Generator
## Overview
As part of the ANZ "go" course the first lab is to produce a piece of software that will produce the Fibonacci series for fib(7). It was also an exercise in the tour.golang.org.
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Markdown is an extension of plain old ascii documents, in that ascii markup is added so it can be prettier when rendered as markdown. But the files should still be readable as ascii documents. This means wrapping text around 80 chars (the general convention), as people use all sorts of different width terminals, and some that require side scrolling to read wider text. So please make markdown text readable as plain ascii as originally intended.

Plenty has been written about line length / text width - here's one example: https://baymard.com/blog/line-length-readability

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

harirakr and others added 2 commits September 9, 2019 12:52
* Implement lab9 requirements

Implement ability to convert between Go in memory objects to JSON
representation and vice versa.

Implement ability to accept user input from CLI and read data from
a file.

Load data from json text file and store in an instance of storer.

* Add tests to main_test.go

* Update README file to reflect changes in lab9

* Fix pesky scopelint error

* Fix pesky test coverage issue

Create new test with totally invalid json

* Fix final lint problem

Lint issue: should merge variable declaration with assignment on next line

* Add 2 json files to read into program

* Fix PR feedback

1) add defer f.close() to close file
2) use kingpin.ExistingFile no kingpin.String
3) tried using kingpin.fatalusage() to replace my printusage() func
   but struggled to hit it for test coverage
4) Remove ./ at start of paths
5) separate flag parsing and loading a file
Jim hejtmanek added 4 commits September 9, 2019 13:41
Modified version of the Excersise: Fibonacci closure from the Tour of Go
It already contains some review comments from a previous attempt
Jim hejtmanek added 3 commits September 9, 2019 16:24
* Removed unwanted blank lines
* Separated the printing of the series from the generation
* Removed math function that use floating point
* Renamed the file to go convention
* Made sure that error messages start with a lower case letter
This was referenced Sep 15, 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.

There is something very wrong with this PR. It has 29 files changed in it with code from other people's lab. I suggest you checkout the latest master and rebase on that, then force push. That should clean it up, but I am not sure how you got here so cannot offer precise guidance of how to get out.

I cannot re-review until this is fixed.

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.

BTW, if you wanted to incorporate negative fibonacci numbers into your closure way of generating numbers:

func fibonacci(direction int) func() int {
	if direction < 0 {
		direction = -1
	} else {
		direction = 1
	}
	secondLast, last := 0, 1

	return func() int {
		result := last
		secondLast, last = last, secondLast+(last*direction)
		return result
	}
}

Then you could just call f := fibonacci(n) and iterate over the result of f() which would remove the need for the intermediate slice. Or slightly more verbose but taking care of the iteration properly:

f := fibonacci(n)
limit := n
if n < 0 {
     limit = -n
}
for i := 0; i < limit; i++ {
    fmt.Fprintln(out, f())
}

I'm not requesting this change, just pointing out what I had in mind with my previous comments.

@jimbosoft jimbosoft merged commit 3411b10 into anz-bank:master Sep 24, 2019
@jimbosoft jimbosoft deleted the lab1 branch September 24, 2019 05:03
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.

Lab1 - Fib
5 participants