Skip to content

Adds distribution() convenience function.#440

Closed
kwmsmith wants to merge 1 commit into
masterfrom
feature/distribution-creation
Closed

Adds distribution() convenience function.#440
kwmsmith wants to merge 1 commit into
masterfrom
feature/distribution-creation

Conversation

@kwmsmith
Copy link
Copy Markdown
Contributor

I'm tired of typing Distribution.from_shape all the time. This seems
to be the main entry point, so distribution is a shortcut.

I'm tired of typing `Distribution.from_shape` all the time.  This seems
to be the main entry point, so `distribution` is a shortcut.
@kwmsmith kwmsmith added this to the 0.4 milestone Jun 13, 2014
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.02%) when pulling 6aac2b5 on feature/distribution-creation into 7a7bf40 on master.

@bgrant
Copy link
Copy Markdown
Contributor

bgrant commented Jun 24, 2014

One down side- I often name my instances distribution :)

@kwmsmith
Copy link
Copy Markdown
Contributor Author

OK, what about this design then:

  • Distribution.from_shape ==> Distribution.__init__
  • New classmethod Distribution.from_maps
  • Distribution.__init__ and all other alternative constructors call Distribution.from_maps to make a Distribution object.

I'd really like a shorter name for what is now Distribution.from_shape, since that is by far the most common and convenient way to make distribution objects.

@kwmsmith kwmsmith changed the title Adds distribution() conveinence function. Adds distribution() convenience function. Jun 24, 2014
@bgrant
Copy link
Copy Markdown
Contributor

bgrant commented Jun 24, 2014

Haha, yeah, that's probably the way to go. I think that's the way it was before, and we changed it to this way because we wanted the most general constructor to be __init__.

@bgrant
Copy link
Copy Markdown
Contributor

bgrant commented Jul 1, 2014

We have considered two design principles for alternate constructors:

  1. __init__ is the most general method, and all other constructors call it
  2. __init__ is the most commonly used method, and it likely calls another, more general, classmethod constructor (as do the other alternate constructors).

I'm leaning towards (2.) now, as makes sense for the shortest name to call the most commonly-used method. I seem to remember Raymond Hettinger recommending that as well. I do think we should try, as much as possible, to have all constructors call an underlying general constructor; else we can end up with bugs where some constructors don't create all the same instance attributes as others.

@bgrant
Copy link
Copy Markdown
Contributor

bgrant commented Jul 1, 2014

@kwmsmith: Should we close this PR and make an issue?

@kwmsmith
Copy link
Copy Markdown
Contributor Author

kwmsmith commented Jul 1, 2014

Closing. Will be addressed by a different PR.

@kwmsmith kwmsmith closed this Jul 1, 2014
@kwmsmith kwmsmith deleted the feature/distribution-creation branch July 1, 2014 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants