On 27/11/2015 21:28, Marvin Humphrey wrote:
The workaround after the proposed behavior change would be to be very careful
about adding named parameters:
my %args = (
analyzer => Lucy::Analysis::StandardTokenizer->new,
indexed => 1,
)
if (defined $config->{$field}{stored}) {
$args{stored} = $config->{$field}{stored};
}
if (defined $config->{$field}{sortable}) {
$args{sortable} = $config->{$field}{sortable};
}
my $field_spec = Lucy::Plan::FullTextType->new(%args);
Or provide the default yourself:
my $field_spec = Lucy::Plan::FullTextType->new(
analyzer => Lucy::Analysis::StandardTokenizer->new,
indexed => 1,
stored => $config->{$field}{stored} // 1,
sortable => $config->{$field}{sortable} // 1,
)
However, I wouldn't consider that an improvement, and it's not possible to
get there from where we are today without inducing silent failure.
Why not? We could add a custom XS wrapper with the old behavior for every Lucy
constructor and method that has a bool param defaulting to true.
I wouldn't rule out making a breaking change to Lucy for the sake of
Clownfish at some point in the future, but for this proposal, I don't think
the costs are justified by the benefits.
There is no perfect way to handle the "bool defaults to true" case. If we
treat undef as false and the user wants "undef means default", code must look
like:
$foo->bar(defined($bool) ? $bool : 1); # or
$foo->bar($bool // 1);
If we treat undef as default and the user wants "undef means false", code must
look like:
$foo->bar(defined($bool) ? $bool : 0); # or
$foo->bar($bool // 0);
For Perl, I find "undef means false" more idiomatic.
Nick