elegance of functional programming

Functional programming allows you to write concise and elegant code. Mainstream languages like Ruby and C# support a lot of functional programming paradigms, and learning them makes you a better programmer. Below is a small example which demonstrates that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

#6 lines of ugly code
i = 0
tasks = list.tasks
while(i < tasks.length - 2)
tasks[i].priority.should >= tasks[i + 1].priority
i += 1
end


#3 lines of elegant functional code
list.tasks.each_cons(2).each do |t1, t2|
t1.priority.should >= t2.priority
end


I am currently working on LiveForm which makes setting up contact forms on your website a breeze.