On 23/03/2016 23:00, Chris Angelico wrote:
On Thu, Mar 24, 2016 at 9:38 AM, Andrew Barnert
wrote: On Mar 23, 2016, at 15:01, Chris Angelico
wrote: On Thu, Mar 24, 2016 at 8:46 AM, Andrew Barnert
wrote: The advantage of having a small set of builtins is that you know the entire set of builtins. Python 3.6 has len(dir(builtins))==150, which is hardly small. Even removing the ones that don't begin with a lower-case letter (which removes a small number of special names like __package__, and a large number of exception classes) leaves 72. Can you name them all?
Can you name all 25000 words of English that you know?
There are 68 builtins listed in a nice table at the top of the builtin functions chapter in the docs. Take a look at that table. They're all (except maybe format and iter[1]) functions[2] that you can immediately recognize them when reading them, and recall when they're relevant to code you're writing, including know exactly what their interface is and what they do. If you see "any()" or "int()" in code, you don't need to turn to the docs to look up what it does. If you need to convert something to a debug string representation, you know to call "repr()". The fact that you might leave out "any", "int", or "repr" in a pop quiz demanding that you list all 68 of them in alphabetical order doesn't mean you don't know them.
You certainly can't say the same is true for all functions and methods in the stdlib.
Fair enough, naming them all is a poor definition of "know". But the flip side (knowing what one means when you meet it) is also a poor definition. The real trick is knowing, when you're faced with a problem, what the solution is; and while most people here will be able to do that, I'm not sure that every Python programmer can. Some builtins are well known, like int and len; others, not so much - zip, hash, divmod. And then there are some (compile, bytearray, callable) that, if they were elsewhere in the stdlib, would barely change people's code. How many non-experts know exactly which function decorators are builtins and which are imported from functools? If you have to look them up, (a) there's not a lot of difference between built-in and stdlib, and (b) the builtins are already a bit crowded.
My conclusion: itertools.chain is just as discoverable as builtins.chain, so the only real benefit would be playing around at the interactive prompt, which you can improve on with an auto script. -0.5 on making chain a builtin.
ChrisA
My conclusion is RTFM. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence