Which of two variants of code is better?
Victor Porton
porton at narod.ru
Mon Nov 21 13:46:46 EST 2016
Ned Batchelder wrote:
> 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,
It is a helper object which helps to paginate issues.
> 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?
It does not create a comment. It is preparing to load the comment.
> How about this:
>
> obj = IssueComment(repo=repository, issue=id1)
>
> or:
>
> obj = repository.create_issue_comment(issue=id1)
Your code is too specialized. I want to make all my code following the same
patterns. (And I am not going to define helper methods like yours, because
we do not use it often enough to be worth of a specific method.)
--
Victor Porton - http://portonvictor.org
More information about the Python-list
mailing list