[Openerp-community] Class or class_obj

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Openerp-community] Class or class_obj

Leonardo Pistone - camptocamp
Hi all,
what do you think about this one?

https://github.com/OCA/sale-workflow/pull/60/files#r20361659

Thanks! (and thanks to Pedro for being an awesome reviewer)

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Class or class_obj

Leonardo "LeartS" Donelli
When global language conventions clash with "local" project
conventions, basically all standards say to use the local one.

In the first lines of PEP8:
> Many projects have their own coding style guidelines. In the event of any conflicts, such project-specific guides take precedence for that project.

A little later:
> Some other good reasons to ignore a particular guideline:
>
> * When applying the guideline would make the code less readable, even for someone who is used to reading code that follows this PEP.
> * To be consistent with surrounding code that also breaks it (maybe for historic reasons) -- although this is also an opportunity to clean up someone else's mess (in true XP style).

So I'd say to prefer Odoo consistency at the moment, and push for a
change in Odoo conventions at the same time, as some of those are
really horrible.

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Class or class_obj

Graeme Gellatly
Leonardo's et al,

I would prefer to define the project as the subset of OCA projects rather than Odoo as a whole.

OCA keeps our conventions up to date and have discussions like this in the open.
We also have control of them.
OCA conventions are generally far closer to pep8 making automated checking much easier.
Odoo has mixed examples of everything all through their code.  Even for this particular point you will see _pool, _model, _obj or nothing.

That said having read the arguments on both sides throughout the linked issue I have no clue about what the convention should be. Personally I prefer the CapWords argument, even though it diverges from PEP8. Really it is used like a class but at the same time if you were reassigning say StringIO within a local scope it would be lowercase (I don't know why you would do this).  Given our existing convention of _obj I'd want very widespread agreement to change and have that change clearly documented before allowing PR's to use CapWords for models assigned from the registry within a local scope.



On Mon, Nov 17, 2014 at 2:53 AM, Leonardo "LeartS" Donelli <[hidden email]> wrote:
When global language conventions clash with "local" project
conventions, basically all standards say to use the local one.

In the first lines of PEP8:
> Many projects have their own coding style guidelines. In the event of any conflicts, such project-specific guides take precedence for that project.

A little later:
> Some other good reasons to ignore a particular guideline:
>
> * When applying the guideline would make the code less readable, even for someone who is used to reading code that follows this PEP.
> * To be consistent with surrounding code that also breaks it (maybe for historic reasons) -- although this is also an opportunity to clean up someone else's mess (in true XP style).

So I'd say to prefer Odoo consistency at the moment, and push for a
change in Odoo conventions at the same time, as some of those are
really horrible.

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp


_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Class or class_obj

Guewen Baconnier @ Camptocamp
Hi all,

I think everybody agree that _obj is a weak convention. _obj appeals
to an object / an instance.
The alternative proposed suffix is _model. The meaning is clear there.
But personally I find it long when the name of the models is already
long.
I like the idea of the CamelCase (I'm usually following the pep8 rules
but here it would make sense to make an exception) as it would be the
closest to the class that it represents (on the other hand we could
have conflicts if we need a model that is in the same file like
SaleOrderLine as noticed by Yannick Vaucher).

I won't bring the debate much further with my poor arguments... but at
least it was an excuse to share this commit
https://github.com/odoo-dev/odoo/commit/3ac368b588b94d2563427df04f62a05c26b171e4
where odoo is using 2 of them: the meaningless suffix Obj *and* the
CamelCase assignation which upset some people ;-)

Guewen Baconnier

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Class or class_obj

Leonardo "LeartS" Donelli
Sorry, I thought I mentioned it: I'm not for using `_obj` at all!
Personally I'm for the `_model` suffix. It's the most clear and
explicit, it's often used by Odoo too so it doesn't clash with their
code, and is correct by PEP8 standards.
It's only 2 letters more than _obj!

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Class or class_obj

Sandy Carter (http://www.savoirfairelinux.com)
I agree.

In Object Oriented Programming, an object is an instance of a class, not
the class itself.
Since these are relational models, _model makes more sense to me.

I also like _pool as it is clear that it comes from self.pool (in v7).
There's also _registry or _reg.

Anyway, _obj doesn't make a lot of sense to me, but if it's our
convention I won't make a fuss. Until it is, though, I won't be changing
my naming convention and won't consider it in my reviews.

+1 for creating a convention and posting it on
http://odoo-community.org/page/how-to

Le 2014-12-02 07:10, Leonardo "LeartS" Donelli a écrit :

> Sorry, I thought I mentioned it: I'm not for using `_obj` at all!
> Personally I'm for the `_model` suffix. It's the most clear and
> explicit, it's often used by Odoo too so it doesn't clash with their
> code, and is correct by PEP8 standards.
> It's only 2 letters more than _obj!
>
> _______________________________________________
> Mailing list: https://launchpad.net/~openerp-community
> Post to     : [hidden email]
> Unsubscribe : https://launchpad.net/~openerp-community
> More help   : https://help.launchpad.net/ListHelp
>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp

signature.asc (484 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Class or class_obj

Alex Comba - Agile BG


On Tue, Dec 2, 2014 at 3:56 PM, Sandy Carter <[hidden email]> wrote:

+1 for creating a convention and posting it on
http://odoo-community.org/page/how-to

I'm in favour too.

Cheers,
 

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp