Need help in understanding a python code

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Nov 16 13:04:53 CET 2008


On Sun, 16 Nov 2008 02:41:03 -0800, John Machin wrote:

> On Nov 16, 9:31 pm, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
>> On Sun, 16 Nov 2008 01:50:16 -0800, John Machin wrote:
>> > > def A(w, v, i,j):
>> > >     if i == 0 or j == 0: return 0
>> > >     if w[i-1] > j:  return A(w, v, i-1, j) if w[i-1] <= j: return
>> > >     max(A(w,v, i-1, j), v[i-1] +
>> > >       A(w,v, i-1, j - w[i-1]))
>> >> I am reading this blog
>>
>> >>http://20bits.com/articles/introduction-to-dynamic-programming/
>>
>> > I suggest that you don't bother reading a blog written by somebody
>> > who (presumably consciously) keyed in that "if w[i-1] <= j: " above.
>>
>> That is a translation of standard terminology for a hybrid function.
>> Mathematics doesn't have an "else", so you write hybrid functions by
>> enumerating each branch as an if.
> 
> An else is not required.
>     if w[i-1] > j:
>        return A(w, v, i-1, j)
>     return max(A(w,v, i-1, j), v[i-1] + A(w,v, i-1, j - w[i-1]))

Which is also not valid terminology for hybrid functions.


>> While it's not especially good Python technique, it's a perfectly
>> idiomatic mathematical expression, and shouldn't be the basis for
>> dismissing an entire blog.
> 
> He's meant to be writing Python code, not mathematical expressions.

And he's written Python code. Perfectly valid Python code. Just because 
it is not what you consider to be idiomatic Python code isn't a good 
reason to dismiss his entire blog. 

What you've done is rather like me saying that because you failed to use 
a colon after "required", and therefore haven't written what *I* consider 
good English style, not only is your specific post best avoided, but 
*all* your posts should be avoided. I trust you understand the logical 
fallacy I would be making, which you have already made.

http://en.wikipedia.org/wiki/Style_over_substance_fallacy



-- 
Steven
and now begins the arguments as to whether it is a fallacy, and if so, if 
it is the fallacy I have said it is...




More information about the Python-list mailing list