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

refactor: encapsulation #3017

Closed
wants to merge 40 commits into from
Closed

refactor: encapsulation #3017

wants to merge 40 commits into from

Conversation

lkwg82
Copy link
Contributor

@lkwg82 lkwg82 commented Apr 26, 2016

Purpose

Refactoring hints from PR #3007

Testing

compile and run tests

@@ -51,3 +51,7 @@ func (f *folder) scanSubdirsIfHealthy(subDirs []string) error {
}
return nil
}

func (f *folder) scanner() *folderScanner {
return &f.scan
Copy link
Member

Choose a reason for hiding this comment

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

So I think this is worse.
I think what @calmh ment by encapsulation was doing

func (f *folder) Scan() {
   f.scan.Scan()
}

but I might be wrong.

Also, why just not embed scan into folder?

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 dont think this is worse. It is meant to be a fluent api implementing a getter for the folderScanner. The only thing is that I made a mistake using the wrong idioms because I'm not familiar with golang yet.

If I had used your suggestions ...

  • it would be confusing with the func (f *folder) Scan(subdirs []string) error
  • and the problem with accessing fields directly would not be solved.

I understood @calmh 's hint, to implement to OOP style. With which I fully agree on. This means using methods to access fields to not undermine any future refactoring and to keep stable contracts.

Copy link
Member

Choose a reason for hiding this comment

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

I guess @calmh needs to clarify what he is after

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@calmh Plz would you have a look at this?

@@ -191,7 +191,7 @@ func (f *rwFolder) Serve() {
l.Debugln(f, "skip (initial)")
f.pullTimer.Reset(f.sleep)
} else {
prevVer, prevIgnoreHash = f.onExpiredPullTimerfunc(prevVer, prevIgnoreHash)
prevVer, prevIgnoreHash = f.updatePreviousVersionAndPreviousIgnoreHashOnExpiredPullTimer(prevVer, prevIgnoreHash)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sry for that long name updatePreviousVersionAndPreviousIgnoreHashOnExpiredPullTimer. This gives me a hint there is more than one responsibility in this method. Just stopped here for a while.

@calmh
Copy link
Member

calmh commented May 4, 2016

I think the gains would come from moving the actual scanning functionality into the folderScanner. Moving an attribute into a separate type, only to access that attribute directly anyway (even via a method) mostly obfuscates, in my opinion.

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 4, 2016

The indirect access is the thinking of object oriented programming. The scanner() acted as a getter. But for the sake of merging I reverted it.

return paused
defer m.pmut.Unlock()

return m.devicePaused[device]
Copy link
Member

Choose a reason for hiding this comment

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

defer kills potential inlining by the compiler (or so I've been told), and given this is small, it looks like a good candidate for inlining.

Copy link
Contributor Author

@lkwg82 lkwg82 May 4, 2016

Choose a reason for hiding this comment

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

ok. But how can I verify this? (Seems a trap of premature optimization, if it is wrong)

Copy link
Member

Choose a reason for hiding this comment

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

root@audrius:~# cat test.go
package main

func foo() int {
        return 0
}

func main() {
        foo()
}
root@audrius:~# go build -gcflags '-m' test.go
# command-line-arguments
./test.go:3: can inline foo
./test.go:7: can inline main
./test.go:8: inlining call to foo
root@audrius:~# cat test.go
package main

func foo() int {
        defer func(){}()
        return 0
}

func main() {
        foo()
}
root@audrius:~# go build -gcflags '-m' test.go
# command-line-arguments
./test.go:4: can inline foo.func1
./test.go:4: foo func literal does not escape

Yet it seems that anything that involves a mutex escapes to heap killing inlining.

@lkwg82
Copy link
Contributor Author

lkwg82 commented Jun 19, 2016

@AudriusButkevicius please have a look what is still missing. But consider to request to much changes in another PR ;)

@AudriusButkevicius
Copy link
Member

LGTM, but I'llleave for @calmh to merge

@lkwg82
Copy link
Contributor Author

lkwg82 commented Jun 28, 2016

bump

@calmh
Copy link
Member

calmh commented Jun 28, 2016

@st-jenkins retest this please

@@ -981,6 +981,20 @@ func (m *Model) GetIgnores(folder string) ([]string, []string, error) {
return lines, patterns, nil
}

func (m *Model) GetFolderFiles(folderID string) *db.FileSet {
Copy link
Member

Choose a reason for hiding this comment

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

These look like dead code to me, but apparently not to the metalinter. Am I missing something?

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 just checked metalinter and tried an update. But nothing helps. I dont know.

Copy link
Member

Choose a reason for hiding this comment

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

It's an exported method. Those can't be dead code eliminated so it makes sense that metalinter doesn't see this, when thinking about it. :)

@@ -981,6 +981,13 @@ func (m *Model) GetIgnores(folder string) ([]string, []string, error) {
return lines, patterns, nil
}

func (m *Model) GetIgnoreMatcher(folderID string) *ignore.Matcher {
Copy link
Member

Choose a reason for hiding this comment

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

You forgot this one

@calmh
Copy link
Member

calmh commented Jun 29, 2016

@st-review merge it

lib/model: Refactor encapsulation of the folder scanning

@st-review
Copy link

👌 Merged as af0bc95. Thanks, @lkwg82!

@st-review st-review closed this Jun 29, 2016
st-review pushed a commit that referenced this pull request Jun 29, 2016
@lkwg82 lkwg82 deleted the refactor-2 branch June 29, 2016 06:49
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jun 29, 2017
@syncthing syncthing locked and limited conversation to collaborators Jun 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants