Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does functional programming influence your coding style? [closed]

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?

like image 312
Dhanapal Avatar asked Jul 09 '09 13:07

Dhanapal


People also ask

What is closure in functional programming?

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.

Is closure a functional programming language?

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.

What is functional programming style?

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”.


2 Answers

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);            
    }
}
like image 188
Steve Cooper Avatar answered Oct 08 '22 04:10

Steve Cooper


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.

like image 34
John Nicholas Avatar answered Oct 08 '22 06:10

John Nicholas