[Python-ideas] Ordered storage of keyword arguments (original) (raw)
Masklinn masklinn at masklinn.net
Fri Oct 29 09:47:38 CEST 2010
- Previous message: [Python-ideas] Ordered storage of keyword arguments
- Next message: [Python-ideas] dict changes [was: Ordered storage of keyword arguments]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2010-10-29, at 06:26 , Greg Ewing wrote:
On 29/10/10 13:54, Nick Coghlan wrote:
The use case is being able to interface naturally with any key-value API where order matters.
For example: # Create an ordered dictionary (WRONG!) d = OrderedDictionary(a=1, b=2, c=3) # Order is actually arbitrary due to unordered kw dict I'd need convincing that the API wouldn't be better designed to take something other than keyword arguments: d = OrderedDictionary(('a', 1), ('b', 2), ('c', 3))
Well that your version takes up nearly 3 times as many characters per item would be quite a ding against it I think. It is verbose and quite alien-looking, and thus not quite ideal for interfacing with systems where ordered keyword arguments are common place (a Python interface to Cocoa for instance, or to a Smalltalk-type system). Then again, you can easily counter that Smalltalk-type keyword arguments allow for repeated keys, whereas Python's don't allow this in any case, so the interface is broken in any case.
Furthermore, it is downright painful to interface with on the other side of the equation, especially since Python has (as far as I know) no support for association lists, as it is necessary to either manually walk the list for the right keys or one has to deal with two different structures at once (a dict for k:v access and a list for order)
- Previous message: [Python-ideas] Ordered storage of keyword arguments
- Next message: [Python-ideas] dict changes [was: Ordered storage of keyword arguments]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]