-
Notifications
You must be signed in to change notification settings - Fork 164
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #625 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 209 210 +1
Lines 3952 3969 +17
=====================================
+ Hits 3952 3969 +17
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #625 +/- ##
======================================
Coverage 100% 100%
======================================
Files 239 235 -4
Lines 4757 4637 -120
======================================
- Hits 4757 4637 -120 Continue to review full report at Codecov.
|
There was a problem hiding this 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
01_fib/jimbotech/.gitignore
Outdated
@@ -0,0 +1,2 @@ | |||
/.vscode/* |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Also please open an 'issue' and put the issue number inside |
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. |
There was a problem hiding this 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!
01_fib/jimbotech/ex_fibonacci.go
Outdated
|
||
if n < 0 { | ||
for i := 0; i > n; i-- { | ||
factor := int(math.Pow(-1, float64(i*-1))) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
01_fib/jimbotech/ex_fibonacci.go
Outdated
factor := int(math.Pow(-1, float64(i*-1))) | ||
fmt.Fprintln(out, f()*factor) | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
01_fib/jimbotech/ex_fib_test.go
Outdated
|
||
for _, val := range fibResults { | ||
if r := f(); r != val { | ||
t.Errorf("Returned value %v does not match %v", r, val) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
01_fib/jimbotech/README.md
Outdated
@@ -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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* 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
d5fddee
to
9cf1af7
Compare
Modified version of the Excersise: Fibonacci closure from the Tour of Go It already contains some review comments from a previous attempt
* 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
There was a problem hiding this 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.
There was a problem hiding this 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.
Fixes #630
Review of colleague's PR #514
Changes proposed in this PR:
Submit lab1 Fibonacci from the go course
-