The most of programmers nowadays use OOPS concepts for software development.
But some of them have exposure to functional programming too.
How does functional programming influence your coding style?
A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function's scope from an inner function.
In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment.
Functional programming is a programming paradigm in which we try to bind everything in pure mathematical functions style. It is a declarative type of programming style. Its main focus is on “what to solve” in contrast to an imperative style where the main focus is “how to solve”.
Main use has been passing functions into higher-order functions like filter and map (Where and Select in .Net) This is really the biggest impact, allowing you to write things like set operations just the once, then things that act on or modify sets.
So things like
var SquareOfEvenIntegers = MyListOfInts
.Where(i=>even(i))
.Select(i=>i*i);
instead of
List<int> SquareOfEvenIntegers = new List<int>()
foreach(int i in MyListOfInts)
{
if (even(i))
{
SquareOfEvenIntegers.Add(i*i);
}
}
I find it a lot easier to write multi threaded code now.
I tend to have less class level variables than before.
I also tend to have interfaces that are functionally independent ... again that has a huge gain when it comes to multi threading as it can greatly reduce the amount of object locking required provided your threads are also functionally independant.
I also tend to have nightmares about closing braces chasing me.
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