A question of style (finding item in list of tuples)

2012-05-21 Thread Roy Smith
I've got this code in a django app: CHOICES = [ ('NONE', 'No experience required'), ('SAIL', 'Sailing experience, new to racing'), ('RACE', 'General racing experience'), ('GOOD', 'Experienced racer'), ('ROCK', 'Rock star'), ] def

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Chris Angelico
On Mon, May 21, 2012 at 10:37 PM, Roy Smith r...@panix.com wrote: The above code works, but it occurs to me that I could use the much shorter:    def experience_text(self):        return dict(CHOICES).get(self.level, ???) So, the question is, purely as a matter of readability, which would

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Steven D'Aprano
On Mon, 21 May 2012 08:37:29 -0400, Roy Smith wrote: [...] The above code works, but it occurs to me that I could use the much shorter: def experience_text(self): return dict(CHOICES).get(self.level, ???) So, the question is, purely as a matter of readability, which would you

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread David Lambert
One suggestion is to construct the dictionary first: CHOICES = dict( NONE = 'No experience required', SAIL = 'Sailing experience, new to racing', RACE = 'General racing experience', GOOD = 'Experienced racer', ROCK = 'Rock star' ) def experience_text(self): try:

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Tim Chase
On 05/21/12 08:10, Steven D'Aprano wrote: On Mon, 21 May 2012 08:37:29 -0400, Roy Smith wrote: [...] The above code works, but it occurs to me that I could use the much shorter: def experience_text(self): return dict(CHOICES).get(self.level, ???) So, the question is, purely

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Jon Clements
On Monday, 21 May 2012 13:37:29 UTC+1, Roy Smith wrote: I've got this code in a django app: CHOICES = [ ('NONE', 'No experience required'), ('SAIL', 'Sailing experience, new to racing'), ('RACE', 'General racing experience'), ('GOOD', 'Experienced

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Roy Smith
On Monday, May 21, 2012 9:39:59 AM UTC-4, Jon Clements wrote: def experience_text(self): return dict(CHOICES).get(self.level, ???) Haven't used django in a while, but doesn't the model provide a get_experience_display() method which you could use... Duh, I totally missed

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread koranthala
That test was designed to treat None as a boolean False, without noticing that numeric 0 is also treated as False and could make the test do the wrong thing. This is an extremely common type of error. Actually, I felt that 0 not being considered False would be a better option. I had lot of

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Chris Rebert
On Thu, Jul 16, 2009 at 11:13 PM, koranthalakoranth...@gmail.com wrote: That test was designed to treat None as a boolean False, without noticing that numeric 0 is also treated as False and could make the test do the wrong thing.  This is an extremely common type of error. Actually, I felt

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Steven D'Aprano
On Thu, 16 Jul 2009 23:13:51 -0700, koranthala wrote: That test was designed to treat None as a boolean False, without noticing that numeric 0 is also treated as False and could make the test do the wrong thing. This is an extremely common type of error. Actually, I felt that 0 not being

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Paul Rubin
Steven D'Aprano st...@remove-this-cybersource.com.au writes: It is very useful to be able to write e.g.: if header or body or footer: print assemble_page(header, body, footer) and have empty strings to be equivalent to False. Why doesn't assemble_page properly handle the case where

Re: question of style

2009-07-17 Thread Piet van Oostrum
koranthala koranth...@gmail.com (k) wrote: That test was designed to treat None as a boolean False, without noticing that numeric 0 is also treated as False and could make the test do the wrong thing. This is an extremely common type of error. k Actually, I felt that 0 not being considered

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 00:34:00 -0700, Paul Rubin wrote: Steven D'Aprano st...@remove-this-cybersource.com.au writes: It is very useful to be able to write e.g.: if header or body or footer: print assemble_page(header, body, footer) and have empty strings to be equivalent to False.

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Paul Rubin
Steven D'Aprano st...@remove-this-cybersource.com.au writes: def assemble_page(header, body, footer): if header or body or footer: do_lots_of_expensive_processing() else: do_nothing_gracefully() Why should the processing be expensive if all three fields are empty?

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 07:12:51 -0700, Paul Rubin wrote: Steven D'Aprano st...@remove-this-cybersource.com.au writes: def assemble_page(header, body, footer): if header or body or footer: do_lots_of_expensive_processing() else: do_nothing_gracefully() Why should the

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Paul Rubin
Steven D'Aprano st...@remove-this-cybersource.com.au writes: Since I haven't specified an implementation for assemble_page, it could be doing *anything*. Perhaps it has to talk to a remote database over a slow link, perhaps it generates 300 lines of really inefficient HTML code with no

Question regarding style/design..

2009-07-17 Thread Wells Oliver
Sometimes I see relatively small application, generally task scripts, written as essentially a list of statements. Other times, I see them neatly divided into functions and then the if __name__ == '__main__': convention. Is there a preference? Is there an... application scope such that the

Re: Question regarding style/design..

2009-07-17 Thread Tim Chase
Sometimes I see relatively small application, generally task scripts, written as essentially a list of statements. Other times, I see them neatly divided into functions and then the if __name__ == '__main__': convention. Is there a preference? Is there an... application scope such that the

Re: Question regarding style/design..

2009-07-17 Thread Robert Kern
On 2009-07-17 12:11, Tim Chase wrote: Sometimes I see relatively small application, generally task scripts, written as essentially a list of statements. Other times, I see them neatly divided into functions and then the if __name__ == '__main__': convention. Is there a preference? Is there an...

Re: Question regarding style/design..

2009-07-17 Thread Tim Chase
Robert Kern wrote: [sage advice snipped] Don't waste half a day trying to figure out why your script mysteriously doesn't work. Learn from my mistakes. :-) I find that's the best type of mistake to learn from: other people's ;-) -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: Question regarding style/design..

2009-07-17 Thread Michael Torrie
Wells Oliver wrote: Sometimes I see relatively small application, generally task scripts, written as essentially a list of statements. Other times, I see them neatly divided into functions and then the if __name__ == '__main__': convention. Is there a preference? Is there an... application

Re: question of style

2009-07-16 Thread Albert van der Horst
In article 7x8wj4uxnb@ruckus.brouhaha.com, Paul Rubin http://phr...@nospam.invalid wrote: Anyway, Python's overloading of bool(...) is yet another misfeature and although it's convenient, the explicit is better than implicit principle indicates to avoid that sort of trick. Well, trading

Re: question of style

2009-07-16 Thread Albert van der Horst
In article 7x8wj2agma@ruckus.brouhaha.com, Paul Rubin http://phr...@nospam.invalid wrote: Steven D'Aprano st...@remove-this-cybersource.com.au writes: but I don't accept that somethingness vs. nothingness is the same distinction as truth vs falsehood. It's the distinction used by Python

Einstein summation notation (was: question of style)

2009-07-16 Thread Erik Max Francis
Albert van der Horst wrote: Einstein introduced the summation convention for indices that are used twice. Leaving out summation signs is absolutely hideous, but it has saved generations of physicists of loosing track (and their minds.) There is a joke among mathematicians that if Einstein

A question of style .....

2009-07-15 Thread tuxagb
If I have to write an extension module with many objects, how can I organizing the code? I think: every object in a separate file, and a last file with the PyInit_. function. But is unmenageable . Solutions? Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: A question of style .....

2009-07-15 Thread Bearophile
tuxagb: If I have to write an extension module with many objects, how can I organizing the code? I think: every object in a separate file, and a last file with the PyInit_. function. But is unmenageable . Solutions? What do you think about using Cython? Bye, bearophile --

Re: question of style

2009-07-05 Thread Paul Rubin
Steven D'Aprano st...@remove-this-cybersource.com.au writes: Yes, it saves a few keystrokes to say if x: instead of if len(x)==0: or even if bool(x):, It's not about saving keystrokes -- that's a furphy. It's about encapsulation. Objects are in a better position to recognise when they

Re: question of style

2009-07-05 Thread Lie Ryan
Paul Rubin wrote: Steven D'Aprano st...@remove-this-cybersource.com.au writes: if len(x) == 0 is wasteful. Perhaps I've passed you a list-like iterable instead of a list, and calculating the actual length is O(N). That doesn't happen in any of Python's built-in container types. I could

Re: question of style

2009-07-05 Thread Paul Rubin
Steven D'Aprano st...@remove-this-cybersource.com.au writes: I wouldn't say Python's None is terrible,... No, wait, I tell I lie... re.search() sometimes bites me, because sometimes it returns None and sometimes it returns a matchobject and I don't use re often enough to have good habits

Re: question of style

2009-07-05 Thread Steven D'Aprano
On Sun, 05 Jul 2009 03:08:16 -0700, Paul Rubin wrote: Steven D'Aprano st...@remove-this-cybersource.com.au writes: Yes, it saves a few keystrokes to say if x: instead of if len(x)==0: or even if bool(x):, It's not about saving keystrokes -- that's a furphy. It's about encapsulation.

Re: question of style

2009-07-05 Thread Steven D'Aprano
On Sun, 05 Jul 2009 11:37:49 +, Lie Ryan wrote: Neither python's `if` nor `if` in formal logic is about testing True vs. False. `if` in python and formal logic receives a statement. The statement must be evaluatable to True or False, but does not have to be True or False themselves. It

Re: question of style

2009-07-05 Thread Steven D'Aprano
On Sun, 05 Jul 2009 06:12:25 -0700, Paul Rubin wrote: There are three natural approaches to (say) re.search() for dealing with failure: (1) return a sentinel value like None; (2) return a matchobject which tests False; (3) raise an exception. 4. Have re.search return a bool and possible

Re: question of style

2009-07-05 Thread Lie Ryan
Steven D'Aprano wrote: On Sun, 05 Jul 2009 11:37:49 +, Lie Ryan wrote: Neither python's `if` nor `if` in formal logic is about testing True vs. False. `if` in python and formal logic receives a statement. The statement must be evaluatable to True or False, but does not have to be True

Re: question of style

2009-07-05 Thread Terry Reedy
Paul Rubin wrote: I don't know what a furphy is, but I don't accept that somethingness vs. nothingness is the same distinction as truth vs falsehood. True and False are values in a specific datatype (namely bool), not abstract qualities of arbitrary data structures. The idea that the if

Re: question of style

2009-07-05 Thread Paul Rubin
Steven D'Aprano st...@remove-this-cybersource.com.au writes: but I don't accept that somethingness vs. nothingness is the same distinction as truth vs falsehood. It's the distinction used by Python since the dawn of time. Python only grew a bool type a few versions back. That's true,

Re: question of style

2009-07-05 Thread Paul Rubin
Simon Forman sajmik...@gmail.com writes: BTW, Paul, kind of a tangent: I reimplemented the same algorithm but using tuples instead of instances (and empty tuples for NULL values.) I was trying to mess around in the space you seemed to indicate existed, i.e. a better implementation using other

Re: question of style

2009-07-04 Thread upwestdon
On Jul 2, 1:23 pm, Simon Forman sajmik...@gmail.com wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first one is easier [for me anyway] to read and understand, but

Re: question of style

2009-07-04 Thread Scott David Daniels
upwestdon wrote: if not (self.higher and self.lower): return self.higher or self.lower self.lower = 0 self.higher = 123 ??? More than just None is False -- http://mail.python.org/mailman/listinfo/python-list

Re: question of style

2009-07-04 Thread Paul Rubin
a...@pythoncraft.com (Aahz) writes: AFAICT, in order for Maybe and Option to work, you need to have some kind of static typing system. Am I missing something? I'm not sure. Maybe there could be some kind of syntactic support in a dynamic language (not that I'm suggesting adding that to

Re: Re: question of style

2009-07-04 Thread Dave Angel
upwestdon wrote: On Jul 2, 1:23 pm, Simon Forman sajmik...@gmail.com wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first one is easier [for me anyway] to read and

Re: question of style

2009-07-04 Thread Simon Forman
On Jul 4, 2:03 am, upwestdon upwest...@gmail.com wrote: On Jul 2, 1:23 pm, Simon Forman sajmik...@gmail.com wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first

Re: question of style

2009-07-04 Thread Aahz
In article 7xws6oa862@ruckus.brouhaha.com, Paul Rubin http://phr...@nospam.invalid wrote: In many cases it later turns out that list really was the natural representation and it ends up growing additional potential elements. I saw some article about database design recently that claimed as a

Re: question of style

2009-07-04 Thread Paul Rubin
Simon Forman sajmik...@gmail.com writes: if not (self.higher and self.lower):     return self.higher or self.lower That would work too in this case, both higher and lower are expected to be either None or an object (that doesn't override the default all- objects-are-true rule.) -1.

Re: question of style

2009-07-04 Thread Simon Forman
On Jul 4, 2:10 pm, Paul Rubin http://phr...@nospam.invalid wrote: Simon Forman sajmik...@gmail.com writes: if not (self.higher and self.lower):     return self.higher or self.lower That would work too in this case, both higher and lower are expected to be either None or an object (that

Re: question of style

2009-07-04 Thread Steven D'Aprano
On Sat, 04 Jul 2009 11:10:48 -0700, Paul Rubin wrote: Anyway, Python's overloading of bool(...) is yet another misfeature and although it's convenient, the explicit is better than implicit principle indicates to avoid that sort of trick. Overloading of bool()? I don't understand what that

Re: question of style

2009-07-03 Thread Lie Ryan
Tim Harig wrote: Speaking only to the style issue, when I've wanted to do something like that, I find: if self.higher is None is self.lower: more readable, by making clear they are both being compared to a constant, rather than compared to each other. By comparing them to *any*

Re: question of style

2009-07-03 Thread Lie Ryan
Simon Forman wrote: On Jul 2, 3:57 pm, Scott David Daniels scott.dani...@acm.org wrote: Duncan Booth wrote: Simon Forman sajmik...@gmail.com wrote: ... if self.higher is self.lower is None: return ... As a matter of style however I wouldn't use the shorthand to run two 'is' comparisons

Re: question of style

2009-07-03 Thread Lie Ryan
Paul Rubin wrote: Generally, having a special value like None to denote a missing datum was considered standard practice a few decades ago, I guess in python, None as the missing datum idiom is still quite prevalent: def cat_list(a=None, b=None): # poor man's list concatenation if a

Re: question of style

2009-07-03 Thread Lie Ryan
Lie Ryan wrote: Tim Harig wrote: Speaking only to the style issue, when I've wanted to do something like that, I find: if self.higher is None is self.lower: more readable, by making clear they are both being compared to a constant, rather than compared to each other. By comparing

Re: question of style

2009-07-03 Thread Lie Ryan
Paul Rubin wrote: Tim Harig user...@ilthio.net writes: That being the case, it might be a good idea either to handle the situation and raise an exception or add: assert self.lower = self.higher That way an exception will be raised if there is an error somewhere else in the code rather then

Re: question of style

2009-07-03 Thread Lie Ryan
Simon Forman wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? If self is an object (and it must have been), it would be preferrable to set self.higher and self.lower to a known

Re: question of style

2009-07-03 Thread Paul Rubin
Lie Ryan lie.1...@gmail.com writes: I guess in python, None as the missing datum idiom is still quite prevalent: Well, sometimes there is no way around it, but: def cat_list(a=None, b=None): # poor man's list concatenation if a is None and b is None: return [] if a is None:

Re: question of style

2009-07-03 Thread Steven D'Aprano
On Thu, 02 Jul 2009 22:14:18 +, Tim Harig wrote: On 2009-07-02, Paul Rubin http wrote: Tim Harig user...@ilthio.net writes: If lower is 5 and higher is 3, then it returns 3 because 3 != None in the first if. Sorry, the presumption was that lower = higher, i.e. the comparison had already

Re: question of style

2009-07-03 Thread Tim Harig
On 2009-07-03, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Thu, 02 Jul 2009 22:14:18 +, Tim Harig wrote: On 2009-07-02, Paul Rubin http wrote: Tim Harig user...@ilthio.net writes: If lower is 5 and higher is 3, then it returns 3 because 3 != None in the first if.

Re: question of style

2009-07-03 Thread Jean-Michel Pichavant
Simon Forman wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first one is easier [for me anyway] to read and understand, but Easier for you but not for those who are

Re: question of style

2009-07-03 Thread Simon Forman
On Jul 3, 2:09 am, Lie Ryan lie.1...@gmail.com wrote: Simon Forman wrote: On Jul 2, 3:57 pm, Scott David Daniels scott.dani...@acm.org wrote: Duncan Booth wrote: Simon Forman sajmik...@gmail.com wrote: ... if self.higher is self.lower is None: return ... As a matter of style however

Re: question of style

2009-07-03 Thread Simon Forman
On Jul 3, 12:56 am, Paul Rubin http://phr...@nospam.invalid wrote: Simon Forman sajmik...@gmail.com writes: Yes, but the concept of null pointers is considered kludgy these days. Seriously? kludgy?  (I really AM getting old.)  

Re: question of style

2009-07-03 Thread Paul Rubin
Simon Forman sajmik...@gmail.com writes: ...stick to the principle: NULL is wrong because it causes horrible and tricky mistakes which appear even after the program was tested thoroughly. You cannot introduce NULL into the language and tell the programmer to be careful about it. The programmer

Re: question of style

2009-07-03 Thread John Yeung
On Jul 3, 4:50 pm, Paul Rubin http://phr...@nospam.invalid wrote: I wouldn't say Python's None is terrible, but the programming style in which None is used as a marker for absent value is genuinely a source of bugs, requiring care when used.  Often it's easy to just avoid it and all the bugs

Re: question of style

2009-07-03 Thread Steven D'Aprano
On Fri, 03 Jul 2009 13:50:12 -0700, Paul Rubin wrote: I wouldn't say Python's None is terrible, but the programming style in which None is used as a marker for absent value is genuinely a source of bugs, requiring care when used. Often it's easy to just avoid it and all the bugs that come

Re: question of style

2009-07-03 Thread Aahz
In article 7xhbxtjxtn@ruckus.brouhaha.com, Paul Rubin http://phr...@nospam.invalid wrote: Simon Forman sajmik...@gmail.com writes: (I like Haskell's Maybe, but saying A is better than B doesn't imply that B is therefore terrible.) I wouldn't say Python's None is terrible, but the

question of style

2009-07-02 Thread Simon Forman
Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first one is easier [for me anyway] to read and understand, but slightly less efficient, while the second is [marginally] harder to

Re: question of style

2009-07-02 Thread Duncan Booth
Simon Forman sajmik...@gmail.com wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first one is easier [for me anyway] to read and understand, but slightly less efficient,

Re: question of style

2009-07-02 Thread Simon Forman
On Jul 2, 1:44 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: Simon Forman sajmik...@gmail.com wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first one is

Re: question of style

2009-07-02 Thread Kee Nethery
the fact that you felt compelled to explain the one minor point in the first snippet tells me that the second snippet does not need that explanation and will be easier for someone (like you for example) to maintain in the future. Second snippet would be my choice. Kee Nethery On Jul 2,

Re: question of style

2009-07-02 Thread Terry Reedy
Simon Forman wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first one is easier [for me anyway] to read and understand, but slightly less efficient, while the second is

Re: question of style

2009-07-02 Thread Paul Rubin
Simon Forman sajmik...@gmail.com writes: These two snippets of code are functionally identical. Which would you use and why? Both are terrible. I can't tell what you're really trying to do. As Terry Reedy points out, the case where self.higher and self.lower are both not None is not handled.

Re: question of style

2009-07-02 Thread Tim Harig
On 2009-07-02, Duncan Booth duncan.bo...@invalid.invalid wrote: so apart from reversing the order of the comparisons once you've dropped the redundant test it is the same as the first one. I try to evaluate what you have given regardless of what Booth pointed out. So, I will only evaluate the

Re: question of style

2009-07-02 Thread Scott David Daniels
Duncan Booth wrote: Simon Forman sajmik...@gmail.com wrote: ... if self.higher is self.lower is None: return ... As a matter of style however I wouldn't use the shorthand to run two 'is' comparisons together, I'd write that out in full if it was actually needed here. Speaking only to the

Re: question of style

2009-07-02 Thread Paul Rubin
Simon Forman sajmik...@gmail.com writes: ## Second snippet if self.higher is None: if self.lower is None: return return self.lower if self.lower is None: return self.higher What do you think? I'm not sure, but my guess is that what you are really trying to write is

Re: question of style

2009-07-02 Thread Paul Rubin
Tim Harig user...@ilthio.net writes: If lower is 5 and higher is 3, then it returns 3 because 3 != None in the first if. Sorry, the presumption was that lower = higher, i.e. the comparison had already been made and the invariant was enforced by the class constructor. The comment should have

Re: question of style

2009-07-02 Thread Tim Harig
On 2009-07-02, Paul Rubin http wrote: Tim Harig user...@ilthio.net writes: If lower is 5 and higher is 3, then it returns 3 because 3 != None in the first if. Sorry, the presumption was that lower = higher, i.e. the comparison had already been made and the invariant was enforced by the class

Re: question of style

2009-07-02 Thread Paul Rubin
Tim Harig user...@ilthio.net writes: That being the case, it might be a good idea either to handle the situation and raise an exception or add: assert self.lower = self.higher That way an exception will be raised if there is an error somewhere else in the code rather then silently passing

Re: question of style

2009-07-02 Thread Tim Harig
On 2009-07-02, Paul Rubin http wrote: Tim Harig user...@ilthio.net writes: That being the case, it might be a good idea either to handle the situation and raise an exception or add: assert self.lower = self.higher That way an exception will be raised if there is an error somewhere else in

Re: question of style

2009-07-02 Thread Tim Harig
On 2009-07-02, Tim Harig user...@ilthio.net wrote: Sorry, it worked under 2.5: [SNIP] None seems to have been evaluated less then any integer. The same isn't true under 3.0: None seem to have been evaluated less then any non-negative integer including 0. --

Re: question of style

2009-07-02 Thread Simon Forman
On Jul 2, 4:08 pm, Erik Max Francis m...@alcyone.com wrote: Simon Forman wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first one is easier [for me anyway] to read

Re: question of style

2009-07-02 Thread Simon Forman
On Jul 2, 3:57 pm, Scott David Daniels scott.dani...@acm.org wrote: Duncan Booth wrote: Simon Forman sajmik...@gmail.com wrote: ... if self.higher is self.lower is None: return ... As a matter of style however I wouldn't use the shorthand to run two 'is' comparisons together, I'd

Re: question of style

2009-07-02 Thread Paul Rubin
Tim Harig user...@ilthio.net writes: Well, that assert is not right because you have to handle the case where one of the values is None... Sorry, it worked under 2.5: Well, it didn't crash under 2.5. Whether the result was correct is a different question. None seems to have been

Re: question of style

2009-07-02 Thread Paul Rubin
Simon Forman sajmik...@gmail.com writes: This code is part of a delete() method for a binary tree implementation. None is used to simulate a NULL pointer. In the case where both children are non-None the code goes on to handle that. None is a unitary or singleton value, so is is the right

Re: question of style

2009-07-02 Thread Simon Forman
On Jul 2, 9:30 pm, Paul Rubin http://phr...@nospam.invalid wrote: Simon Forman sajmik...@gmail.com writes: This code is part of a delete() method for a binary tree implementation. None is used to simulate a NULL pointer. In the case where both children are non-None the code goes on to

Re: question of style

2009-07-02 Thread Paul Rubin
Simon Forman sajmik...@gmail.com writes: Yes, but the concept of null pointers is considered kludgy these days. Seriously? kludgy? (I really AM getting old.) http://math.andrej.com/2009/04/11/on-programming-language-design/ discusses the issue (scroll down to Undefined values section).