ID:152396
 
What are all the differences between writing a proc like
/datum/proc/My_Procedure()
and writing it as
/proc/My_Procedure(datum/D)


Procedures don't get attached to objects like vars (right? o.o). Is there any difference between these 2 approaches, apart from the fact that in the former, the proc would automatically stop if 'src' is deleted?
Also, just wondering, if in /proc/My_Procedure(datum/D), if I do src=D, will I now have that automatic feature?
That's really a matter of how you use it. In example, if the procedure has to do with editing the datum directly, then it may be a good idea to attach it to that datum- But, if that procedure uses the datum indirectly(e.g. comparing his variable with another), then it may be more suit not to attach it.

Is there any difference between these 2 approaches, apart from the fact that in the former, the proc would automatically stop if 'src' is deleted?

Yes, attaching it allow you to modify it for child-types of the object, but aside from that, none that I know of.
In response to DivineO'peanut
DivineO'peanut wrote:
That's really a matter of how you use it. In example, if the procedure has to do with editing the datum directly, then it may be a good idea to attach it to that datum- But, if that procedure uses the datum indirectly(e.g. comparing his variable with another), then it may be more suit not to attach it.


Yes, attaching it allow you to modify it for child-types of the object, but aside from that, none that I know of.

Oh yeah, I temporarily forgot about that when making the post. :x
So these are probably all the differences.
So, another thing, does this matter so much I should consider, when making procs, which type to use, for awhlie? Like, does using object.Proc "noticably" affect efficienty? (machine-wise)
In response to Kaioken
Kaioken wrote:
So, another thing, does this matter so much I should consider, when making procs, which type to use, for awhlie? Like, does using object.Proc "noticably" affect efficienty? (machine-wise)

Nope.
Rule of thumb... a proc should be attached to an object if you feel as though it should belong to that object.

If that proc runs from that object's 'perspective' then it should belong to that object. Examples would be an attack procedure, the Bump() proc.

(In ActionScript, a function that belongs to an object is called a method, even though they're essentially the same thing).
Don't quote me on this, but I think that you can have multiple instances of datum.procedure if you have different datums. For example, if you have two datums, then you can run datum.procedure off both of them, regardless of them being the same.

I don't think that you can run two instances of the same procedure at one time. I think they start to queue up or something.
In response to CaptFalcon33035
Nope, there's no restrictions like that. You can run as many copies of a global procedure as you'd like, although in most cases if you're defining it as a global procedure you should really only be calling it once. =)
Kaioken wrote:
What are all the differences between writing a proc like
/datum/proc/My_Procedure()
and writing it as
/proc/My_Procedure(datum/D)

Procedures don't get attached to objects like vars (right? o.o). Is there any difference between these 2 approaches, apart from the fact that in the former, the proc would automatically stop if 'src' is deleted?
Also, just wondering, if in /proc/My_Procedure(datum/D), if I do src=D, will I now have that automatic feature?

There's no difference, logically speaking, other than the src ending the procedure. I haven't tried the latter "src=D" option, but I would imagine that it would not cause the proc to terminate automatically when src is deleted.

Of course, there's a big difference between those two when it comes to programming style. The former datum/proc/MyProc() format is object-oriented. The latter proc/MyProc(datum/D) format is not object-oriented, and thus prone to lead to spaghetti code. For instance, if /datum/mydatum/specialversionofmydatum has to have special behaviour, the former method could be done as a simple proc override while the latter method would require an if(istype()) inside the proc, thus already being less efficient. I'm not certain how efficient BYOND's runtime-typing is, however, though it's probably more efficient than many other languages'. =)
In response to Jtgibson
I begin to wonder how I should define my procedures. =\ Mainly the more general ones, not having to do with systems etc, of course.


Hmm, I see. Seems those are all the differences - thanks you guys. :)