C and its many quirks

WBahn

Joined Mar 31, 2012
32,935
And mathematically speaking, a function never has side effects -- it only takes values for arguments and returns values in response. Any side effects, including changing the value of the arguments, violates referential transparency.

So why should a function that returns a random number, or that returns the current time, require an input argument? It seems to me that it makes perfect sense for such functions to not take any arguments and return a value.
 

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,762
And mathematically speaking, a function never has side effects -- it only takes values for arguments and returns values in response. Any side effects, including changing the value of the arguments, violates referential transparency.
Yes, this is quite true.

So why should a function that returns a random number, or that returns the current time, require an input argument? It seems to me that it makes perfect sense for such functions to not take any arguments and return a value.
Well in my specific case it's a matter of grammar design. I'm reviewing grammar decisions and seeing what justification there is for some of them.

I use "procedure" and "function" to define invokable code, for a procedure that takes no arguments we pass no arguments:

Code:
call reset_system;
But function invocations that takes no arguments can appear as operands in expressions, they too can be parsed fine without an argument list:

Code:
a = get_date - two_weeks;
But unlike with procedures which must be invoked with "call" these are not, so looking at that code one has no idea if the operands are variables or functions.

Yes we can - as some languages do - simply require "(" and ")" but that is then inconsistent with the "call" above, that has no parens because it has no args, so requiring these for functions is inconsistent.

If you think about it, why choose to implement something like this:

Code:
function get_date() returns (Date)
end;
rather than

Code:
procedure get_date (Date date);
end;
So that's the context of this question, just stepping back and taking a 5,000 ft view, if something has no arguments why even write the parentheses...

Many of the conventions we see in C-derived languages stem from the perverse concept that all invokable code "is a function" which is not true, actions and functions are different things, this is why they invented the horrible "void".
 
Last edited:
Top