How difficult is it to move from OOP thinking to purely function-oriented thinking programming in .NET?

I have been working with C # for many years, starting with the beta version. I have some time moving from OOP to functional oriented programming (FOP). I started with the concepts of procedural programming and functional composition in the late 1980s and have been doing OO since 1995, when UML was in its infancy, when I programmed the procedural and OO approach in Delphi using a multi-paradigm. Are there any good suggestions for books to help transition to functional programming with a deeply rooted OO programmer?

I tried the Haskell book, but it seemed to require some background in the subject and was very impregnable.

I have a couple of O'Reilly , Apress books on F #, but it all seems a bit woolly and half empty house just doing the job. It also mixes objects with features that suit your needs.

F # seems to forgive me in my OOP thinking much more than Haskell, but I think in order to get the real benefits I need to get FOP thinking in order to get the most out of the code. I read about functional programming for about two years between my daily C # affairs. But I feel that I do not delve into thoughts.

I am sure that there are many people like me. Any answers would be, I think, a big help for many C # guys wanting to switch to F #. Especially with many big market hitters requiring F #. I am a contractor who needs to get up to speed as soon as possible.

+7
c # functional-programming f #
source share
4 answers

This is definitely subjective, but I think many people ask similar questions. Of course, I did this when I started learning F # (like someone with C # experience). Here are a few different ideas:

  • Choose the right learning problems . The best way to learn functional programming is to start working on some non-trivial projects. If you choose a project that is easy to solve in the OO path, you are likely to be inclined toward solving OO. However, if you choose a project that naturally matches the FP solutions, you will learn something. In my case, I worked on a translator from F # quotes to JavaScript, which includes many recursive processing and discriminatory associations.

  • Do not try to be perfect . If you try to write something in a functional way, it may not be perfect on the first try. Don't worry about it (and don't tell yourself what you can do better in OO). You can do better in the FP way, as it just takes some time to learn how to do it.

  • Try to be a purist . If you start learning Haskell, you will have to write pure functional code. F # does not apply this, but I do not think that F # is less suitable for learning functional programming. If you know C # and .NET, you can reuse your experience. Just try to be more strict on yourself and avoid using non-functional constructs such as volatile state and inheritance - they are sometimes useful, but you can use them after you learn to think along the FP path.

And the little shameless plugin, answering such a question, was one of the key motives of my book on programming in the real world , so maybe this can help ...

+9
source share

Are there any good suggestions for books to help move towards functional programming from a deeply rooted OO programmer

The structure and interpretation of computer programs (SICP):

His course, apparently, is mainly focused on the functional composition. It is in LISP, but it is less related to the language and more related to abstract concepts.

I don’t think that he talks a lot (or anything else) about pure FP, but I really haven’t read it all: :) Concepts and way of thinking should still be very applicable.

+3
source share

I believe that in order to really understand functional programming, you must first reorganize all your knowledge about how to implement different things (for example, you need to understand that objects can be represented as hash maps or even associative lists, and not just how records). You will also need to start thinking in terms of immutable data and pure functions (procedures without a side effect). Then you have to compare the functional and procedural ways of implementing and treating the objects.

All this can be found in SICP - a classic book for studying not only FP, but also programming in general. To understand the functional way, you do not have to read the entire book, but at least the first 3 chapters.

Once you understand the basic concepts of FP and can implement something in this style, read any book in statically typed languages. For example. Apress books on F # will be much easier to read.

+2
source share

Teach you Haskell is a decent read, although it is probably too thorough, since you probably already know the Haskell syntax from one of the books you have chosen ...

Moving Up, Haskell Programming , which, if you scroll down the page, has tons of links to video lectures on a book provided by MS researcher Eric Meyer.

Equational Reasoning is especially interesting, if only academically.

From the point of view of the application, this book of functional programming Real-World, cited in another answer, looks very beautiful - although I did not read it, so I can not judge.

+1
source share

All Articles