This crazy idea is inspired by a discussing in Python-Dev which should be here. Currently we have a None singleton which representing nothing and raises an exception in almost all operations (except equality, etc). What about introducing its antonym, an Everything singleton (the name is discussable), which newer raises an exception in any operation, but returns consistent value?
Everything + 2 2 Everything < 3 True Everything * 'foo' 'foo'
Your examples do not make sense to me. On Tue Feb 18 2014 at 11:08:00 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
This crazy idea is inspired by a discussing in Python-Dev which should be here.
Currently we have a None singleton which representing nothing and raises an exception in almost all operations (except equality, etc). What about introducing its antonym, an Everything singleton (the name is discussable), which newer raises an exception in any operation, but returns consistent value?
Everything + 2 2 Everything < 3 True Everything * 'foo' 'foo'
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
This idea comes up occasionally (though I've never heard it named "everything" before). I believe it is similar to a feature in Objective-C (or maybe just Apple's version) where the behavior is that if you send any message to nil it does nothing and returns nil. In Python I think it would be very disturbing though and would end up masking errors. (Python and ObjC seems to have very different attitudes about exceptions -- in Python they are used all the time while in ObjC the culture seems to favor the idea that exceptions are fatal and shouldn't even be caught.) On Tue, Feb 18, 2014 at 11:09 AM, Amber Yust <amber.yust@gmail.com> wrote:
Your examples do not make sense to me.
On Tue Feb 18 2014 at 11:08:00 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
This crazy idea is inspired by a discussing in Python-Dev which should be here.
Currently we have a None singleton which representing nothing and raises an exception in almost all operations (except equality, etc). What about introducing its antonym, an Everything singleton (the name is discussable), which newer raises an exception in any operation, but returns consistent value?
Everything + 2 2 Everything < 3 True Everything * 'foo' 'foo'
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido)
As Serhiy notes, Python's None value fails when trying to use it. In contrast, SQL's NULL does not fail and instead the NULL propagates. Note that this is not what Serhiy actually proposed. I can see that he wants Everything to be essentially an empty value for + and * but no idea why Everything < 3 is True. Unless of course he meant Everything <3 (the emoticon). :-) None + 3 => exception NULL + 3 => NULL In some sense, None is related to BOTTOM (⊥) and NULL is related to TOP (⊤). While I've sometimes wanted a None-like object that would not raise exceptions when operated on, I've usually thought it better to create an object that ignored specific expected operations not everything. Is there a use case or is this just an abstract idea? --- Bruce Learn how hackers think: http://j.mp/gruyere-security On Tue, Feb 18, 2014 at 11:27 AM, Guido van Rossum <guido@python.org> wrote:
This idea comes up occasionally (though I've never heard it named "everything" before). I believe it is similar to a feature in Objective-C (or maybe just Apple's version) where the behavior is that if you send any message to nil it does nothing and returns nil.
In Python I think it would be very disturbing though and would end up masking errors. (Python and ObjC seems to have very different attitudes about exceptions -- in Python they are used all the time while in ObjC the culture seems to favor the idea that exceptions are fatal and shouldn't even be caught.)
On Tue, Feb 18, 2014 at 11:09 AM, Amber Yust <amber.yust@gmail.com> wrote:
Your examples do not make sense to me.
On Tue Feb 18 2014 at 11:08:00 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
This crazy idea is inspired by a discussing in Python-Dev which should be here.
Currently we have a None singleton which representing nothing and raises an exception in almost all operations (except equality, etc). What about introducing its antonym, an Everything singleton (the name is discussable), which newer raises an exception in any operation, but returns consistent value?
Everything + 2 2 Everything < 3 True Everything * 'foo' 'foo'
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido)
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
On 02/18/2014 08:27 PM, Guido van Rossum wrote:
This idea comes up occasionally (though I've never heard it named "everything" before). I believe it is similar to a feature in Objective-C (or maybe just Apple's version) where the behavior is that if you send any message to nil it does nothing and returns nil.
In Python I think it would be very disturbing though and would end up masking errors.
Yes; and unfortunately this often happens (also with none in python, when misused); there are related discussion about NaN as well (eg see Eiffel), and with funcs which try to guess clients' needs instead of just failing.
(Python and ObjC seems to have very different attitudes about exceptions -- in Python they are used all the time while in ObjC the culture seems to favor the idea that exceptions are fatal and shouldn't even be caught.)
(Rather, they are for cases of failures impredictable on the client side (eg file not found), which are not programmer errors (the cases belong to the app logic); in such a case, one may catch and deal with the case (eg create the file)). d
On Tue, Feb 18, 2014 at 1:07 PM, Serhiy Storchaka <storchaka@gmail.com>wrote:
This crazy idea is inspired by a discussing in Python-Dev which should be here.
Currently we have a None singleton which representing nothing and raises an exception in almost all operations (except equality, etc). What about introducing its antonym, an Everything singleton (the name is discussable), which newer raises an exception in any operation, but returns consistent value?
Everything + 2 2 Everything < 3 True Everything * 'foo' 'foo'
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Sounds like Haskell's Maybe in a slight way. Personally, I'm favored against it, because, as Guido said, it can mask already hard to find bugs. I understand the idea of a null-ish value like this: def f(a,b): return a+b f(Everything,b) or: class x(some_base): def __eq__(self, rhs): return self.some_value == rhs.some_value x() == Everything # True A quick glance, however, would show that it could make writing libraries a pain(What if the user puts Everything? It should work...but it might not!). -- Ryan If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated."
From: Serhiy Storchaka <storchaka@gmail.com> Sent: Tuesday, February 18, 2014 11:07 AM
T his crazy idea is inspired by a discussing in Python-Dev which should be here.
Currently we have a None singleton which representing nothing and raises an exception in almost all operations (except equality, etc). What about introducing its antonym, an Everything singleton (the name is discussable), which newer raises an exception in any operation, but returns consistent value?
Everything + 2 2 Everything < 3 True Everything * 'foo' 'foo'
What about these: >>> Everything + None >>> 1 if Everything else 0 >>> int(Everything) >>> iter(Everything) >>> next(Everything) >>> Everything(23, kw=42) >>> Everything[-1, 1:3, ...] >>> range(Everything) >>> spam(1, Everything, 2) >>> eggs[Everything:-1] None acts a lot like a singleton value of an ultimate superclass, if the language had such a thing. In fact, it acts almost exactly like, e.g., Scala's null, where null is a singleton instance of the ultimate superclass Null (well, it's really a penultimate superclass; there's Nothing, with _no_ instances, above it… but that isn't relevant here). So Everything should act like a singleton value of an ultimate subclass, right? But Python has an ultimate subclass, object, and it already works almost exactly like Scala's equivalent, Any. You can create lots of object instances, and it can make good sense to do so (e.g., as separate sentinels for separate functions at the same scope). These instances support only a bare minimum set of operations (equality testing, type testing, hashing, string-representing, and introspection). In Scala, Any is also useful as a declared type for variables, as a way to wedge duck typing into static typing (a function can take an Any parameter, a collection can be parameterized on Any element type, etc., in which case they effectively act like Python functions and collections), and there are a few places in or near Python (e.g., parameter attributes used for type annotation, Cython variable types, the PyObject* type and "o"-related arg types in the C API, etc.) where it's used for the same thing. So, Everything clearly isn't the opposite of None in that sense. So… what type _is_ it? Maybe Objective C's nil is a better model. It's a legal value of all types (even those that aren't derived from NSObject or any alternate real class root), and you can call any method on it and it will return nil. But you still can't pass it as an argument to any arbitrary function or operator and expect to get back anything consistent (and, to the extent that you _do_ expect something consistent, it's nil, not some other value from the expression). And the same is true with SQL NULL, IEEE NaN, and every other similar value I can think of: they all avoid exceptions by "infecting" every expression as much as possible, not as little as possible. For a type like that, Everything is easier, but there are still some problems: >>> Everything + 2 Everything >>> Everything < 3 ??? (could be Everything, but you still have to decide whether that's truthy…) >>> Everything * 'foo' Everything >>> Everything + None Everything >>> 1 if Everything else 0 1 # assuming Everything is truthy, as above >>> int(Everything) Everything # fine, but what about Everything.__index__()? >>> iter(Everything) Everything? >>> next(Everything) Everything? >>> Everything(23, kw=42) Everything? >>> Everything[-1, 1:3, ...] Everything? >>> range(Everything) ??? >>> spam(1, Everything, 2) ??? # often Everything, but no guarantee >>> eggs[Everything:-1] ??? But anyway, even if it's easier to define, it's not what you wanted…
On Tue, Feb 18, 2014 at 09:07:07PM +0200, Serhiy Storchaka wrote:
This crazy idea is inspired by a discussing in Python-Dev which should be here.
Currently we have a None singleton which representing nothing and raises an exception in almost all operations (except equality, etc). What about introducing its antonym, an Everything singleton (the name is discussable), which newer raises an exception in any operation, but returns consistent value?
Everything + 2 2
Here, your Everything value acts like the Null Object pattern.
Everything < 3 True
Here, your Everything value acts like a Smallest object. But if you then do Everything > 5, presumably you would want it to return True, so it also acts like a Biggest object. Why have Everything < 3 return True? Why not False?
Everything * 'foo' 'foo'
Here, your Everything object acts like an Identity object. But earlier you had it acting like a Null object. How does the Everything object decide whether it should behave as Null or Identity for a certain operation? E.g. should 23**Everything return 1 or 23? 23 == Everything == 42 will presumably return True. What should these things do? some_dict.pop(Everything) # Is this the same as some_dict.clear()? Everything & 42 '+'.join(['a', 'b', Everything, 'c']) I don't think this idea is either useful or self-consistent. -- Steven
Is there a strong use case for this? How did this idea come about? On Feb 18, 2014 11:08 AM, "Serhiy Storchaka" <storchaka@gmail.com> wrote:
This crazy idea is inspired by a discussing in Python-Dev which should be
here.
Currently we have a None singleton which representing nothing and raises
an exception in almost all operations (except equality, etc). What about introducing its antonym, an Everything singleton (the name is discussable), which newer raises an exception in any operation, but returns consistent value?
Everything + 2 2 Everything < 3 True Everything * 'foo' 'foo'
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
participants (10)
-
Amber Yust -
Andrew Barnert -
Bruce Leban -
Greg -
Guido van Rossum -
Ryan Gonzalez -
Serhiy Storchaka -
spir -
Steven D'Aprano -
Westley Martínez