[Piglit] [PATCH 2/4] arb_shader_precision: add framework for calculating tolerances for complex functions
baker.dylan.c at gmail.com
Thu Feb 19 13:57:44 PST 2015
On Thu, Feb 19, 2015 at 02:27:38PM -0500, Ilia Mirkin wrote:
> On Thu, Feb 19, 2015 at 2:16 PM, Dylan Baker <baker.dylan.c at gmail.com> wrote:
> > On Thu, Feb 19, 2015 at 02:03:41PM -0500, Ilia Mirkin wrote:
> >> On Thu, Feb 19, 2015 at 12:59 PM, Dylan Baker <baker.dylan.c at gmail.com> wrote:
> >> >> + return -1.0 if any(ret['badlands']) else map(float,
> >> >> ret['component_tolerances'])
> >> >
> >> > Generally at this point python (both upstream and community) discourage
> >> > the use of map and filter, with a preference for comprehensions.
> >> > [float(x) for x in ret['component_tolerances']] should be what you want.
> >> Just to provide a counterpoint, I think that
> >> map(float, fooarray)
> >> is a ton more readable than
> >> list(float(x) for x in fooarray)
> > I agree that list(generator) is ugly, which is why I suggested a list
> > comprehension, and not a generator comprehension.
> Ah. But with a list comprehension the variable leaks out, so I tend to
> avoid it since it can, in certain situations, create horribly
> difficult to track down bugs. But my point still stands -- I prefer
I'll concede that map() is a pretty standard concept, especially if
you've worked with functional programing languages. The leaking of
variables is a python2.x bug, it's not present in 3.x. And honestly,
if you follow good practices and don't have a lot of one letter
variables just floating in your code you're unlikely to hit a weird bug
from that value leaking.
> map(float, fooarray)
> [float(x) for x in fooarray]
> Map is a pretty core concept in computer science and math, I think
> most people are familiar with it. With the comprehension, I have to
> read the whole thing carefully to see if it does something weird.
> Anyways, I think, like many things, this comes down to personal
> preference, in which case whatever the author of the code likes to do
> goes. I think that PEP8 or whatever the doc with "The One And Only
> True Way To Write Python" thing is went way too far.
I think that the "one, and preferably only one" concept is one of the
nice things about python. Coming from a background in ruby I find that
Anyway, since we're only using map I'll drop the suggestion.
I am however adamant that if we're using filter and map together a
comprehension is much more readable.
[f(x) for x in a_list if x is not None]
is much more readable than
filter(map(f, a_list), lambda x: x is not None)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 473 bytes
Desc: Digital signature
More information about the Piglit