Clinton wrote:
> [a patch for truncate()]

Hi Clinton, thanks for the patch.

I'm all in favour of the functionality, but I'm not so keen on the
way the parameters have turned out (though that's really not your fault
- it's the best job in a bad situation)

  truncate(max, suffix, min)

Obviously we don't want to go changing the order of the first two
parameters because it'll break existing code.  But tagging the min
parameter on the end feels pretty wrong too.  It's not very intuitive
or obvious as to why it's that way (other than "backwards compatibility").

It's issues like this that make me lean heavily towards named parameters.
That way you have more flexibility, with no ambiguity or long argument
lists to remember.

e.g.

  truncate(max=32, min=26)
  truncate(min=15)
  truncate(words=5)

Because TT allows you to use both positional and named parameters,
this is something we can support relatively easily.  It's just a
question of modifying the filter to expect and accommodate it.
(named parameters get merged into a hash reference which is passed
as the last positional argument)

  truncate(32, '...')               # positional
  truncate(max=32, suffix='...')    # named
  truncate(32, suffix='...')        # both

However, I think that is something that should be done for all filters
as part of the mass cleanup and patchup from TT2 to TT3.  Furthermore,
in TT3, filters, vmethods and the string plugin will all be merged into
one Template::Text module (or something similarly named) to avoid all the
unnecessary duplication that we currently have.

Incidentally, most of this work is already done for TT3.  I'll make finishing
it one of my priorities so I can release the code for you lot to tear apart.
I'm sure there are lots of other filters/vmethods that can be improved upon
in various ways and it's something that can be done in relative isolation
from the rest of the development process.

So in the longer term we'll fix it properly and include this functionality
in a more flexible way.  In the short term, I'm disinclined to add a third
parameter that we'll have to provide backward compatibility with in the
future.

So I think I'll have to pass on the patch this time, but keep the basic
idea.  Thank you for your efforts, all the same.

Cheers
A




_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to