What is “referential transparency” that I hear talked about in computer programming?

491 views

What is “referential transparency” that I hear talked about in computer programming?

In: Technology

3 Answers

Anonymous 0 Comments

It means that you can replace an expression with its value without changing the behavior of the program. It’s usually used in the context of functions: If we have some function `foo`, and it turns out that calling `foo(1, 2, 3)` returns `5`, then there should be no difference between writing `int x = foo(1, 2, 3)` and `int x = 5`.

This has some implications:

* `foo` must always return the same output for the same input, so it can’t depend on any external value that changes
* `foo` must not produce any side effects, which includes performing I/O or setting external values

You are viewing 1 out of 3 answers, click here to view all answers.