Find a way to clean up API

Issue #194 new
Ronald Oussoren
repo owner created an issue

It would be nice to optionally use a more swift-like naming convention with PyObjC, but doing that while maintaining backward compatibility and performance will be hard.

  1. Expose @property properties as properties instead of requiring to use the getter/setter methods. Doing this is backward compatibility break because unlike ObjC Python doesn't have a separate namespace for properties (note: see the "_" special attribute on instances, but not yet on classes)

  2. Swift exposes shorter names for enums in the enum namespace, that is ObjC (and Python): NSColorTypeComponentBased, Swift: NSColorType.ComponentBased

    Not sure yet if this will be useful for Python. At the very least this will help with introspection.

    Extendable enums are problematic here. Performance is also an issue.

  3. Python 3.6 has OrderedDictionaries by default (more or less, and definitely not ABI), this should make it easier to following the Swift naming convention at least for calling methods (especially when coupled with first class @property support).

    Not sure if this can be done performantly and if this can also be done for declaring methods.

    A challenge will be effectively overloaded versions of methods.

Comments (4)

  1. Ronald Oussoren reporter

    2 should already work with the current long names (NSColorType<tab> should show a list of completions). The major win w.r.t. how the names are exposed in Swift is that it cleans up the global namespace (which PyObjC won't be able to do initially due to backward compatibility concerns), and better documentation. In Swift you can als leave out the type name in a lot of cases (e.g. use .ComponentBased because the compiler can deduce the type used based on other information), but that's not possible in Python.

    I'm slightly more interested in 1 and 3 because that will allow for cleaner code (by doing away with the idiotically long names we have to use now for 3).

    Anyways.... it might be a while before I actually find time to work on this and backward compatibility may well be a deal breaker here.

  2. Log in to comment