Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminology for a deterministic function with no side-effects?

I need the proper terminology for a specific type of function.

Suppose you write a function in your SQL database, whose inputs and outputs are contained within the scope of a database transaction.

That is, if you call this function in the scope of a database transaction, all the data used by the function is available within the same scope. It can query a database table, but it can't read a file from the filesystem, or ping a web site, etc. If you call the function twice within a single transaction with REPEATABLE READ isolation, you should get the same result, even if other clients are making changes in the database.

Likewise, the function has no side-effects, except within the same transaction scope. Changes in state outside the scope of the database transaction are not allowed. The function shouldn't send emails, nor write to the filesystem, nor store a value in memcached, etc. If the function changes data within the database, that's okay because if the calling transaction is rolled back, then the effects of the function are too.

The arguments of the function are okay, since they're basically used as constants.

What would be the proper term for a function of this type? "Deterministic" doesn't really seem to be specific enough. How would you describe this class of function?


Thanks for your answers, but none of them is exactly what I had in mind. Idempotent gets closest, so I marked that as the accepted answer. But each of you got an upvote from me regardless.

  • Pure functions have no side-effects, and their result is based solely on their arguments. The result given the same arguments is always identical. This doesn't work because the database functions I have in mind can be based on the state of data, and the function can also affect the state of data.

  • Idempotent functions can return a result based on the state of data, and given the same state of data, the result is always identical. But this doesn't work for what I have in mind exactly; the effects of an idempotent functions must result in an unchanging result no matter how many times the function is called. But there's no distinction between changes made within transaction isolation and changes made external to that scope.

like image 428
Bill Karwin Avatar asked Dec 13 '22 04:12

Bill Karwin


2 Answers

You can also call these pure functions.

like image 148
RossFabricant Avatar answered Jan 14 '23 12:01

RossFabricant


Are you asking about idempotent?

like image 43
S.Lott Avatar answered Jan 14 '23 11:01

S.Lott