我应该美元的C#p $ PFER静态方法 [英] Should I prefer static methods in C#

查看:105
本文介绍了我应该美元的C#p $ PFER静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经花了一点时间来学习函数式编程,它变得越来越自然,我想与不执行任何突变的静态方法来处理。

Having spent a bit of time learning about functional programming, it's becoming more and more natural for me to want to work with static methods that don't perform any mutation.

是否有任何理由为什么我要遏制这种本能?

Are there any reasons why I should curb this instinct?

推荐答案

这个问题我觉得有点古怪,因为静态方法和方法执行没有突变的方法两个正交分类。你可以有变异的静态方法和nonmutating实例方法。

The question I find a bit odd, because static methods and methods that perform no mutations are two orthogonal classifications of methods. You can have mutating static methods and nonmutating instance methods.

对于我来说,这已经成为越来越多的自然功能和面向对象编程结合起来;我喜欢的实例的方法执行没有突变。函数式编程更容易理解,因为它阻碍了复杂的突变;面向对象编程更容易理解,因为code和它的运作上的数据彼此靠近。为什么选择?拥抱和的力量;一举两得!

For me, it has become more and more natural to combine functional and oo programming; I like instance methods that perform no mutations. Functional programming is easier to understand because it discourages complex mutations; OO programming is easier to understand because the code and the data it operates on are close together. Why choose? Embrace the power of "and"; do both!

这篇关于我应该美元的C#p $ PFER静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆