Ruby parens-free function calls [was Re: Accessing parent objects]

Chris Angelico rosuav at gmail.com
Tue Mar 27 12:35:02 EDT 2018


On Wed, Mar 28, 2018 at 3:28 AM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> On Tuesday, March 27, 2018 at 8:46:54 AM UTC-5, Chris Angelico wrote:
> [...]
>> Cool, so Greg was right: you can't get a reference to a
>> method or function. You need magic to simulate it.
>
> Since when did utilizing a method to request a specific
> value become some sort of magic?
>
> Do you consider this to be magic?
>
>     os.lstdir('C:\\')

That requests the "lstdir" method of the "os" object, most likely a
module. And then it calls that. Nope, not magic. When you use the name
"os", you get the object referenced by that name. When you put a dot
after an object, you get an attribute of that object. When you put
parentheses after an object, you call it. Why would it be magic?

> What about this?
>
>     ''.join(map(chr, [109, 101, 97, 116, 32, 104, 101, 97, 100]))
>

You have a string literal, and you get a method off that object.
Etcetera. Why are you suggesting that this is magic?

> Even though i prefer Python's way better, the implicit
> return of Python function references is far more "magical"
> than making an explicit call to a method will ever be.
>
> Python Zen Says: "Explicit is better than implicit"

Yep, one of the most misunderstood lines in the zen. "Explicit" means
"stuff I like", and "implicit" means "stuff I don't like". Or at
least, that's how I see this used.

ChrisA



More information about the Python-list mailing list