Is making in-place operations return the object a bad idea?

前端 未结 4 644
遇见更好的自我
遇见更好的自我 2020-12-16 10:35

I\'m talking mostly about Python here, but I suppose this probably holds for most languages. If I have a mutable object, is it a bad idea to make an in-place operation also

4条回答
  •  -上瘾入骨i
    2020-12-16 11:17

    I suppose it depends on the use case. I don't see why returning an object from an in-place operation would hurt, other than maybe you won't use the result, but that's not really a problem if you're not being super-fastidious about pure functionalism. I like the call-chaining pattern, such as jQuery uses, so I appreciate it when functions return the object they've acted upon, in case I want to use it further.

提交回复
热议问题