In VB.NET, which is better to use: function overloading or default parameters?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Is the code going to be used by other languages? If so, that swings the balance towards overloads while still bearing Hamish’s answer in mind. In particular, C# doesn’t support optional parameters – yet…
Admittedly this wouldn’t actually prevent someone using your code from C#, it just might be a pain for them.
If there are a lot of parameters and they logically represent something, you might want to consider encapsulating them together, in the same way that
Processworks withProcessStartInfo. That’s particularly nice from C# due to object initializers.If this is for construction, you might also consider the builder pattern as a variant of this. For instance, in Protocol Buffers I can do something like:
which ends up being very readable while still creating a person in one go (in one expression, and without having to mutate the person itself – indeed the message type is immutable; it’s only the builder which isn’t).