views:

30

answers:

2

Lets assume we have a class car.
How would You name parameters of function that takes two different cars?

void Race(Car first, Car second);

or maybe

void Race(Car car1, Car car2);

The same situation with function that takes car and list of cars as a parameters.
I'm used to name 'cars' for list of cars, so it is inconvenient to use names like:

void Race(Car car, List<Car> cars);

Any suggestions about names?

+1  A: 

Adding numbers to function arguments is commonly a bad practice therefore I'd go with void Race(Car first, Car second);

Concerning your second function I don't see any problems with the list of cars named cars but I cannot understand the idea of passing a single car as a separate argument so I'd advice to rename it to show it's difference from the cars in the list or remove if it can be passed as a member of cars list.

P.S. You can surely rename cars list into participants or competitors as soon as their type can be retrieved by intellisense of your IDE.

Upd.: Basically, the names of the arguments should depend on the name of the function first and on the type of the argument second, if needed. So, I'd go with Car GetSimilar(Car targetCar, IList<Car> cars).

Li0liQ
Maybe the race function is not the best idea for the second question. Instead of race You can imagine a function that return most similar car from the list, similiar to the car that is passed as a first argument.
Tomek Tarczynski
+4  A: 

I personally choose names that represent how the cars will be used.

In your example, I'd probably just have void Race(IList<Car> cars), since each car is equivalent.

If there are always two, equivalent options, using firstCar and secondCar seems reasonable.

However, if you were doing something like moving parts from one car to another, I'd be very descriptive, ie:

static void StealParts(Car targetCar, Car sourceCar);

The more descriptive you can be in your argument naming, the easier your API becomes for usage.

Reed Copsey
+1 - that's also what I would do.
kiwicptn