I have noticed a lot of beginners think that functions with no return value, or "void functions", are different from other functions. It seems to be in their head that they cannot treat them the same...
The fact is they can't treat these the same. From a semantic point of view, void functions, in order to have any effect at all must have side effects. Whereas functions which return a value are often "pure" functions, with no side effects.
I mean in terms of designing code, they seem to consider them as completely different rather than only thinking "Oh, I can't do var = VoidReturningFunc()"
Well, if you think about it, void functions are not functions (as in mathematics). Thus they are called procedures.
Though I haven't noticed anyone treating them weirdly, I think.
Void functions are nothing on void * in terms of confusion, especially when they are used for a stupid approximation of object encapsulation in C.
(The smart way to get real encapsulation in C is to forward-declare structs in a header, and then define them in the internal code, as done in stdio.)
I sometimes forget about void when writing my void member functions. ;)
And to my delight the compiler catches an error: I forgot to specify I'm not returning anything.
I sometimes forget about std::string when writing my std::string member functions. ;)
And to my delight the compiler catches an error: I forgot to specify I'm returning something.
@Catfish I can't help but notice that a lot of the time you deserve every bit of hotheadedness Duoas and other elders give you.
On topic I have also noticed people thinking of them weird but not on the forums as I am pretty new here. I tutor for a college, and every once in awhile I have to go through explaining what void functions really are/or do, much like hamsterman just did.
Well, if you think about it, void functions are not functions (as in mathematics). Thus they are called procedures.
@LB They can't treat them the same, which is where most of the errors I've seen come from. It also brings in pointer, reference, and parameter type errors.