here is two samples with two different approaches to naming variables:
decimal amountDue = 1000; decimal amountPaid = 800;
vs.
decimal dueAmount = 1000; decimal paidAmount = 800;
Which one would you usually prefer and why?
You should use which ever one reads better as an english sentence. Such as the amount due to the customer is 1000 dollars. In my opinion #1 is better. Because if you write the customer is due the amount of 1000 dollars, it breaks up the wording of the actual variable.
Whatever is most readable in the given context. I could see this ranging from either of your options to simply "paid" and "due".
For example:
public decimal RemainingAmount( Invoice invoice, int quantity, Coupon[] coupons )
{
decimal paid = coupons.Sum( c => c.Value );
decimal due = invoice.Price * quantity;
return due - paid;
}
The first one (amountDue) means typing seven characters before getting useful intellisense. I'd opt for number two.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With