-
Notifications
You must be signed in to change notification settings - Fork 21
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
Assignment clever-challenge. #8
base: master
Are you sure you want to change the base?
Conversation
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 did not see any code detecting function calls or maybe I have misunderstood some part of the code, could you confirm if this is missing?
Also, please be consistent with indentation, either choose tabs or spaces, but keep to it.
main.go
Outdated
} | ||
res := result{} | ||
for _, f := range files { | ||
file_path := path.Join(diff_dir_path, f.Name()) |
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.
Watch out with the path
package as it is not intended for file system path manipulation, filepath
is more suited for this
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.
Noted.
main.go
Outdated
task_list := []string{"DIFF", "REGION", "UPDATE"} | ||
for scanner.Scan() { | ||
if scanner.Text() != "" { | ||
if len(scanner.Text()) > 0 { |
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 speak for myself, and possibly others will agree that this can be &
ed for more linear code, this'll help 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.
Yes I agree.
main.go
Outdated
if len(scanner.Text()) > 0 { | ||
for _, task := range task_list { | ||
success, on_success := execute_task(&task, scanner.Text(), res) | ||
if success && len(on_success) == 0 { |
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 think this can be simplified by the negative; i.e. if !success { continue }
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.
Yes it works
main.go
Outdated
if success && len(on_success) == 0 { | ||
continue | ||
} else if success { | ||
task_list = on_success |
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 think I understand what you are doing, is it some state machine?
It may require a bit of commenting since it was rather confusing for me at first.
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.
Yes it is kind of a state machine where I have mainly tree states, the states determine which pattern to search in priority, like a very simple waterfall where we test the most complex and intricated task when no other task succeded, the tasks being finding clue about state transition, states 'being in a diff headline' (DIFF), 'in a region headline' (REGION) 'in diff content' (UPDATE). When we are in state UPDATE, we have to check all states with priority DIFF then REGION then UPDATE and FUNCTION CALL.
main.go
Outdated
|
||
func execute_task(task *string, line string, res *result) (bool, []string) { | ||
success := false | ||
on_success := make([]string, 0) |
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.
That's a small detail, but this should be declared as nil
first
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
} | ||
} | ||
} | ||
} |
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.
Adding a fallback for missing future cases may be worth it
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
main.go
Outdated
func execute_task(task *string, line string, res *result) (bool, []string) { | ||
success := false | ||
on_success := make([]string, 0) | ||
if *task == "DIFF" { |
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.
If you're going towards a state-machine approach, I'd suggest using enums for that kind of manipulation, it'll be way lighter than strings for states.
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.
Thank you, I just found out how to write enums.
main.go
Outdated
// Extract $file_path_a and $file_path_b if line = 'diff --git a/$file_path_a b/$file_path_b' | ||
func is_new_diff(line *string, res *result) bool { | ||
new_diff := false | ||
if line != nil { |
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.
This is personal preference (and is something advocated by several open-source projects), but I think you should linearize your code for easier understanding of what's happening.
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.
Alright, I see that I refined a lot of conditions and indeed there refacto to do.
main.go
Outdated
new_diff := false | ||
if line != nil { | ||
if len(*line) > 10 { | ||
if (*line)[:11] == "diff --git " { |
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.
Both those lines could be replaced by a strings.HasPrefix
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.
It increased a bit performances.
I am currently working on a new version where I read the file character by character and try to apply a combination of expectation maximization on Hidden Markov Models to learn the statistics of an HMM which state would be Thank you for this, and thank you Lucas for your comments, I learned from them and am working on it. Best regards |
No description provided.