Functional programming: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Added bibcode. | Use this bot. Report bugs. | Suggested by Dominic3203 | Linked from User:LinguisticMystic/cs/outline | #UCB_webform_linked 789/2277
Line 165:
=== Imperative vs. functional programming ===
 
The following two examples (written in [[JavaScript (programming language)|JavaScript]]) achieve the same effect: they multiply all even numbers in an array by 10 and add them all, storing the final sum in the variable "<code>result"</code>.
 
Traditional imperative loop:
Line 184:
.map(a => a * 10)
.reduce((a, b) => a + b, 0);
</syntaxhighlight>Sometimes the abstractions offered by functional programming might lead to development of more robust code that avoids certain issues that might arise when building upon large amount of complex, imperative code, such as [[Offoff-by-one error|off-by-one errors]]s (see [[Greenspun's tenth rule]]).
 
=== Simulating state ===