Perhaps, but it is lexical semantics we are talking about here. Taking my idiomatic expression above...
It is not Black or White - I've not ever stated that Subroutines and Function Blocks are wholy indifferent. I said they have both similarities and differences, of which we should be aware of, if choosing between using one over the other.
It is not Black and Black - I've not ever stated that Subroutines are Function Blocks and are instantiated, variable-declared and called in the same way.
It is not White and White - I've not ever stated that Function Blocks are Subroutines and are logically prioritised, parameter-assigned and executed in the same way.
Platform independently - if we, for example, create a "Program" within a "Task" and add several Subroutines with logical functions all being executed in the sequence required to perform the "Task".
If we create another "Program" and instantiate several Function Blocks within the "Program", and call them according to the logical functions required to perform the "Task".
The Function Blocks are effectively, or in essence, performing the same logical role as the Subroutines. That is not me saying that a Function Block is a Subroutine or vice versa. It is me saying that, apart from how they are actually implemented within the Task, they may be used to execute blocks of code in a similar fashion while performing a similar Task.
So at the implementation level we can state that they are quite different, but at the programming level we can state that they are quite similar.
I know where you're coming from here but don't forget that Subroutines may also be called or not called from several other sources. Parameters associated with a Subroutine may be manipulated to "reinstantiate" the Subroutine prior to execution. This can effectively make a Subroutine, containing intended reusable code, actually reusable. These methods exist and are in use as we "speak".
So that I am still being clear because people often think I'm choosing a side in these matters - I am not saying that Subroutines are as good as or better than Function Blocks. Again, I would point out, or advise, that deciding which or when to use either method of code encapsulation, to achieve certain Tasks, should be an application-dependant decision.
I've been keeping my comments as general as possible so as to focus more on the structural heirarchy of POUs and not really get into brand specifics. However, your last comment here would also prompt me to point out that the apparent power that Function Blocks may have traditionally appeared to hold over Subroutines has somewhat diminished in recent years. On certain platforms, such as Allen Bradley's Logix 5000, the power of the Subroutine has been increased to level the playing field somewhat with Function Blocks (AOIs). For instance, the introduction of Public Parameters at Logix Designer v24 allows Program parameter tags now be globally exposed within a project so Subroutines can reach and be reached beyond the local Program.
Subroutines and Function Blocks, while comparable at certain levels, are indeed separate entities. And we can say with certainty that they are not in the main functionally or logically used for the same thing. Subroutines tend to be used more for either one-off code within a Program, or reusable code across Programs or projects, but not usually reused within the same Program. Whereas Function Blocks tend to be used for reusable code either in or across Programs or projects, and reused within the same Program.
But again, and even if the lesser, there are and will continue to be applications out there using these methods where Subroutines are being used more than once in a Program and Function Blocks are being used to execute substantial one-off blocks of code, never to be used again.
Regards,
George
I agree with your detailed analysis but I don't think it's a case of one or another however. A function block is a subroutine but I tend to reserve the term subroutine when referencing fixed code that is called by a jump & return type command usually internal to the main code. The term function blocks is used for code implemented with instances and often contained in a separate vessel from "main" code (POU). Maybe it's an incorrect usage for all platforms, but with what I'm familiar with it's a valid way of differentiating.