13 ms·
Recharging the Python standard library
- mattdeboard 13y agoWho is this article for?
- mjolk 13y agoThe author.
- lmm 13y agoNow that we've (mostly) figured out how to do dependency management, a large standard library has become more of a liability than an asset. As a scala fan I hope we can move more library-type functionality out into, well, libraries, allowing that to evolve on its own schedule, and keeping the core language small.
- riffraff 13y agoI am not sure we've figured out how to do dependency management, on any platform. E.g. even in scala land I got the feeling ivy/maven dependency management weren't universally loved, but maybe I am wrong?
- Oculus 13y agoI think we're getting pretty close to figure it out in the world of node with npm.
- riffraff 13y agoplease correct me if I'm wrong because I just had a cursory look at NPM some time ago, but I believe * it doesn't have virtual packages (in the sense, "'email-sender' is a package that provides a sendmail() function") * it hardcodes a max of two dependency sets: runtime and dev. This maybe be better than a freeform Gemfile or a 6-scopes pom.xml but it seems quite arbitrary
- themckman 13y agoA while back, while I was a doing Ruby, I remember a discussion that came up regarding moving some of/all of (can't remember) the standard library to Gems so that, as you say, they could "evolve on their own schedule". It'd be interesting if standard libraries of languages adopted this approach. A release of a language would then become the interpreter/compiler and set of vendored libraries deemed the standard library. Then, in projects, if say, the path module gets updated with new features, I can include that version and not wait for the next major/minor release of the language to get new features/bug fixes.
- troygoode 13y agonode.js follows this pattern relatively strictly (the standard library is quite small, with everything else pushed into userland)
- Chris_Newton 13y agoThe term “standard library” has a second interpretation that is increasingly relevant in modern programming: as well as meaning “the [one true] standard library”, it could also mean “the library of standards”. It doesn’t necessarily have to provide its own tools. It can also define conventions and frameworks that establish a baseline for interoperability that everyone else’s tools can work with. I don’t believe it’s realistic to create a standardised toolbox when every new language come along and expect everything in it to still be a good way of doing things ten years later, as requirements change and new ideas come along. This is probably why so many languages today have at least a de facto standard place where you get other libraries when you need them: PyPI, CPAN, Boost, etc. On the other hand, there are many recurring themes that appear in those libraries, particularly in the interface they offer and their overall design: basic data types and data structures, application-specific concepts like windows and database connections and file formats, architectural tools like publish-subscribe mechanics and test hooks. Standardising these common ideas, so it’s as easy as possible to connect up libraries from different sources or to replace one library with another, offers many benefits in efficiency and maintainability for a programming language’s ecosystem as a whole. We already see examples of this being done: many languages have a somewhat standardised interface for connecting to SQL-based database engines, for example. We also see some unfortunate examples where it wasn’t done quickly enough, such as the myriad string types everyone defined in C++ because there was no standard type for so long. I suspect the most successful programming languages of tomorrow may not have anything like as many tools available “out of the box” as Java and Python and C# do today. However, if I were a betting man, I’d wager they will all provide solid foundations for managing third party libraries and much better frameworks and conventions for interoperability between those libraries.
- stevenleeg 13y agoI get the feeling that overloading the division operator for paths is a really bad idea for clarity... To someone who is unfamiliar with the path.py package, it looks like you're trying to divide some sort of object by a string. Not to mention the fact that, in his code, he aliased path to p, so it's even more confusing as to what is going on there.
- viraptor 13y agoYeah, not the best example I think. This code is not bad at all: filepath = os.path.join('.', 'test_dirs) os.makedirs(filepath) with open(os.path.join(filepath, 'test.txt'), 'w') as f: f.write('hello world') And it's actually obvious what happens with the file handle after write. I'm not sure if it's still open or not at the end of his example really. I wouldn't be surprised by his example in ruby code (overloading with magic functionality), but in python that just looks weird...
- revelation 13y agoI guess its a terrible thing for a dynamic language like Python. boost::filesystem::path has been overloading the '/' operator all along.
- herge 13y agoIt does make the code a lot clearer to read. There are a lot of other python packages that overload specific operators/magic functions to aid readability. For example, numpy arrays overload the slice operator to great effect. Also, on the same topic, what about using the '+' operator with strings and lists/tuples for concatenation? Or the '|', '&' and '^' operator for sets (which I have to admit I never use because I can never remember which is which)?
- falcolas 13y ago> It does make the code a lot clearer to read. If, and only if, you're familiar with how the path library works. I had to shift mental contexts away from python and into shell to understand that it was a "shortcut" for os.path.join(). The division operator is not typically associated with path joining in programming languages. Frankly, it's not really offering any greater level of abstraction for paths; just shortcuts. You still have to call makedirs, open, write, etc. I don't find the minute improvements to os.path.join that terribly compelling.
- dochtman 13y agoI'll just leave these here: http://www.python.org/dev/peps/pep-0428/ http://www.python.org/dev/peps/pep-0428/ http://www.python.org/dev/peps/pep-0431/ http://www.python.org/dev/peps/pep-0431/
- deleted 13y ago[deleted]
- raymondh 13y agoSummary: The author wishes that the third-party requests module were part of the Python standard library (ignoring the wishes of the person who wrote the requests module). The title is link bait. The "batteries" work fine - some are venerable, but they are well tested and documented. The author ignores stellar parts of the standard library such as: collections, itertools, contextlib, functools, itertools, sqlite3, hashlib, struct, json, elementtree, etc. Essentially, the author is bashing the entire standard library because the urllib modules are somewhat dated. IMO, The rant is not worthy of being on the front page of Hacker News.
- d23 13y agoHmm, I was going to list additional standard libraries that I use on a regular basis to "prove" the author wrong, but I could only come up with two (in addition to your list): csv & re. Still, the only thing I use with any frequency that is an outright replacement for standard library functionality is requests and beautifulsoup. Well, if you don't include ipython, which is an absolute necessity.
- jdost 13y agoI also like using argparse. Nice utility library to "power up" helpful scripts.
- vezzy-fnord 13y agoArgument parsing is an essential utility and part of the standard library in all major programming languages, though. Dating back to getopt becoming a standard in C (or earlier?) Or do you find Python's argument parsing to be especially notable for some reason?
- RyanMcGreal 13y agoFor a language whose motto is "There should be one - and preferably only one - obvious way to do it", Python has at least four ways to handle command line arguments out-of-the-box: * sys.argv * argparse * optparse * getopt There are, of course, additional third party modules (like opster) that also handle arguments.
- mattip 13y agoSome of us use python as a rapid prototyping language before writing "real" code in c or even (horrors) c++ for performance. This is what makes ctypes so popular, python becomes the glue between calls to well tested low level functionality. So the place of the std libraries in this paradigm is to replace the c-like functionality. In c mkdir does not return the directory name, so os.mkdir does not either, allowing translation of the final prototype to c where it becomes another well tested tool in the next evolution of the application. I can appreciate the need for higher level libraries in the std, but not at the expense of os, sys, and other 'dead' modules.
- andrewcooke 13y agothe article mentions pytz, but that's pretty low-level. i wrote a wrapper, called simple-date, that tries to make it easier to use. https://github.com/andrewcooke/simple-date https://github.com/andrewcooke/simple-date (self, link, obviously; also 3.2+ only)
- MagicWishMonkey 13y agoSlightly off topic, but does anyone know why is PyCrypto standard part of the python library?
- falcolas 13y agoDo you mean why is PyCrypto not part of the standard library? Export controls, mostly. From PyCrypto's website: "Unfortunately, cryptography software is still governed by arms control regulations in Canada, the United States, and elsewhere. The controls are fairly loose for free/open-source software, but they exist nonetheless."
- MagicWishMonkey 13y agoAhh, ok, that makes sense.
- wslh 13y agoBatteries included or not, I can always find battery replacements in Python and that's what I love about it. Do you want an excellent graph library? you have networkx. Do you need more speed? bind an existing C++ library with SWIG. If I want to use .NET or Java libraries there is IronPython and Jython. And you have two excellent IDEs: Visual Studio and PyCharm.
- dbecker 13y agoBatteries included or not, I can always find battery replacements in Python and that's what I love about it. I agree that the breadth of high-quality python libraries is great... but in a language that believes "There should be one-- and preferably only one --obvious way to do it," it'd be nice if we weren't also looking for replacements for the standard library.
- Thrymr 13y agoThe author has some reasonable points. There is old cruft in the standard library, and there are vital 3rd party libraries that will never go into the standard library. I don't think the path example is particularly strong, but things like NumPy, IPython, pytz and requests are essential for some tasks. The following is rather poor advice, though: "Python programmers should never restrict themselves to the standard library and should be open—even eager—to depend on third party packages that provide the APIs and functionality they need." Really, you should not be "eager" to depend on things outside the standard library unless you have a good reason to. Every 3rd-party dependency you use adds complexity and you will have to make sure that the latest version doesn't change out from under you. If you are building an open source tool, for example, you may end up supporting multiple versions of the packages you depend on. Sure, use a 3rd-party library if it is worth that overhead, but you should never do it without good reason.