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

style: add comments #588

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

style: add comments #588

wants to merge 8 commits into from

Conversation

c33howard
Copy link

Add code comments to the code to aid understanding.

I'm trying to wrap my head around some of the details of the signalk implementation and adding comments seemed like the most efficient way to do this. I figured others would benefit from the work.

There's some very light refactoring in here where it simplified the explanation.

Little bit of refactoring to simplify the flow.

- No need for an else branch when the if branch ends with a return
- path length is compared to 0 at the beginning of the function, no need
to check it's not 0 at the end
s/mmsiPrefixLenght/mmsiPrefixLength/
findContext() is really doing two jobs, so renamed to describe what else
it's doing.  It's probably best to split into multiple functions, but
this seemed simplest for now.
Copy link
Member

@tkurki tkurki left a comment

Choose a reason for hiding this comment

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

All in all a really nice job! I've done the same a few times in open source projects, documenting how an algorithm works just to wrap my head around it. Nice to be on the receiving end!

Would you mind addressing my minor comments?

src/fullsignalk.js Outdated Show resolved Hide resolved
parts.reduce((cursor, part) => {
if(typeof cursor[part] === 'undefined') {
return cursor[part] = {}
}
return cursor[part]
}, this.sources)

// Uh, shouldn't something be done with the result of the reduce? What if
// the pointed to value isn't found?
Copy link
Member

Choose a reason for hiding this comment

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

You already documented what this does: creating elements as needed, using reduce cursor as a temp variable.

Copy link
Author

Choose a reason for hiding this comment

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

I'm still confused. All this does is create elements, it doesn't actually update anything. Notice that context and timestamp aren't referenced in the body of the method. (Which means my comment is wrong, it's descending into this.sources, not context.)

Copy link
Member

Choose a reason for hiding this comment

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

Ok, so

  • it is handling this.sources and context is not needed nor used here, should be removed
  • it is not updating timestamp, which it should be doing, so a bug - add a FIXME comment in this documentation PR?
  • your comment about descending into sources of the context is not correct, so to get this PR merged please remove that

src/fullsignalk.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants