Getting a result from a bash function

Let's have a simple function:

function sum() {
 total=$(($1+$2))
}

Getting the result to a variable:
Way 1:
result=$(sum 10 20)
Way 2:
sum 10 20
result=$?
$? - captures the return value of the last command