LWN.net Logo

Why is it a mess?

Why is it a mess?

Posted Dec 20, 2011 23:32 UTC (Tue) by pboddie (subscriber, #50784)
In reply to: Why is it a mess? by khim
Parent article: Cracks in the Foundation (PHP Advent)

In languages like perl, php and python (which try to "guess" what you meant and "help" you) it's disaster, obviously.

Python doesn't "guess" anything. There's a protocol that all classes support which indicates whether an instance is considered true or false.


(Log in to post comments)

Why is it a mess?

Posted Dec 21, 2011 7:37 UTC (Wed) by ekj (guest, #1524) [Link]

Yeah. But even python considers boolean false and integer zero to be equivalent, and all other integers to be true. Indeed the method to override to define your own behaviour for if object is object.__nonzero__ or object.__len__

From the naming alone it's clear that being "true" by convention means "having length" or "not being zero". (why is the method __nonzero__ and not __zero__ (with opposite semantics) by the way, seems an odd kind of superfluous negation. Returning false hear means that the object is *not* *nonzero* i.e. that it's zero.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds