Junior — Middle
Can you explain what a pure function means in programming?
sobes.tech AI
Answer from AI
A pure function is a function that always returns the same result given the same inputs and has no side effects. This means it does not modify the program's state, interact with the external world (for example, it does not write to a file or change global variables), and does not depend on external states.
An example of a pure function in C#:
int Sum(int a, int b) {
return a + b;
}
This function always returns the sum of two numbers and does not change anything outside itself. Such an approach makes testing, debugging, and parallel execution of code easier.