What is referential transparency?

Q: What is referential transparency?


A: Referential transparency is a feature of parts of computer programs where a part of the program can be replaced with the value it gives back without changing the program's behavior.

Q: What is the opposite of referential transparency?


A: The opposite of referential transparency is referential opacity.

Q: Are all functions in mathematics referentially transparent?


A: Yes, all functions in mathematics are referentially transparent because a mathematical function can only take values in and spit a value out.

Q: How does referential transparency help programmers and compilers?


A: Referential transparency lets programmers and compilers to think of code as a rewrite system—something that takes an expression and replaces it with something else. This helps with tasks such as proving that the program or code is correct, making an algorithm more simple, making it easier to change code while still being sure that it does what its supposed to, and making the code run faster or use less memory.

Q: What are some techniques used for making code run faster or use less memory?


A: Some techniques used for making code run faster or use less memory include memoization (saving answers after the first time), common subexpression elimination (figuring out if it is worth it to combine two parts of the code that are the same) , lazy evaluation (not finding the answer until the code really needs it), and parallelization (working on multiple problems at the same time).

Q: Is there any difference between functions in programming compared to those in mathematics?


A:Yes, there is a difference between functions in programming compared to those in mathematics -In programming, a function might also find out what day of year it is or print a message to screen whereas this isn't possible with mathematical functions.

AlegsaOnline.com - 2020 / 2023 - License CC3