473,378 Members | 1,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Null pattern

I'd like to extend the Null pattern from
http://aspn.activestate.com/ASPN/Coo...n/Recipe/68205 to
handle special methods (e.g. Null[3], del Null['key'], Null+1) but
it's not always clear how to do it while keeping the behavior
consistent and intuitive.

For example, consider the container methods __len__, __iter__ and
__contains__. The obvious choice for a null container is an empty one.
When taking __getitem__ into account though, the behaviour looks
inconsistent:
>>Null[3]
Null
>>len(Null)
0

Another group of methods is rich comparisons: Should Null x be
allowed and if so, what it should return ?

Then again, perhaps Null is an inherently domain-specific notion and
there are no general answers to such questions, in which case it
doesn't make sense trying to define an all-purpose Null object.

George
Jun 27 '08 #1
1 1585
George Sakkis <ge***********@gmail.comwrites:
For example, consider the container methods __len__, __iter__ and
__contains__. The obvious choice for a null container is an empty
one. When taking __getitem__ into account though, the behaviour
looks inconsistent:
>>Null[3]
Null
>>len(Null)
0
I think the typical use case of Null (a special object designed to
allow any use harmlessly) would allow the above inconsistency as the
least-worst solution.
Another group of methods is rich comparisons: Should Null x be
allowed and if so, what it should return ?
I expect this should take advantage of the following provision from
<URL:http://docs.python.org/ref/customization.html>:

A rich comparison method may return the singleton NotImplemented
if it does not implement the operation for a given pair of
arguments. …

So, perhaps 'Null.__cmp__' should always return 'NotImplemented',
allowing Python's fallback comparison behaviour to take over.

--
\ "Are you pondering what I'm pondering, Pinky?" "Sure, Brain, |
`\ but how are we going to find chaps our size?" -- _Pinky and |
_o__) The Brain_ |
Ben Finney
w
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brendan McLoughlin | last post by:
Hi, I am looking for opinions and alternatives for handling null values in a data object which reads a record from a database table. This object will have properties which will be populated...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
29
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's...
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
51
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
15
by: Tarun Mistry | last post by:
Hi guys, what is the best/correct way to check for a NULL object? I.e. myClass test; if(test == null) {}
15
by: khan | last post by:
Hi, I read that pointer representation can non-zero bit pattern, machine specific.Compiler when comes accross value '0' in pointer context, converts it to machine specific null pointer...
18
by: sanjay | last post by:
Hi, I have a doubt about passing values to a function accepting string. ====================================== #include <iostream> using namespace std; int main() {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.