1.) Optional Parameters are a really cool feature. The reason why VB.NET developers did not use it as often is because if you make a dll with your code and a C# developer used it then he had to type every parameter because he had no support for leaving
it out.
2.) It is not a question of design if you use method overloading or optional parameters. If you have a function with 10 arguments where you should be able to only specify those which you like then you would have hundreds of methods that only call other methods with default values. Often you choose only the most important combinations, but often you also have more then 20 methods.
3.) Optional Parameters should not only accept constant values like true or false, but in most cases you need dynamic values. I have a function WriteProtocolEntry(Source as String, Message as String, Date as DateTime)
Most Time Date is DateTime.Now. You can not default date to DateTime.Now so you have to use method overloading again.
In many of my read/write Functions I have a Timeout. Defaulting it would be nice, but if you move the default value to a config file to change it very easy then you have to use method overloading again or default it to nothing and at the start of the method you write (in VB.NET):
If Timeout Is Nothing Then
Timeout=Config.Timeout
EndIf
If Timeout is an Integer even this is not possible and you have to default it to 0 or -1 or if it is a DateTime you could use DateTime.MinValue and hope that noone will ever write a Protocol Entry with 1/1/0000
Another example of the advantage of optional parameters is the creation of Exceptions:
Without the use of optional parameters you had to create 6 constructors:
Public Sub New()
Public Sub New(Message as String)
Public Sub New(Message as String, InnerException as Exception)
Public Sub New(AdditionalInfo as String)
Public Sub New(Message as String, AdditionalInfo as String)
Public Sub New(Message as String, InnerException as Exception, AdditionalInfo as String)
Each Constructor only calls MyBase.New and I think MyBase.New() will do things like Me.New(Nothing,Nothing)
With Optional Parameters you could use:
Public Sub New(Message as String=Nothing, InnerExceptions as Exception=Nothing,AdditionalInfo as String=Nothing)
MyBase.New(Message,InnerException)
Me._AdditionalInfo=AdditionalInfo
End Sub
And if you want to compile it then you would notice that you have two constructors with the same parameter types (Message as String) and (AdditionalInfo as String).
4.) For watching videos I use Media Player Classic and the KLite Codec Pack. With this player you can change the size of the video with the Num Pad.
2.) It is not a question of design if you use method overloading or optional parameters. If you have a function with 10 arguments where you should be able to only specify those which you like then you would have hundreds of methods that only call other methods with default values. Often you choose only the most important combinations, but often you also have more then 20 methods.
3.) Optional Parameters should not only accept constant values like true or false, but in most cases you need dynamic values. I have a function WriteProtocolEntry(Source as String, Message as String, Date as DateTime)
Most Time Date is DateTime.Now. You can not default date to DateTime.Now so you have to use method overloading again.
In many of my read/write Functions I have a Timeout. Defaulting it would be nice, but if you move the default value to a config file to change it very easy then you have to use method overloading again or default it to nothing and at the start of the method you write (in VB.NET):
If Timeout Is Nothing Then
Timeout=Config.Timeout
EndIf
If Timeout is an Integer even this is not possible and you have to default it to 0 or -1 or if it is a DateTime you could use DateTime.MinValue and hope that noone will ever write a Protocol Entry with 1/1/0000
Another example of the advantage of optional parameters is the creation of Exceptions:
Without the use of optional parameters you had to create 6 constructors:
Public Sub New()
Public Sub New(Message as String)
Public Sub New(Message as String, InnerException as Exception)
Public Sub New(AdditionalInfo as String)
Public Sub New(Message as String, AdditionalInfo as String)
Public Sub New(Message as String, InnerException as Exception, AdditionalInfo as String)
Each Constructor only calls MyBase.New and I think MyBase.New() will do things like Me.New(Nothing,Nothing)
With Optional Parameters you could use:
Public Sub New(Message as String=Nothing, InnerExceptions as Exception=Nothing,AdditionalInfo as String=Nothing)
MyBase.New(Message,InnerException)
Me._AdditionalInfo=AdditionalInfo
End Sub
And if you want to compile it then you would notice that you have two constructors with the same parameter types (Message as String) and (AdditionalInfo as String).
4.) For watching videos I use Media Player Classic and the KLite Codec Pack. With this player you can change the size of the video with the Num Pad.