A colleague and I are discussing best practices regarding ordering method parameters. The goal is to establish a standard in our organization to improve readability and productivity by giving our methods common signatures. We are merely establishing guidelines for the recent grads we are hiring.
Example (userId is always passed in to audit the calls):
GetOrders(string userId, int customerId); GetOrders(string userId, int[] orderIds); GetCustomer(string userId, int customerId);
My argument is the following:
His argument is essentially the opposite.
I'm not asking for a right or wrong answer here, nor a discussion. I just want to see what standards exist already.
Thanks!
I'd go with the ordering of input,output,optional.
Optional should go at the end to me because most languages allow you to specify a default value for optional arguments to avoid having to include them. The provision of that is that they have to be the last argument(s) otherwise you can't drop them.
That's assuming you can't have named arguments though. If you can have them, I'd always suggest using them for clarity and order becomes a moot point.
I try to make all methods that use similar parameters use them in the same order.
For the choice for a single method, I go by importance. Optional items last.
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