简体   繁体   English

当我在c#中定义一个类中的所有函数时,我在进行函数式编程吗?

[英]Am I doing functional programming when I define all of my functions in a class in c#?

I am asking this question because I don't want to humiliate myself in a job interview in near future. 我问这个问题是因为我不想在不久的将来在面试中羞辱自己。

I like to create many functions in one place when programming and avoid creating classes and dealing with entity states as much as possible. 我喜欢在编程时在一个地方创建许多函数,并尽可能避免创建类和处理实体状态。 Can I say that I like functional programming and this is my style or preference in programming or do I have to use a functional programming language like F# or Haskell to be able to say that? 我可以说我喜欢函数式编程,这是我在编程中的风格或偏好,还是我必须使用像F#或Haskell这样的函数式编程语言才能说出来?


According to http://en.wikipedia.org/wiki/Comparison_of_programming_paradigms I am actually doing imperative programming in an object oriented language. 根据http://en.wikipedia.org/wiki/Comparison_of_programming_paradigms,我实际上是在面向对象语言中进行命令式编程。

No. 没有。

The hallmarks of functional programming are 函数式编程的标志是

  • avoiding objects (or anything else) with state changes 避免状态变化的对象(或其他任何东西)
  • avoiding mutable data and mutable data structures (more simply; variables don't change their values) 避免可变数据和可变数据结构(更简单地说;变量不会改变它们的值)
  • all (or very nearly all) functions are pure . 所有(或几乎所有)功能都是纯粹的

Many functional languages also rely on pattern matching and strong typing, though it is possible to program in a functional style in a language which lacks these features. 许多函数式语言也依赖于模式匹配和强类型,尽管可以用缺乏这些特性的语言编写功能样式。

To learn more about functional programming, consider reading an introduction to the field (for example Learn You a Haskell for Great Good ). 要了解有关函数式编程的更多信息,请考虑阅读该领域的介绍(例如, 了解大好的Haskell )。

No. Putting all methods in one class makes you a fan of procedural programming, in other words, you are anti-OOP. 不。将所有方法放在一个类中会让你成为程序编程的粉丝,换句话说,你是反OOP。

You could claim to be doing functional programming in C#, if most/all of your variables/arguments/functions were const or readonly , of if these qualifiers could be applied. 如果大多数/所有变量/参数/函数都是constreadonly ,你可以声称在C#中进行函数式编程,如果可以应用这些限定符。

我认为你描述的是更多的程序编程,而不是功能编程。

Afaik you can do functional programming in an oop language. Afaik你可以用oop语言进行函数式编程。 If I understand correctly, functional simply means that you pass in all the stuff the function needs and you take out again the results, storing nothing for next call etc. In other words, your classes and methods are stateless. 如果我理解正确,功能只是意味着你传递函数所需的所有东西,你再次取出结果,不为下次调用存储任何内容等。换句话说,你的类和方法是无状态的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM