[WEBINAR] The New Normal: Dealing with the Reality of an Unsecure World

Referential Transparency

Definition - What does Referential Transparency mean?

Referential transparency is a property of a specific part of a program or a programming language, especially functional programming languages like Haskell and R. An expression in a program is said to be referentially transparent if it can be replaced with its value and the resulting behavior is the same as before the change. This means that the program's behavior is not changed whether the input used is a reference or an actual value that the reference is pointing to.

Techopedia explains Referential Transparency

Referential transparency has its roots in analytical philosophy, which is a branch of philosophy that studies natural language constructs, arguments and statements based on the methods of mathematics and logic and has little to do with programming, although it has been adopted by computer scientists.

The concept is simple, the "referent," the thing that an expression refers to, can be used to substitute the "referrer" without changing the meaning of the expression. For example, the statement "Luke's father is an evil man," "Luke's father" references "Darth Vader" in Star Wars lore. So the statement is referentially transparent since "Luke's father" can be replaced at any time with "Darth Vader" and the statement would not change in meaning. However, in the statement "the audience did not know until 'The Empire Strikes Back' that Luke's father is actually Darth Vader" is not a referentially transparent expression since if "Luke's father" is replaced with "Darth Vader" the expression becomes "the audience did not know until 'The Empire Strikes Back' that Darth Vader is actually Darth Vader," which has an entirely different meaning.

In relation to programming, the concept is at first glance the same, but many philosophers disagree that the concept is implemented or carried over well in programming languages. But in general programming, this simply means that an expression can be replaced by its resulting value without having an effect on the program's behavior. For example, the function plusOne(x) simply adds one to whatever the value of x is, so if we know that x = 5 then we can safely replace the function with the value 6 in an expression which yields the same behavior when using plusOne(x). But if there is an external variable within the expression that is controlled externally, say in the function plusY(x) where Y within the function is externally controlled, the resulting behavior may not be the same — in this case this is not a referentially transparent expression.

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
"Techopedia" on Twitter

Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Free Whitepaper: The Path to Hybrid Cloud
Free Whitepaper: The Path to Hybrid Cloud:
The Path to Hybrid Cloud: Intelligent Bursting To Amazon Web Services & Microsoft Azure
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.