0

In Solidity, what's the difference between funtion type and funtion? And what can they be used for and how respectively? Thanks!

1
  • They are fundamentally different things. A function is a sequence of instructions that executes an action, and a function type is a type that holds a reference to a function. – Ismael Jul 2 '20 at 17:03
1

Function types can be internal,external, public or private functions where a function is just a normal function that can be classified as one of these types.

  1. Public functions can be called from anywhere.
  2. Private functions can only be called from inside the contract.
  3. Internal functions can be called inside the current contract but includes inherited functions and libraries.
  4. External functions can be called inside or outside the contract.
3
  • "function is just a normal function" - that's a circular definition! The blame on this can be ascribed mostly to the question itself, though, I would still refrain from stating this "recursive definition" to begin with (and I would more generally refrain from answering that ill-phrased question altogether). – goodvibration Jul 2 '20 at 9:08
  • I assume as a programmer, they understand what we mean if we speak about a "normal function". But to clear things up, what I mean by a normal function is: a block of organized, reusable code that is used to perform a single, related action. – AvocadoChocolate Jul 2 '20 at 9:17
  • A programmer wouldn't ask "what's the difference between funtion type and funtion". The most accurate equivalence of function type which I can think of is function prototype or function signature, meaning it argument types and return-value type. This is also backed by the fact that if you want to pass a function pointer to another function, then you need to specify all of that, as well as the function access-level (e.g., internal view, etc). In that sense, your answer is flawed because it assumes that only public/private/external/internal matter. – goodvibration Jul 2 '20 at 9:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.