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

should bare methods that expect input be an exception? #245

Open
notbenh opened this issue Mar 22, 2013 · 1 comment
Open

should bare methods that expect input be an exception? #245

notbenh opened this issue Mar 22, 2013 · 1 comment

Comments

@notbenh
Copy link
Contributor

notbenh commented Mar 22, 2013

This is related to #241

Currently we have methods that preform some action with out input:

my $rounded_number = 12.1->round;

Others expect input:

my $joined_string = [1,2,3]->join(':');

Should a call to join with out any input be an exception:

my $joined_string = [1,2,3]->join;

If so, for the sake of consistency should we now make ->round an exception to? How will we inform the user what methods take input and which ones do not?

@schwern
Copy link
Contributor

schwern commented Mar 22, 2013

Default to yes. Which is to say, if you're not sure what the default should be make it an exception. This is to counter act the Perl tendency to make everything do something. We can always make it not an exception later whereas the other way around has to wait for a major version.

Otherwise, I don't think we need to make a blanket rule about what handing a method no argument means. Its a case by case basis how obvious the default is. You can figure that out by having a little conversation with yourself.

Alice: Round 12.1 please.
Bob:  12

See how one doesn't have to ask "to what precision" or "up or down". Even though these are rounding options, humans, on a regular basis, round in one way.

Contrast with join...

Alice:  Join "foo", "bar", and "baz" together.
Bob:  Join them with what?
Alice:  Commas.

Alice could have equally likely said "spaces" or "tabs" or "nothing". Good indicator that join should not have a default.

I've written this up in the coding standards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants