E
E
eldar_web2014-09-23 19:20:02
ruby
eldar_web, 2014-09-23 19:20:02

Why are procedures (closures) needed in programming?

Why are procedures (closures) needed in programming?
Here is the ruby ​​code.
1) - percent. function.

var = Proc.new do
puts 'Как-то так'
end
var.call => Как-то так

2) regular function (method)
def var
puts 'Как-то так'
end
var = > Как-то так

Here the second function (not procedural) is clearly better than the procedural function. And why do we need these percentages. ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-09-23
@eldar_web

You have misunderstood the question. By giving an example, you did not reveal the whole essence of closures. Namely, that they can be passed as parameters to other functions/methods. That. the method can be internally extended by an anonymous function.
But this approach should not be abused.
In any case, closures or ordinary procedures/methods are the same approach --- a description of the program in steps: what and how to do to get the result.
It is much more interesting to describe the problem in the form of boundary conditions and obtain a solution without describing the algorithm (see Prologue), but this approach is very limited and resource intensive.

D
Don Kaban, 2014-09-24
@donkaban

https://ru.wikipedia.org/wiki/First_class_functions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question