Reputation: 2101
I always came across with this question when creating function or variable in swift. Consider the following implementations:
var
var isOpen: Bool
{
// expression returning either true or false
}
var subTotal: Double
{
return quantity * price
}
func
func isOpen() -> Bool
{
// expression returning either true or false
}
func subTotal() -> Double
{
return quantity * price
}
What's the best practice on this?
Upvotes: 1
Views: 386
Reputation: 1933
I use var
for fairy simple implementation with no side effect. If the computation takes long time or it changes something, I use func
.
Upvotes: 2