In .net, Which method is better and why?
- Having a fu开发者_如何学Pythonnction which has a DataTable parameter to fill
- 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.
精彩评论