I have read about function vs procedure function and procedure both are subroutines but function returns a value and procedure doesn't.
Can a function returning void be called a procedure?
Give reasons with definitions...
I have read about function vs procedure function and procedure both are subroutines but function returns a value and procedure doesn't.
Can a function returning void be called a procedure?
Give reasons with definitions...
Yes, this is a common terminology.
Pascal goes so far as to have a separate procedure
keyword for subroutines that do not return.
There is some consensus among programmers of a certain age about the meaning of the terms. Just be aware that it is all culture related.
When a new language or paradigm was introduced, the people selling it would choose new terms to go with their product to make it stand out. As more of these products were born, we soon ran out of words that made sense. To some however being unique and distinct was more important. That is how we got the method. It does not get any more stupid than that and fortunately everyone realized that so the craze was put to an end and from that point on we did with the monikers we had.
It depends on the scene you are in whether people insist on the use of certain terms and whether they attribute a particular meaning to them. Ultimately they are just words that have existed centuries before the first computers emerged. The etymology of function and procedure is not strong in a computer science context, although a Pascal programmer may have a strong opinion about it.
It must be borne in mind that most of these terms, in computing contexts, are more or less synonyms. Some appear to have been drawn from mathematics, others from what might broadly be called administrative science, which predate computers as we know them.
I would tentatively suggest that they are all small variations of what programmers recognise as methods or calls.
A function tends to imply that a value is "returned" - that is, it produces what I believe C programmers know as an "r-value".
A subroutine or procedure meanwhile may provide an "out" parameter or modify a parameter passed in by reference, without being considered a function. This is typical of procedural programming, where a series of calls may manipulate a common parameter which is passed to each of the calls in turn.
For a programmer this distinction is typically a matter of style or convenience rather than fundamental (and many calls to methods involve a mix and match of both return values and out parameters).
In many languages there is no syntax distinction between functions and procedures, and even where the distinction seems to exist such as in VB, in reality the return value of a function can be ignored, and both functions and subroutines are capable of providing out parameters.
Now, can a "function" returning void be called a procedure? I would say no, because such a method is not a function in the first place, unless the word function is used synonymously with procedure (thus no distinction in meaning exists anyway).