Skip to content

Simplify terminology and behavior.#4

Merged
ramsey merged 12 commits into
conneg:masterfrom
mkantor:master
Sep 12, 2012
Merged

Simplify terminology and behavior.#4
ramsey merged 12 commits into
conneg:masterfrom
mkantor:master

Conversation

@mkantor
Copy link
Copy Markdown
Contributor

@mkantor mkantor commented Sep 11, 2012

  • Improve accuracy/precision of wording (including method names, variable names, and documentation) wherever possible.
  • Simplify a few internal algorithms.
  • Change tie-breaking behavior to use the order of the $supported array (mime-types closer to the beginning of the array are preferred) instead of a separate $tieBreaker parameter.

The public-facing (possibly backwards-incompatible) changes are as follows:

  • parseMimeType() becomes parseMediaRange().
  • The message of the UnexpectedValueException thrown by parseMediaRange() is different.
  • bestMatch() loses its $tieBreaker parameter, and the order of the $supported array becomes significant.

Apologies for the large changeset. I can try to split this up into multiple pull requests if you'd prefer, but it may take some time. Hopefully my commit history is clean enough for you to easily review.

- Rename parseMediaRange to parseAndNormalizeMimeType to better
  explain its relationship with parseMimeType.
- Update parseAndNormalizeMimeType to not eat parseMimeType's generic
  subtype.
- Update documentation and tests to reflect changes.
- Rename parseMimeType and parseAndNormalizeMimeType to *MediaRange.
- Rename several variables in the same fashion.
- Update documentation where appropriate.
- Update tests to reflect changes (also fix a stray usage of "format"
  for "generic subtype").
@ramsey
Copy link
Copy Markdown
Contributor

ramsey commented Sep 12, 2012

Most of the documentation and terminology all comes from the original code here: http://code.google.com/p/mimeparse/

I simply copied it over mostly verbatim.

I like and agree with your changes, but I'll have to give it a little thought, since it does break backwards compatibility.

In addition, your pull request removes code that I've since added 4-5 days ago, so you'll need to pull the latest from master before I can accept this request.

Thanks!

@mkantor
Copy link
Copy Markdown
Contributor Author

mkantor commented Sep 12, 2012

I forked after your latest commit, 8c53c4f. If you check out the network graph you should see that my repository is up to date.

Let me know if there's any changes I should make or anything else I can do to make things easier.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you choose to remove the $tieBreaker parameter? If so, why?

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.

Yes. As stated in my commit messages I changed the behavior to use the order of the $supported array to break ties, making $tieBreaker unnecessary.

This allows for more flexible behavior which would not be possible with a single $tieBreaker parameter, including having multiple fallbacks (this is especially helpful when the specified $tieBreaker is not among the best matches, but there is still a tie) and easier handling of tie breakers when the $supported array is not constant.

It also specifies previously-unspecified behavior: What happens when there is a tie but no $tieBreaker (or one which does not match)? Now that condition is impossible.

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.

FYI: I made this change in 67fb915.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oops. I glossed over that when originally reading the PR description. Sorry about that. I like your approach better. I had given that approach some thought when I built in the $tieBreaker, but my original goal was to stick as close to the original implementation as possible, and changing the behavior of $supported breaks what is expected in the other implementations (i.e. Java, Python, Ruby, etc.).

Given that your updates change the naming and behavior expected in all the other implementations, I'm less inclined to follow their convention, and I'm okay with merging in your changes.

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.

Thankfully, making the order of $supported significant only serves to specify unspecified behavior in the other implementations (it doesn't actually "change the rules", it just "makes a new rule"). I haven't tested other implementations' behavior as far as what happens when there are ties, but I wouldn't be surprised to learn that there are already inconsistencies between them.

Thanks for reviewing/merging, and again sorry that I handed this over to you as one big fat blob of changes. In the future I'll try to submit more atomic pull requests. 😄

ramsey added a commit that referenced this pull request Sep 12, 2012
Simplify terminology and behavior.
@ramsey ramsey merged commit 563b9cd into conneg:master Sep 12, 2012
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.

2 participants