Nice trick Mohammad I didn't know that if we use pointers on types we get nil values, but be careful with this because you can have panic errors if you forgot to check if it's a nil or int, what I would do is keep the type as it is and add a method to check if the field is not zero, like this:
Nice trick Mohammad I didn't know that if we use pointers on types we get
nil
values, but be careful with this because you can have panic errors if you forgot to check if it's anil
orint
, what I would do is keep the type as it is and add a method to check if the field isnot zero
, like this:This way I don't need to check if the field is
nil
and can still perform arithmetic operations.