Re:Imdb-pie – Python IMDB client using the IMDB json web ser...
by StavrosK on Monday January 21, 2013 @10:18AM
(#5091818)
I will agree with everything but the first one. I prefer functions that claim to return True or False to return precisely that, rather than Truthy/Falsy values. Otherwise, if I want to do "if func() is other_val" where "other_val" is True or False, it will fail.
[ Parent
| on HN ]
Re:Imdb-pie – Python IMDB client using the IMDB json web ser...
by JulianWasTaken on Monday January 21, 2013 @10:25AM
(#5091844)
Yes, you should never do ‛foo is True either :).
Also, here the point is that <some stuff> was a boolean expression already.
Re:Imdb-pie – Python IMDB client using the IMDB json web ser...
by StavrosK on Monday January 21, 2013 @10:27AM
(#5091854)
Well, how else would you check if a return value matches a True/False variable? if <var> and <retval>? That's horrible!
Re:Imdb-pie – Python IMDB client using the IMDB json web ser...
by VBprogrammer on Monday January 21, 2013 @10:51AM
(#5091951)
Obviously its a matter of personal preference but PEP 8 (official Python style guide) disagrees with you.
Re:Imdb-pie – Python IMDB client using the IMDB json web ser...
by StavrosK on Monday January 21, 2013 @10:55AM
(#5091973)
PEP 8 only mentions truth checks, it doesn't mention if functions' return values should be True or the truthy value. Personally, I find it very unclean to have your function return half a string, or some unrelated int or something similar when your function is called, e.g. "is_member()".
Re:Imdb-pie – Python IMDB client using the IMDB json web ser...
by VBprogrammer on Monday January 21, 2013 @11:08AM
(#5092028)
Ah, sorry think we are talking about different things. I thought you where complaining about:
if [something]:
VS if [something] is True:
In the case I think you are talking about I would probably agree with you that returning some non-boolean is less clean, though I would probably just use the equality operator to force a boolean result: def foo(i):
return i == 0
Re:Imdb-pie – Python IMDB client using the IMDB json web ser...
by StavrosK on Monday January 21, 2013 @11:11AM
(#5092044)
Yep, we agree exactly. I just don't like "return i", and would rather do "return i is True" or something.