Thursday, April 2, 2009

Methods and Procedures

Recently I have started to notice more and more people in my field (Computer Science) confusing the terms method and procedure, using them as if they were interchangeable. I just want to set the record straight: they are not interchangeable, they are different things. This confusion, I've noticed, is present mostly in people accustomed to program in Object Oriented Languages, as the closest thing to a sub-routine or procedure in these languages is precisely a method.

A method is not the same as a procedure. OK? A procedure, in a programming language, is a sequence of instructions that perform a certain task. As simple as that. A method, on the other hand, is a concept that only makes sense in OO languages. A method is associated with an object (or a class) and it is the object's way of doing things. I feel like going into a more philosophical discussion about this... but I won't. Suffice it to say, they are not the same, so if you're a computer scientist, and you're reading this, please stop doing this. Use the word procedure where it belongs, and the word method where it belongs... and let us all make a more rigorous science :-)

4 comments:

Scott Harmon said...

Now what about functions and subroutines?

Apolo Imagod said...

Subroutines and procedures are basically synonyms, subroutines being a term carried over from the old days on unstructured programming languages. Now, strictly speaking functions are a special type of procedures that have no side effects and map inputs to an output. However, the term function has already been abused in programming languages like C/C++ where they should have been named procedures (in the case of C) or methods (in the case of C++). But, since C/C++ are just big hacks, we'll just let it slide :-P

Scott Harmon said...

I wonder if a 'final static method' (with no side-effects) in a class is more of a procedure than a method. Also, would you classify a static block as a procedure?

Apolo Imagod said...

I would say so... in any case, the biggest issue I have is with people calling procedures, like in Pascal procedures, methods. That's is clearly I huge disuse. In the first case you mentioned (the final static method), like I said above, and like you pointed out, I would say it's more of a procedure... however, it is still associated to a class... however, the fact that it is final, makes it just a block of code invoked by the system to affect the state... not really a method (philosophically speaking).

A static block, cannot be explicitly invoked... that's not even a procedure :-)