Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

add circular buffer exercism#17

Merged
wilmoore merged 1 commit intoexercism:masterfrom
anthonygreen:circular-buffer
May 16, 2014
Merged

add circular buffer exercism#17
wilmoore merged 1 commit intoexercism:masterfrom
anthonygreen:circular-buffer

Conversation

@anthonygreen
Copy link
Copy Markdown
Contributor

The last pull request appears to have been deleted following an attempt to resolve a bad merge.
Here it is again
cc @wilmoore

@wilmoore
Copy link
Copy Markdown

Thanks for updating. I'll have a look.

Comment thread circular-buffer/example.js Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

missing semicolon.

@anthonygreen
Copy link
Copy Markdown
Contributor Author

Updated pull request with some of the requested changes.

Comment thread circular-buffer/example.js Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The parens are superfluous here and don't really add anything to the readability so we can probably nix them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing semicolon.

@anthonygreen
Copy link
Copy Markdown
Contributor Author

Ready for review

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You still seem to have the superfluous anonymous function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's expected. See Jasmine Matchers https://github.com/pivotal/jasmine/wiki/Matchers

@anthonygreen
Copy link
Copy Markdown
Contributor Author

Mainly typo fixes in these commits.

@anthonygreen
Copy link
Copy Markdown
Contributor Author

Apologies @wilmoore Could you review again and suggest the appropriate changes. Thanks

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The best way I know to explain it is with an example:

function call(fn) {
  return fn();
}

function make_money() {
  return "$5.00";
}

// superfluous
console.log("superfluous: %s", call(function () {
  return make_money();
}));

// treating functions as first-class
console.log("first-class: %s", call(make_money));

This will produce output of:

superfluous: $5.00
first-class: $5.00

Same result, but it is obvious which is less code, easier to read and reason about.

The fact of the matter is, whenever a function takes another function, it is doing so because it means to call that function. It doesn't matter which function you pass it, so long as when it is called, it does what you want. In the case of the code we are reviewing, buffer.read is referring to a function. If all you are doing in the anonymous function is calling just that function, you may as well just pass the function reference itself so it will get called directly rather than having to pass a wrapper function where you manually invoke it.

I hope this helps.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's expected. See Jasmine Matchers https://github.com/pivotal/jasmine/wiki/Matchers

That's mostly an issue with how they choose to document this case.

@anthonygreen
Copy link
Copy Markdown
Contributor Author

Ready for review

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants