How do you choose between writing a function and a procedure with one output?

How do you choose between writing a function and a procedure with one output?

That is the question I asked several colleagues of mine. I usually go with how I feel on a given day, but yesterday I thought to ask around. A way to strike up a conversation on our office day. Office day is when we get to meet other colleagues who are working on different projects for different companies.

What came up was that the difference between the a function and a procedure is that you can call a function in a select statement. Other than that it was a matter of taste I guess.

And today I read about functional programming in the book grokking algorithms. Which lead me to the concept of pure functions. A pure function is a concept commonly used in computer programming and mathematics. A pure function is a function that satisfies two key properties:

Deterministic Output: Given the same input, it always produces the same output. In other words, the return value is identical for identical arguments.

No Side Effects: It does not have any observable side effects, such as modifying global variables, altering external state, or printing to the console.

Essentially, a pure function behaves like a mathematical function: for a given input, it consistently produces the same result without affecting anything else. Examples of a pure functions: sum(), length(), avg().

This is what I will use whenever I have to make the choice between writing a function or a procedure with an output. If there are no data manipulation actions required or POST Rest actions it will become a function.

#function #procedure #oracle #codingbookworm

To view or add a comment, sign in

More articles by Raoul Mangoensentono

Insights from the community

Others also viewed

Explore topics