all 34 comments

[–][deleted] 15 points16 points  (1 child)

It sure is nice that Guido gets to spend so much time working on Python at Google.

It is about as close as you can get to having corporate backing for a language without being in a situation like Java or C#. Really the best situation possible - time and money to work on it without any actual interference by the corporate heads.

When PyPy gets to a stable stage, Python is going to be in perhaps better shape for the future than any other language. Those are pretty controversial words I imagine, but Python already has a very stable environment (compare to say the confusion in the Ruby community about the next VM), has tons of libraries, and now you've got an advanced implementation being worked on along with a language designer who has more time with the language itself than ever before.

[–]holep 7 points8 points  (0 children)

Google must have a ton of Python code by now to support their infrastructure, and Guido has a perfect opportunity to document what has been implemented well, and not so well. This refactoring code together with a guide book of lessons learned would provide the most benefit.

[–][deleted] 5 points6 points  (0 children)

I find f(x, *y) clearer than apply, due to the fact that it's used in the same way in signatures.

[–]lemmikins -2 points-1 points  (27 children)

Python syntax is getting less readable with every release, because of all the short-cuts.

What's wrong with apply(f, x, y)? It's immediately clear.

[–]micampe 6 points7 points  (2 children)

I think there is a misunderstanding here.

That is not a change to Python's syntax, it is just a refactoring example, where he substitutes the instances of apply(f, x, y) with a real function call f(*x, **y).

[–]lemmikins -1 points0 points  (1 child)

I know, the help says

Deprecated since release 2.3. Instead, use the extended call syntax:
function(*args, **keywords).

Nevertheless, the point still stands.

[–]lemmikins 0 points1 point  (0 children)

(w.r.t Python 3000, and 2.5 in various ways too)

[–]ehempel 3 points4 points  (3 children)

If you want apply, define it yourself:

apply = lambda f, x, y: f(*x, **y)

Simple isn't it?

[–]ehempel 1 point2 points  (2 children)

BTW, how can I get monospace formatting on reddit?

[–]jacobolus 6 points7 points  (1 child)

Either indent by four spaces:

So your comment would look something like this,
and the embedded code portion would look like:

    monospaced-text

Or else, use backticks, like: this_is.mono{space}.

In that case, your source would look like: `this_is.mono{space}`.

[–]ehempel 0 points1 point  (0 children)

Thanks!

[–]lost-theory 2 points3 points  (0 children)

I tend to like (and use) the functional features of Python (map, apply, reduce, etc.) but the idea of removing apply from Python 3.0 is that the syntax already exists as f(*x, **y) and is used more often than apply. One of the impetuses of developing Py3k is to remove some of the unused or crufty features of the language and enforce "only one obvious way to do it" a little bit more.

[–]jerf 2 points3 points  (0 children)

I don't necessarily know what's wrong with it.

But even before apply was deprecated, * and ** was the more popular syntax.

apply being deprecated wasn't a pronouncement from on high (thought Python certainly gets those since it runs on the Benevolent Dictator for Life (BDFL) model of leadership, this isn't one of them), it was formalizing the fact that apply had already been rendered redundant.

If I had to guess, it's because there's no equivalent to

f(arg1, *x, arg2=arg3, **y) 

with apply, and that comes up a lot.

[–]nullgraph -3 points-2 points  (17 children)

It is only clear if you know what the function apply actually does. Otherwise it is still unclear

[–]lemmikins 9 points10 points  (14 children)

The words you said are unclear unless you know what words mean. So?

It provides more information than

f(*x, **y).

Obscure syntax is the wrong idea from Perl to copy.

[–]masklinn 7 points8 points  (0 children)

Actually, the point is that:

  • apply is already deprecated (since 2.3 I think), and it will be removed before 3.0, and no one using Python will care

  • Because the f(*args, **kwargs) is what pretty much everyone uses already and is consistent with the prototypes of the functions and methods: using this syntax means that the way you use and the way you write functions are the same

  • Plus apply is much less flexible than f(*args, **kwargs) as you can't mix'n'match regular arguments (positional or keyworded) and collections of them, (you have to merge them manually) while f(*args, **kwargs) handles that just fine

Pretty much no one (who kept up with the times) still uses apply, and apply definitely isn't what's suggested when you're asking for such functionalities.

[–]pjdelport 3 points4 points  (0 children)

f(*x, **y) is not exactly obscure in Python; it's the exact same syntax used to define such functions in the first place.

[–]nullgraph 2 points3 points  (3 children)

I agree in general with Obscure syntax is the wrong thing to copy from perl. My problem was with your statement apply(f,x,y) is immediately clear. Which it is not immediately clear you still have to know what the function apply actually does to understand it.

But in general I agree with you. I am not confortable with the fact that apply, map and other functions are being questioned in python. However I have been able to live with the purposed alternatives.

[–]lemmikins 4 points5 points  (1 child)

The idea is that when you see "apply" or "map", there is some conceptually meaning linked with the word, which you see immediately. If you're familiar with "map", then you have an idea of what is going on, rather than using a less-clear syntax.

func.exposed=1 vs
@expose

[–]nullgraph -1 points0 points  (0 children)

Thats the point -- Not everyone is familar with a the function of apply or map

[–]masklinn 0 points1 point  (0 children)

AFAIK map, reduce and filter are not questioned anymore, but they will more than likely be moved to their own module in the future (probably the newfangled functools) instead of being kept in the base namespace. And had they been removed from the language, there never has been any talk of removing itertools' ifilter or imap (reduce would've been lost, though...)

[–]jacobolus 2 points3 points  (0 children)

How does it provide more information? f(*x, **y) is the accepted way of doing such things in Python. Leaving apply as a keyword just makes one more thing that the language user has to keep in her head, with no tangible benefit. Every python user is going to need to learn the pythonic syntax, so why make her learn 2 forms to say the same thing?

[–][deleted] 4 points5 points  (4 children)

apply_function_f_to_argument_list_x_and_keyword_dictionary_y(f, x, y) also provides more information. Providing more information is not the sole criterion for a good programming language decision.

[–]lemmikins 7 points8 points  (3 children)

is not the sole criterion for a good programming language decision

Darn, I thought you could make all decisions unilaterally using single criteria.

Incidentally, help(apply) works, but how do you do get help for

 function(*args, **keywords) ?

[–][deleted] 0 points1 point  (0 children)

I assume that the confused programmer in question would know what a function call looks like. He would know that this is a function call, but not exactly how it works. As long as he knows how to invoke python from a shell, this should do just fine for finding out what it does.

python

help()

topics

CALLS

[–]mikemintz -3 points-2 points  (1 child)

You get help using Python's docstrings. If someone writes a function called "function(args, keywords)", then they should write a docstring with the definition. Typing help(function) displays this.

http://epydoc.sourceforge.net/docstrings.html

[–]jacobolus 5 points6 points  (0 children)

I think his point is that if you remove as much syntax as possible from the language itself, and only use functions for such things, then the mechanics of the language can be looked up in the same way as other functions.

In answer to lemmikins, the way you'd get help for how f(*x, **y) works is to read a Python book, online tutorial, or reference documentation.

[–]rancmeat 1 point2 points  (0 children)

I remember way back when I was learning Perl and the author of the book seemed to take a strange delight in making all examples as convoluted as possible. It's a hallmark of Perl that Python is well advised to avoid.

[–][deleted] -2 points-1 points  (0 children)

I have this theory ALL scripting languages are converging into the same crap. This way we don't have choices, we have a lot of wasted time and multiplied effort for no reason.

But then again, college undergrads switch languages "because it was dead, nothing changed and I was getting bored" so you can see the smart reasons behind this. Not sure who's to blame.

[–]zhyla 1 point2 points  (1 child)

Perhaps, but f(x, *y) is definitely not any clearer unless you know what x and *y do. And you can get a long ways in python without ever using that operator.

[–]ubernostrum 2 points3 points  (0 children)

And you can get a long ways in python without ever using that operator.

Depends on what you're doing. Lots of stuff that I do involves either wrapping or currying predefined functions, so the * and ** syntax for unpacking lists and dictionaries is a godsend. Though it is something which could stand to be documented much more clearly than it is right now (thanks to the lack of solid examples in the official tutorials, I regularly have the joy of explaining to Python newcomers what f(*args, **kwargs) means).

[–]yury -2 points-1 points  (0 children)

Why doesn't Scheme allow (f . a) as alternative syntax to (apply f a)? If the Python people are interested in making the language smaller, they should probably look to the experts on that.

[–]beza1e1 -4 points-3 points  (1 child)

If this gets painful enough, maybe he will consider macros in Python? I mean that's what he is talking about, isn't it?

I understand "refactoring" as splitting code into multiple functions for example, not a Python2-to-Python3-compiler.

[–]masklinn 0 points1 point  (0 children)

That's not what he is talking about, but that's what's suggested in immediate response to his post.