What is the meaning of return a `bool` type in a function?

this is an issue on our OpenZepplin repo that has been closed, the question is:

The burn and burnFrom functions on ERC20Burnable do not return a bool 
like other OZ ERC20 function. eg ERC20Mintable.mint

and below is nventuro's response:

In OpenZeppelin, we adopt the convention that functions revert when encountering an 
error condition, as opposed to returning an error value. We believe this is safer,
since it is very easy to forget to handle an error, 
which may have catastrophic consequences. 
Because of this, a call to burn will either succeed, or revert.

The fact that ERC20Mintable does return a boolean value is a mistake we should 
correct, but this is sadly a breaking change, and will therefore be postponed 
until v3.0 comes out.

but I am still confused with it, so I come here for more details, so what is the meaning of return a bool type in a function?

Hi there,

Not too sure what the question is, but this may help you out.

Functions in computer programs can return objects or primitive types. Both of these types have cons and pros. Primitive types are easy to work with and are baked into programming langs. Think of them like super basic elements such as protons or electrons in real life.

They are normally the following:

  • integers or int
  • single float numbers
  • double float numbers for long numbers
  • booleans or bool

Depending on the lang, there might be more prim types. But they follow the same principles regardless.

Booleans (bool) are types that hold 1 value, and that value can be either true or false. But nothing else. They are useful for conditions or in cases where you know that only two outcomes are possible. Functions use booleans to indicate success or failure. Or answering yes/no situations. ETC…

To use booleans, you use operators like == or != in statements

For example:

age = 23

if age is greater then 10 do
  say "you are older than 10"
  say "not older then 10"

behind the scenes, this if statement returns a boolean. EASY to read/understand.

Errors are special objects and objects are more complex than the primitive types. I won’t go into details, if you want to know more then you can google it. :smiley:

After saying that, if programs use errors to indicate something, there will be more code. Specifically error handling code. You have to throw errors and catch exceptions to make sure your program doesn’t crash in the middle of something important like funding you money.

You will have to write try statements like so:

try this 
  refund steve
 catch (someError)
   revert the funds ASAP

With booleans, you just have to check and then the function that returns a boolean can automatically revert what it was doing.

Hope that helps you!


Thanks for your patiently replying! Just like what you said, I will google for more details.


@Skyge any news on this?

It seems that when we want to interact with other contracts, the return value may help in some point.