← Back to team overview

openerp-expert-framework team mailing list archive

on the new API proposal

 

Hi community !

Many thanks to the openerp dev team for sharing the new API proposal in the openerpdays.

Here are random ideas / open questions / proposals:


Ability to call record method on a set of records
-------------------------------------------------

We could question why this had to be done:

- shorcuts ? It's maybe thought as convenient way to be able to call
  the method on all the elements ?
- performance ? This allows some optimisation that wouldn't be possible.

Let me get in to this:

shortcuts:

  Calling a method on each record is no more than an automatic
  classical "map" on record list. Besides the implementation of this
  method is very often using a "for". The new API will remove the
  "for". Very well, but why even keep this functionality ?

  Let

    >>> record_set = RecordSet(from_ids=[1, 2, 3])

  Then, in the API proposal:

    >>> result_set = record_set.method(args)

  is equivalent to :

    >>> result_set = [r.method(args) for r in record_set]

  Why not use this last form when needed ? It's not that much longer...

  Removing in the general case the possibility to call directly
  methods on record_set has these advantage:

  - it removes a specificity of openerp ORM, so it's API is easier
    to grasp.
  - it simplifies the implementation of the method (which should be
    defined in Record class)
  - less magic (and code) in the API implementation.

performance:

  It is true that in some rare case, you could get some performance
  benefit by avoiding a complete loop. If this is of some importance, I
  would suggest then to add optional API sugar for this case. (In this
  case, the @multiple decorator in front of a method of Record object
  would make some sense).


Remove the specifics of the record set
--------------------------------------

Why the RecordSet could not be just a simple python list ? Or a very lightly modified subclass of it ?

I don't think of cases where "result_set.record" would be of some use,
result_set[0] seems sufficient. If the remainder of the API is
coherent, we should not have record_set in places where we only need
one record. There will be some rare case where we want explicitely the
first element of the record set, and I think this should be explicitly
stated with "result_set[0]".


Use the python instantiation instead of some ".new()" method
------------------------------------------------------------

Well, I'd rather see:

    >>> new_person = Person(name="Guido", lastname="Van Rossum")

Than

    >>> new_person = Person.new(name="Guido", lastname="Van Rossum")

Sometimes its more than bikeshedding.


More inspiration from existing API
----------------------------------

Similarity to existing successful model should not be seen as a shame,
but instead as a great openness toward the python community. There are
great ideas lying around. And using some of them would ease the
learning curve of newcomers.

For more info, I would suggest reading:

Elixir: http://elixir.ematia.de/trac/wiki/TutorialDivingIn

Which gives a good example of a similar ORM can be.

Of course, you can look also to:

Django: https://docs.djangoproject.com/en/1.4/topics/db/models/


There are plenty of inspirationnal ORM implementation in python.


Regards,
Valentin LAB


Follow ups