On 11/11/2011 09:34, René Dudfield wrote:
On Fri, Nov 11, 2011 at 10:23 AM, Jonathan <tart...@tartley.com <mailto:tart...@tartley.com>> wrote:

    That's good to know René, but I *think* it's orthogonal to the
    question. Please correct me if I'm wrong.

    If PyPy returns items in a different order than CPython, that
    doesn't matter to me, so long as every invocation of my function
    in a particular process ends up receiving a particular  order,
    that doesn't change until the process ends (or the cache is cleared.)

    The dict subclass is a great idea - but if the change in order
    isn't ever manifested by a regular dict, then it implies to me
    that the 'sorted' call isn't actually required in real life, so
    the need for this whole test disappears.

    See also my imminent reply to Ross.

        Jonathan



Just because your code works Now, does not mean it will work in the future. Especially when the ordering is explicitly marked as a non-deterministic implementation detail. Relying on it to be deterministic when it is stated to be non-deterministic will mean that in the future you could get a failure.

Relying on implementation quirks is fine, but not reliable. In your case though, the worst that can happen now is a cache miss. In the future though, your cache could be completely useless because every time the data could be in a different order.

Testing on multiple platforms allows you to sometimes see a failure condition, which lets you test it. Likewise, using a randomised dict subclass will let you test your code as if there is an error condition.

cya.

ps. my randomised items subclass is buggy... I forgot that random.shuffle works in place, and doesn't return a shuffled sequence.


_______________________________________________
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk

Hey René,
Thanks for that! I guess I was getting distracted because I was interpreting the situation as the fact that .items() for an *arbitrary* dictionary may well be non-deterministic, but in this particular case, for dictionaries newly-created by the '**' mechanism, they appear to be non-deterministic. I was forgetting that this is (presumably) also an implementation detail. Regardless, it sounds like you are probably right on all counts. Thanks for your enlightening thoughts.
Cheers,
    Jonathan

--
Jonathan Hartley    tart...@tartley.com    http://tartley.com
Made of meat.       +44 7737 062 225       twitter/skype: tartley


_______________________________________________
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk

Reply via email to