为经验丰富的C#3.0开发人员学习F#有多难?

时间:2022-09-11 10:32:10

How difficult is it to learn F# for experienced C# 3.0 developers, and/or what would you say is the most difficult part of learning F#?

为经验丰富的C#3.0开发人员学习F#有多难,和/或你认为学习F#最困难的部分是什么?

9 个解决方案

#1


Starting out in F# (learning the syntax, scraping the surface of how to program in a functional manner) is not too hard. A good C# 3 developer familiar with LINQ and with a solid understanding of Lambda expressions should be able to pick up the basics quickly.

从F#开始(学习语法,抓住如何以功能方式编程的表面)并不太难。熟悉LINQ并且对Lambda表达式有深刻理解的优秀C#3开发人员应该能够快速掌握基础知识。

It is hard to say how hard it would be for them to break out the habit of object oriented problem solving, but problems that call for functional solutions should force them to make that leap. It is difficult to change your thinking unless you are presented with a new problem in my opinion.

很难说他们打破面向对象解决问题的习惯是多么困难,但需要功能性解决方案的问题应该迫使他们实现这一飞跃。除非你在我看来遇到一个新问题,否则很难改变你的想法。

All in all I would say it took me a week to learn the syntax and basics of the language in my spare time (2-3 hours a night). You'll need more time than that to get a real feel for functional programming though.

总而言之,我会说我花了一周时间在业余时间(每晚2-3小时)学习语言的语法和基础知识。你需要更多的时间才能真正感受到函数式编程。

Issues

I am still struggling with types. I have been doing Project Euler problems to teach myself the syntax, so I haven't needed to any kind of complex user defined types so far.

我仍在努力与类型。我一直在做Project Euler问题来自学语法,所以到目前为止我还不需要任何复杂的用户定义类型。

The type inference the compiler does takes a little getting used to as well, as it is not always clear when it needs types to be specified, and when it can just work them out.

编译器所做的类型推断也需要稍微习惯,因为当它需要指定类型时,并且它何时可以解决它们时并不总是很清楚。

Learning

I would definitely suggest trying Project Euler problems for starters. Mathematical problems are always a good candidate for functional programming.

我肯定会建议为初学者尝试Project Euler问题。数学问题总是适合函数式编程。

On a more general note, data processing problems are good too. List processing is very easy in functional languages, and is one of the first things you should learn IMO.

更一般地说,数据处理问题也很好。函数式语言中的列表处理非常简单,是您应该学习IMO的第一件事。

Books

Real-world Functional Programming: I finished this book a little while ago, and found it really good for working through how to apply functional programming principals to problems using both C# and F#. Most of the examples in the book are done in both languages, using functional programming idioms specific to each language and explaining the difference between them.

真实的函数式编程:我不久前完成了本书,并发现如何将函数式编程原理应用于使用C#和F#的问题非常有用。本书中的大多数示例都是使用两种语言完成的,使用特定于每种语言的函数式编程习语并解释它们之间的区别。

Resources

#2


For me, one of the more difficult parts was really learning algebraic data types (discriminated unions and tuples) and pattern matching, since I had really not deeply encountered these concepts in other languages.

对我来说,其中一个更难的部分是学习代数数据类型(有区别的联合和元组)和模式匹配,因为我真的没有在其他语言中深入地遇到过这些概念。

As for getting up to speed, here is my favorite online content for learning F#. Since you're coming from C#, you may find 'what does this C# code look like in F#' useful.

至于速度,这是我最喜欢的学习F#的在线内容。由于你是来自C#,你可能会发现'这个C#代码在F#中看起来像什么'很有用。

#3


As stated in other answers, the question isn't so much C# vs F#, as Object-Oriented/Procedural vs Functional.

正如其他答案所述,问题不在于C#与F#,而是面向对象/程序与功能。

Having said that, if you've dabbled in Linq, lambdas, anonymous delegates, you've already been doing some functional and/or functional-inspired stuff, so the first hurdle of 'functions as variables' is behind you.

话虽如此,如果你涉足Linq,lambdas,匿名代表,你已经做了一些功能性和/或功能性的东西,所以“作为变量的功能”的第一个障碍就在你身后。

There is a book in the pipes (Functional Programming in the Real World)* which I'm very much looking forward to, as it explains functional programming with C# and F# examples. I thoroughly recommend this webcast, by the author, which I think is an excellent taster. He walks you through an example in procedural C#, then transforms it into functional C#, then hops over to do the same in procedural F#, then functional F#. Very nice.

管道中有一本书(真实世界中的功能编程)*我非常期待,因为它解释了使用C#和F#示例的函数式编程。我完全推荐作者的这个网络广播,我认为这是一个非常好的品尝者。他带您了解程序C#中的一个示例,然后将其转换为函数C#,然后在程序F#中执行相同操作,然后执行功能F#。非常好。

The hardest thing for me is deciphering the cryptic type inference error messages, though apparently they're working on improving that.

对我来说最困难的事情是破译隐藏式的推理错误信息,尽管显然他们正在努力改进这一点。

Side note, there are quite a lot of F# questions on Stack overflow, but you can't find them by searching for "searchword f#", you have to search for "searchword [f#]"

注意,堆栈溢出时有很多F#问题,但是你无法通过搜索“searchword f#”找到它们,你必须搜索“searchword [f#]”

*Of which the co-author/editor is rather well-known to the community ;)

*其*同作者/编辑对社区而言是众所周知的;)

#4


You can learn F# quickly, but the question is how you will program in it.

你可以快速学习F#,但问题是你将如何编程。

F# will let you write procedural code like C#, but it is more cumbersome, and you would be missing the point of a functional language.

F#将允许您编写像C#这样的过程代码,但它更麻烦,您将忽略功能语言的重点。

Drawing from my own experience, you will have to throw away your trusty loops in exchange for list comprehensions. You will also have to learn to use nested functions, and recursion.

根据我自己的经验,你将不得不抛弃你可靠的循环来换取列表理解。您还必须学习使用嵌套函数和递归。

There are also some pitfalls to be wary of with pattern matching.

还有一些陷阱需要警惕模式匹配。

#5


You might learn the F# language pretty fast but it will definitely take some to time to use F# the way it should be used. It could be similar to your jump from C to C++ with the addition of a syntax foreign to the eyes and mindset foreign to the brain.

您可能会非常快速地学习F#语言,但使用F#肯定需要一些时间。它可能类似于你从C到C ++的跳跃,增加了对大脑异常的眼睛和心态的语法。

#6


I'd say before delving into F# dip your toes in a bit of Lisp or Haskell first, or even both. After having a bit of prior experience in Lisp and Haskell, and using C# religiously for a long time, I felt right at home with F#. Then again I also have a bit of experience in OCaml (one of the main influences behind F#) so that helps a fair amount. Functional languages are an entirely different way of looking at things with the Mathematical & Science approach. Add in the power of .NET libraries available in C# that you have prior experience with and you're golden.

我先说,在钻研F#之前,先用一点Lisp或Haskell,甚至两者。在Lisp和Haskell之前有过一些经验,并且在很长一段时间内使用C#后,我觉得在家里用F#。然后,我也有一些OCaml的经验(F#背后的主要影响之一),所以这有助于相当数量。功能语言是用数学和科学方法看待事物的完全不同的方式。添加C#中提供的.NET库的强大功能,您之前有过这样的经验,而且您很高兴。

#7


If you want to learn F#, you need to be familar with Reflector or at least reading IL code.

如果你想学习F#,你需要熟悉Reflector或至少阅读IL代码。

F# does a lot of strange things that on the surface just don't make sense. Examples:

F#做了很多奇怪的事情,表面上看起来没有意义。例子:

  • You have three kinds of null. CLR null, Nullable, and Option.
  • 你有三种null。 CLR null,Nullable和Option。

  • They can be combined. If you see Option you need to check for both None and Some(null) before using the string.
  • 它们可以结合起来。如果看到Option,则需要在使用字符串之前检查None和Some(null)。

  • You can overload most operators like addition (+), concatenate (^), and greater than (>).
  • 您可以重载大多数运算符,如加法(+),连接(^)和大于(>)。

  • Other languages will recognize these overloads in your libraries.
  • 其他语言将识别库中的这些重载。

  • You canot use an overloaded concatenate operator from F#.
  • 您可以使用F#中的重载连接运算符。

  • If you use the > operator, it doesn't honor your overload. Instead it looks for the IComparable interface.
  • 如果使用>运算符,则不会过载。相反,它寻找IComparable接口。

  • The compiler won't tell you that using > without implementing IComparable will be a runtime error.
  • 编译器不会告诉您使用>而不实现IComparable将是运行时错误。

In short, F# is an incredibly inconsistent language and you can't truly understand it without digging into the code it produces.

简而言之,F#是一种令人难以置信的不一致的语言,如果不深入研究它产生的代码,你就无法真正理解它。

#8


How difficult is it to learn F# for experienced C# 3.0 developers,

为有经验的C#3.0开发人员学习F#有多难,

Really easy. You should be able to do serious work after 1 month of learning F#.

真的很容易学习F#一个月后你应该能够做认真的工作。

and/or what would you say is the most difficult part of learning F#?

和/或你会说什么是学习F#最困难的部分?

Firstly, learning to use record and union types and pattern matching instead of classes. Secondly, learning to factor code more aggressively using first-class functions.

首先,学习使用记录和联合类型以及模式匹配而不是类。其次,学习使用一流函数更积极地对代码进行分解。

These are minor issues though. Pick up any decent book on F# and you'll grok them quickly enough. Then you can get on to the really juicy stuff line parallelism and asynchronous workflows and...

这些都是小问题。拿起关于F#的任何体面的书,你会很快就搞定它们。然后你就可以开始真正多汁的东西线并行和异步工作流程......

#9


The biggest leap is going to be the following fact:

最大的飞跃将是以下事实:

C# is an Object Oriented Programming Language

C#是一种面向对象的编程语言

F# is a Function Programming Language

F#是一种函数式编程语言

Developers that aren't familiar with Functional Programming are going to need to catch up on what the differences are and how to transition between the two. The nice thing is that F# is part of the .NET framework...so many of the familiar libraries are going to be there.

不熟悉功能编程的开发人员需要了解差异是什么以及如何在两者之间进行转换。好消息是F#是.NET框架的一部分......所以很多熟悉的库都会出现在那里。

#1


Starting out in F# (learning the syntax, scraping the surface of how to program in a functional manner) is not too hard. A good C# 3 developer familiar with LINQ and with a solid understanding of Lambda expressions should be able to pick up the basics quickly.

从F#开始(学习语法,抓住如何以功能方式编程的表面)并不太难。熟悉LINQ并且对Lambda表达式有深刻理解的优秀C#3开发人员应该能够快速掌握基础知识。

It is hard to say how hard it would be for them to break out the habit of object oriented problem solving, but problems that call for functional solutions should force them to make that leap. It is difficult to change your thinking unless you are presented with a new problem in my opinion.

很难说他们打破面向对象解决问题的习惯是多么困难,但需要功能性解决方案的问题应该迫使他们实现这一飞跃。除非你在我看来遇到一个新问题,否则很难改变你的想法。

All in all I would say it took me a week to learn the syntax and basics of the language in my spare time (2-3 hours a night). You'll need more time than that to get a real feel for functional programming though.

总而言之,我会说我花了一周时间在业余时间(每晚2-3小时)学习语言的语法和基础知识。你需要更多的时间才能真正感受到函数式编程。

Issues

I am still struggling with types. I have been doing Project Euler problems to teach myself the syntax, so I haven't needed to any kind of complex user defined types so far.

我仍在努力与类型。我一直在做Project Euler问题来自学语法,所以到目前为止我还不需要任何复杂的用户定义类型。

The type inference the compiler does takes a little getting used to as well, as it is not always clear when it needs types to be specified, and when it can just work them out.

编译器所做的类型推断也需要稍微习惯,因为当它需要指定类型时,并且它何时可以解决它们时并不总是很清楚。

Learning

I would definitely suggest trying Project Euler problems for starters. Mathematical problems are always a good candidate for functional programming.

我肯定会建议为初学者尝试Project Euler问题。数学问题总是适合函数式编程。

On a more general note, data processing problems are good too. List processing is very easy in functional languages, and is one of the first things you should learn IMO.

更一般地说,数据处理问题也很好。函数式语言中的列表处理非常简单,是您应该学习IMO的第一件事。

Books

Real-world Functional Programming: I finished this book a little while ago, and found it really good for working through how to apply functional programming principals to problems using both C# and F#. Most of the examples in the book are done in both languages, using functional programming idioms specific to each language and explaining the difference between them.

真实的函数式编程:我不久前完成了本书,并发现如何将函数式编程原理应用于使用C#和F#的问题非常有用。本书中的大多数示例都是使用两种语言完成的,使用特定于每种语言的函数式编程习语并解释它们之间的区别。

Resources

#2


For me, one of the more difficult parts was really learning algebraic data types (discriminated unions and tuples) and pattern matching, since I had really not deeply encountered these concepts in other languages.

对我来说,其中一个更难的部分是学习代数数据类型(有区别的联合和元组)和模式匹配,因为我真的没有在其他语言中深入地遇到过这些概念。

As for getting up to speed, here is my favorite online content for learning F#. Since you're coming from C#, you may find 'what does this C# code look like in F#' useful.

至于速度,这是我最喜欢的学习F#的在线内容。由于你是来自C#,你可能会发现'这个C#代码在F#中看起来像什么'很有用。

#3


As stated in other answers, the question isn't so much C# vs F#, as Object-Oriented/Procedural vs Functional.

正如其他答案所述,问题不在于C#与F#,而是面向对象/程序与功能。

Having said that, if you've dabbled in Linq, lambdas, anonymous delegates, you've already been doing some functional and/or functional-inspired stuff, so the first hurdle of 'functions as variables' is behind you.

话虽如此,如果你涉足Linq,lambdas,匿名代表,你已经做了一些功能性和/或功能性的东西,所以“作为变量的功能”的第一个障碍就在你身后。

There is a book in the pipes (Functional Programming in the Real World)* which I'm very much looking forward to, as it explains functional programming with C# and F# examples. I thoroughly recommend this webcast, by the author, which I think is an excellent taster. He walks you through an example in procedural C#, then transforms it into functional C#, then hops over to do the same in procedural F#, then functional F#. Very nice.

管道中有一本书(真实世界中的功能编程)*我非常期待,因为它解释了使用C#和F#示例的函数式编程。我完全推荐作者的这个网络广播,我认为这是一个非常好的品尝者。他带您了解程序C#中的一个示例,然后将其转换为函数C#,然后在程序F#中执行相同操作,然后执行功能F#。非常好。

The hardest thing for me is deciphering the cryptic type inference error messages, though apparently they're working on improving that.

对我来说最困难的事情是破译隐藏式的推理错误信息,尽管显然他们正在努力改进这一点。

Side note, there are quite a lot of F# questions on Stack overflow, but you can't find them by searching for "searchword f#", you have to search for "searchword [f#]"

注意,堆栈溢出时有很多F#问题,但是你无法通过搜索“searchword f#”找到它们,你必须搜索“searchword [f#]”

*Of which the co-author/editor is rather well-known to the community ;)

*其*同作者/编辑对社区而言是众所周知的;)

#4


You can learn F# quickly, but the question is how you will program in it.

你可以快速学习F#,但问题是你将如何编程。

F# will let you write procedural code like C#, but it is more cumbersome, and you would be missing the point of a functional language.

F#将允许您编写像C#这样的过程代码,但它更麻烦,您将忽略功能语言的重点。

Drawing from my own experience, you will have to throw away your trusty loops in exchange for list comprehensions. You will also have to learn to use nested functions, and recursion.

根据我自己的经验,你将不得不抛弃你可靠的循环来换取列表理解。您还必须学习使用嵌套函数和递归。

There are also some pitfalls to be wary of with pattern matching.

还有一些陷阱需要警惕模式匹配。

#5


You might learn the F# language pretty fast but it will definitely take some to time to use F# the way it should be used. It could be similar to your jump from C to C++ with the addition of a syntax foreign to the eyes and mindset foreign to the brain.

您可能会非常快速地学习F#语言,但使用F#肯定需要一些时间。它可能类似于你从C到C ++的跳跃,增加了对大脑异常的眼睛和心态的语法。

#6


I'd say before delving into F# dip your toes in a bit of Lisp or Haskell first, or even both. After having a bit of prior experience in Lisp and Haskell, and using C# religiously for a long time, I felt right at home with F#. Then again I also have a bit of experience in OCaml (one of the main influences behind F#) so that helps a fair amount. Functional languages are an entirely different way of looking at things with the Mathematical & Science approach. Add in the power of .NET libraries available in C# that you have prior experience with and you're golden.

我先说,在钻研F#之前,先用一点Lisp或Haskell,甚至两者。在Lisp和Haskell之前有过一些经验,并且在很长一段时间内使用C#后,我觉得在家里用F#。然后,我也有一些OCaml的经验(F#背后的主要影响之一),所以这有助于相当数量。功能语言是用数学和科学方法看待事物的完全不同的方式。添加C#中提供的.NET库的强大功能,您之前有过这样的经验,而且您很高兴。

#7


If you want to learn F#, you need to be familar with Reflector or at least reading IL code.

如果你想学习F#,你需要熟悉Reflector或至少阅读IL代码。

F# does a lot of strange things that on the surface just don't make sense. Examples:

F#做了很多奇怪的事情,表面上看起来没有意义。例子:

  • You have three kinds of null. CLR null, Nullable, and Option.
  • 你有三种null。 CLR null,Nullable和Option。

  • They can be combined. If you see Option you need to check for both None and Some(null) before using the string.
  • 它们可以结合起来。如果看到Option,则需要在使用字符串之前检查None和Some(null)。

  • You can overload most operators like addition (+), concatenate (^), and greater than (>).
  • 您可以重载大多数运算符,如加法(+),连接(^)和大于(>)。

  • Other languages will recognize these overloads in your libraries.
  • 其他语言将识别库中的这些重载。

  • You canot use an overloaded concatenate operator from F#.
  • 您可以使用F#中的重载连接运算符。

  • If you use the > operator, it doesn't honor your overload. Instead it looks for the IComparable interface.
  • 如果使用>运算符,则不会过载。相反,它寻找IComparable接口。

  • The compiler won't tell you that using > without implementing IComparable will be a runtime error.
  • 编译器不会告诉您使用>而不实现IComparable将是运行时错误。

In short, F# is an incredibly inconsistent language and you can't truly understand it without digging into the code it produces.

简而言之,F#是一种令人难以置信的不一致的语言,如果不深入研究它产生的代码,你就无法真正理解它。

#8


How difficult is it to learn F# for experienced C# 3.0 developers,

为有经验的C#3.0开发人员学习F#有多难,

Really easy. You should be able to do serious work after 1 month of learning F#.

真的很容易学习F#一个月后你应该能够做认真的工作。

and/or what would you say is the most difficult part of learning F#?

和/或你会说什么是学习F#最困难的部分?

Firstly, learning to use record and union types and pattern matching instead of classes. Secondly, learning to factor code more aggressively using first-class functions.

首先,学习使用记录和联合类型以及模式匹配而不是类。其次,学习使用一流函数更积极地对代码进行分解。

These are minor issues though. Pick up any decent book on F# and you'll grok them quickly enough. Then you can get on to the really juicy stuff line parallelism and asynchronous workflows and...

这些都是小问题。拿起关于F#的任何体面的书,你会很快就搞定它们。然后你就可以开始真正多汁的东西线并行和异步工作流程......

#9


The biggest leap is going to be the following fact:

最大的飞跃将是以下事实:

C# is an Object Oriented Programming Language

C#是一种面向对象的编程语言

F# is a Function Programming Language

F#是一种函数式编程语言

Developers that aren't familiar with Functional Programming are going to need to catch up on what the differences are and how to transition between the two. The nice thing is that F# is part of the .NET framework...so many of the familiar libraries are going to be there.

不熟悉功能编程的开发人员需要了解差异是什么以及如何在两者之间进行转换。好消息是F#是.NET框架的一部分......所以很多熟悉的库都会出现在那里。