K
Kless
What advantage or difference has a procedure (Proc) over a method?
Kless said:What advantage or difference has a procedure (Proc) over a method?
What advantage or difference has a procedure (Proc) over a method?
Is this for homework or something?
Ruby has no procedures, only methods. All methods have a hidden 'self'
variable linking them to an object.
2008/10/12 David A. Black said:I think you missed the "(Proc)" in the question. The question is about
Proc objects (which I think it's reasonable to refer to as procedures,
though typically people don't) in comparison with methods.
I wanted to know why or when is used Proc because it looks that is theIs this for homework or something?
Kless said:I wanted to know why or when is used Proc because it looks that is the
same that a method.
IMHO it makes sense to not refer to Procs as "procedures" because they
actually are _closures_. This is a significant difference.
IMHO it makes sense to not refer to Procs as "procedures" because they
actually are _closures_. This is a significant difference.
2008/10/13 Phlip said:An important goal of encapsulation is to give everything the narrowest scope
possible. Without closure, if we need 'a' to have a lifespan as long as
'bar', we have to make 'a' into a data member. That widens 'a's scope.
With closures, 'a' has the narrowest scope possible over a long lifespan.
That is a major win - and it's why platforms without closures don't know
what they are missing!
2008/10/13 David A. Black said:Doesn't that vary by language though? I assume Proc/proc stands for
"procedure", so it's hard to rule that out as something to call them.
Well, probably you are right although I do not know a language where
procedures are closures.
OTOH you can say "proc" != "procedure".
Anyway, I just wanted to point out that a Proc is more than a simple
procedure that accepts parameters works on them and probably returns
something.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.