It's more expensive if the except is hit frequently, but less expensive
than an explicit check if it is truly exceptional. IMO, they can make the
code more difficult to read when used often. I do like that use for feature
discovery, but I think in this case, given the nature of its use, I think
it makes more sense to have an explicit check at the top of the function
along the lines of:

```
if r not in data:
    raise ValueError("...")
```

Which would fit well next to the alpha parameter check as the try/except is
essentially an assertion on the value a parameter can take.


On Fri, Apr 25, 2014 at 10:10 AM, Jorge Cañardo Alastuey <
notifications@github.com> wrote:

> In skbio/maths/diversity/alpha/lladser.py:
>
> > +            13: 19.44256933,
> > +            14: 20.66856908,
> > +            15: 21.88648591,
> > +            16: 23.09712976,
> > +            17: 24.30118368,
> > +            18: 25.49923008,
> > +            19: 26.69177031,
> > +            20: 27.87923964,
> > +            21: 29.06201884,
> > +            22: 30.24044329,
> > +            23: 31.41481021,
> > +            24: 32.58538445,
> > +            25: 33.75240327,
> > +            50: 62.17105670,
> > +            }
> > +    try:
>
> Try/excepts are a very common Python idiom. From the Python glossary<https://docs.python.org/2.7/glossary.html>
> :
>
> *EAFP*
> Easier to ask for forgiveness than permission. This common Python coding
> style assumes the existence of valid keys or attributes and catches
> exceptions if the assumption proves false. This clean and fast style is
> characterized by the presence of many try and except statements. The
> technique contrasts with the LBYL style common to many other languages such
> as C.
>
> It is even sometimes recommended, so I reckon its usage doesn't have to be
> justified. E.g, from a week old post in python-dev<https://mail.python.org/pipermail/python-dev/2014-April/134172.html>
> :
>
> Feature discovery is better than explicit version checks:
>
>     try:
>         items = mydict.iteritems()
>     except AttributeError:
>         items = mydict.items()
>
>  --
> Reply to this email directly or view it on GitHub<https://github.com/biocore/scikit-bio/pull/283/files#r12003366>
> .
>