Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming Conventions: amountPaid vs. paidAmount [closed]

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?

like image 928
Pavel Bastov Avatar asked Apr 24 '09 10:04

Pavel Bastov


3 Answers

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.

like image 67
Nick Berardi Avatar answered Oct 15 '22 07:10

Nick Berardi


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;
}
like image 22
tvanfosson Avatar answered Oct 15 '22 05:10

tvanfosson


The first one (amountDue) means typing seven characters before getting useful intellisense. I'd opt for number two.

like image 32
Damien_The_Unbeliever Avatar answered Oct 15 '22 07:10

Damien_The_Unbeliever