Bools and explicitness [was Re: PyWart: The problem with "print"]

Rick Johnson rantingrickjohnson at gmail.com
Thu Jun 6 12:24:57 EDT 2013


On Wednesday, June 5, 2013 6:18:13 PM UTC-5, Michael Torrie wrote:
> On 06/05/2013 12:11 AM, Russ P. wrote:
> > But then, what would you expect of a language that allows you to
> > write
> > x = 1 
> > x = "Hello"
> > It's all loosey goosey -- which is fine for many applications but
> > certainly not for critical ones.
> This comment shows me that you don't understand the difference between
> names, objects, and variables.  May sound like a minor quibble, but
> there're actually major differences between binding names to objects
> (which is what python does) and variables (which is what languages like
> C have).  It's very clear Rick does not have an understanding of this
> either.

Just because someone does not "prefer" this or that aspect of Python, does not mean they don't understand it. I understand "implicit conversion to Boolean" just fine, however, i don't like it. Actually, i hate it! I think it's foolish. It was invented by people who rather save a few keystrokes at the cost writing cryptic code. There are many good reasons for saving keystrokes, implicit conversion to Boolean is NOT one of them. 

I make the same argument for "return". Some languages allow implicit return values from functions/methods. When writing a function with Ruby, the return statement is optional:

## START RUBY CODE ##

def foo:
    "implicit return"
end

rb> puts foo
"implicit return"

## END RUBY CODE ##

This is one area where Python shines! 

In Python, if you fail to use the return statement, then Python will return None, NOT some some value that just happens to be the last line executed in the function -- Ruby breaks the law of least astonishment.

The point is we must balance our selfish need to save keystrokes against the need of a reader to QUICKLY understand what he is reading. Python's "explicit return statement" satisfies both requirements, whereas, the optional return value of Ruby does not. We don't want to overly implicit, or overly explicit (as in the nightmare of "public static void foo", which is overkill (at least for a language as high level as Python)). 




More information about the Python-list mailing list