Functional programming in C#—A brief consideration
-
-
Didn't we hear about this with Object Oriented Programming, Structured Programming, etc.? Different programming paradigms support different environments. Using the wrong paradigm for the environment leads to excessively complex code with the attendant bugs.
-
Quote:
A very common problem encountered in most program code is high complexity. To deal with this, a great alternative is functional programming
Wow, what a total miss on how to deal with complexity. :laugh: Complexity exists regardless of the programming language, and a programming language does not address complexity. What he means by "complexity" in his post is better termed "elegancy" though some may argue that => this => that => thar => wherefore art thou Romeo => dead is not elegant.
Latest Article:
Create a Digital Ocean Droplet for .NET Core Web API with a real SSL Certificate on a Domain -
Quote:
...Something I’ve noticed is that many developers, based on their experiences and taking advantage of the possibilities of OOP, have created totally empirical code, full of endless “if” and “else” statements...
Then it must not be very good OOP code, if it even warrants that title.
Quote:
The use of immutable values and recursion can generate more memory consumption ... but compared to the overhead of imperative programming, pure functions require much less overhead
Self-contradictory.
namespace FPExampleApp;
public class Order
{
public int UnitPrice { get; set; }
public int Discount { get; set; }public void SpecialCustomer(int unitPrice, int discount) { UnitPrice = unitPrice; Discount += discount; }
}
The article uses constructors to simplify code in the Immutable version, but no
Order(UnitPrice up, int discount) { }
to simplify the imperative case. :rolleyes: :rolleyes: :rolleyes: :doh: :doh: :doh: They can be made practically identical. I stick by my first statement.Our Forgotten Astronomy | Object Oriented Programming with C++ | Wordle solver
-
The thing that makes sense to me is the immutable data. Most errors I see is where someone, somewhere changed an object's state which was not anticipated elsewhere. Same thing could happen with immutable data as well, but it would be easier to track back to where something went wrong. I could see some higher memory use, especially if dealing with large datasets. For people that like Test Driven Development, functional is a good way to go. Once the algorithm is proven, it should be solid and not need to worry about weird state issues.
-
The thing that makes sense to me is the immutable data. Most errors I see is where someone, somewhere changed an object's state which was not anticipated elsewhere. Same thing could happen with immutable data as well, but it would be easier to track back to where something went wrong. I could see some higher memory use, especially if dealing with large datasets. For people that like Test Driven Development, functional is a good way to go. Once the algorithm is proven, it should be solid and not need to worry about weird state issues.
I have always asked "how would you do something like a word processing program in a functional manner?" The only response I've heard makes me think it would be very difficult, because the main document would have more and more states as each addition/revision was made. Each change basically creates a new main document. An 'undo' function would probably be easier than many other methods, but that by itself isn't enough to convince me...
Our Forgotten Astronomy | Object Oriented Programming with C++ | Wordle solver
-
The thing that makes sense to me is the immutable data. Most errors I see is where someone, somewhere changed an object's state which was not anticipated elsewhere. Same thing could happen with immutable data as well, but it would be easier to track back to where something went wrong. I could see some higher memory use, especially if dealing with large datasets. For people that like Test Driven Development, functional is a good way to go. Once the algorithm is proven, it should be solid and not need to worry about weird state issues.