Although the two have almost the same purpose, they have a small difference, where mixin serves more to include a block of code while the function serves more returns a value.
What is the real difference between mixins and functions?
Mixin Example:
Following mixin can accept arguments and make calculations. The output of this mixin (in this case) is a CSS rule and will be placed wherever you include it.
@mixin my-mixin($some-number) {
padding: $some-number;
margin: $some-number;
}
Now let's use the include directive to enter the mixins code.
.my-module {
@include my-mixin(10px);
}
And here is the CSS output code.
.my-module {
padding: 10px;
}
Function Example:
A function is very similar to a mixin, however, the output from a function is a single value. This can be any Sass data type, including: numbers, string, colors, booleans, or lists.
The following function can accept 2 arguments, $ some-number and $ another-number. The value returned by these two variables are added together.
@function my-calculation-function($some-number, $another-number){
@return $some-number + $another-number
}
This time, we will replace the common value of the padding property with a snippet of SassScript to call our function, pass them arguments and include in our output CSS code.
.my-module {
padding: my-calculation-function(10px, 5px);
}
And here is the CSS output code.
.my-module {
padding: 15px;
}
This link below shows some more good examples of this besides what I mentioned here:
Using pure Sass functions to make reusable logic more useful
Note that in the example you cited, it is not possible to return several properties as in the mixins:
@function border-default($color) {
@return border: 1px solid $color:
}
@mixin my-mixin($some-number) {
padding: $some-number;
margin: $some-number;
}