Which of two variants of code is better?

Ned Batchelder ned at nedbatchelder.com
Mon Nov 21 13:26:47 EST 2016


On Monday, November 21, 2016 at 12:48:25 PM UTC-5, Victor Porton wrote:
> Which of two variants of code to construct an "issue comment" object (about 
> BitBucket issue comments) is better?
> 
> 1.
> 
> obj = IssueComment(Issue(IssueGroup(repository, 'issues'), id1), id2)
> 
> or
> 
> 2.
> 
> list = [('issues', IssueGroup), (id1, Issue), (id2, IssueComment)]
> obj = construct_subobject(repository, list)
> 
> (`construct_subobject` is to be defined in such as way that "1" and "2" do 
> the same.)
> 
> Would you advise me to make such function construct_subobject function or 
> just to use the direct coding as in "1"?

Neither of these seem very convenient. I don't know what an IssueGroup is,
so I don't know why I need to specify it.  To create a comment on an issue,
why do I need id2, which seems to be the id of a comment?

How about this:

    obj = IssueComment(repo=repository, issue=id1)

or:

    obj = repository.create_issue_comment(issue=id1)

--Ned.



More information about the Python-list mailing list