Although the two serve almost the same purpose, they have a slight difference, where mixin serves more to include a block of code while Function serves more returns a value.
What is the real Difference between mixins and functions?
Mixin example:
The following mixin can accept arguments and do calculations. The output of this mixin (in this case) is a CSS rule and will be placed wherever you include.
@mixin my-mixin($some-number) {
padding: $some-number;
margin: $some-number;
}
Now let’s use the include directive to insert the mixins code.
.my-module {
@include my-mixin(10px);
}
And here’s the output CSS code.
.my-module {
padding: 10px;
}
Example Function:
A function is very similar to a mixin, however the output from a function is a single value. This can be any type of Sass data, including: Numbers, string, Colors, booleans or lists.
The following function can accept 2 arguments, $some-number and $Another-number. The returned value of these two variables is 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 what a chunk of Sassscript to call our function, pass arguments and include in our output CSS code.
.my-module {
padding: my-calculation-function(10px, 5px);
}
And here’s the output CSS 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 mentioned, it is not possible to return several properties as in mixins:
@function border-default($color) {
@return border: 1px solid $color:
}
@mixin my-mixin($some-number) {
padding: $some-number;
margin: $some-number;
}