Hacker News new | ask | show | jobs
by thom_nic 3656 days ago
Interesting Ethereum uses the term "function" however in programming we understand a pure function to be an operation that always returns the same result given the same inputs.

I don't know anything about Ethereum, but if functions rely on external shared state then they aren't pure functions, are they?

3 comments

Well, solidity is kinda javascript-style syntax and that's the keyword from javascript.

On a pedantic level, you're absolutely correct, but real-world usage generally makes 'function' equivalent to 'subroutine', hence why we have the specific term pure function to disambiguate.

Ethereum (well, Solidity) calls them methods, not functions, and everybody agrees that methods are potentially state changing procedures.

Moreover, there is a staggering amount of precedence for using "function" without implying purity, so even if Solidity did call them functions, that would be entirely normal terminology.

And, well, the entire point of invoking a contract is to effect some change to the state of the blockchain, so it would be strange to expect that Solidity methods were pure functions.

No - a pure function is a function that has no side-effect (other than heat loss).

You are talking about referential transparency. Even functions that are not pure can be referentially transparent.