What are the primary differences between LISP and C# with regards to functional programming? In specific, if a LISP programmer was to switch to using C#, what are the features they are most likely to miss?
Generally, functional programming means using functions to the best effect for creating clean and maintainable software. More specifically, functional programming is a set of approaches to coding, usually described as a programming paradigm.
Obviously you can do functional programming in C. In theory, you can also learn functional programming principles in C, but the language doesn't make it easy.
Every programming language lets you create blocks of code that, when called, perform tasks. Imagine a dog that does the same trick only when asked. Except you do not need dog treats to make your code perform. In programming, these code blocks are called functions.
Doing functional programming in C# is technically possible (well, any language that has function pointers or delegates equivalent can be "functional") -- but C# gets very very painful if you try to do much.
Off the top of my head, in no particular order:
Edit: One more:
Function composition
C# should emit tail.call too. Not needed, the JIT will add tail calls itself as appropriate.
Items in bold have been addressed since this answer was written.
Support for immutability, primarily.
It should be easy to create an immutable type and verify that it's immutable. It should be easy to use an immutable type - support like object and collection initializers, but for the immutable case.
After that: better type inference capabilities, tuples, pattern matching, and supporting libraries (again, immutable lists etc).
EDIT: I should say that I'm not a functional programmer, but I'm a C# programmer trying to learn more functional ways. I'm currently helping out (in a small way) with a functional programming book, so I'm learning lots of stuff there.
However, you will hopefully be pleased with LINQ. It does make life much easier for working with sequences of data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With