开发者

.net: What do you prefer and why: having a function which has a DataTable parameter to fill or return a DataTable?

开发者 https://www.devze.com 2023-02-02 05:44 出处:网络
In .net, Which method is better and why? Having a fu开发者_如何学Pythonnction which has a DataTable parameter to fill

In .net, Which method is better and why?

  1. Having a fu开发者_如何学Pythonnction which has a DataTable parameter to fill
  2. Having a function which returns a DataTable after filling it

I mean:

1.

Public Function Test(tb As DataTable) As boolean
    '
    '
End Function

2.

Public Function Test() As DataTable
    '
    '
End Function

Thank you


The first practice can be more efficient in some cases, but the latter is generally better practice because there are no unintended side effects, and it's more like functional programming. It just depends on whether you need that efficiency or not.


Use the approach that reduces side-effects and leads to code which is easier to maintain.

I would only use the side-effect form in (extreme) cases where it is unavoidable to fulfill the functional requirements -- and then I would likely re-think the design/approach in general. My "cycles" are much more important than those of a computer.

0

精彩评论

暂无评论...
验证码 换一张
取 消