Today I am going to talk about default arguments in programming languages.
What do you think about it ? Should your language support default arguments ?
Some languages support and some don’t. It has a heavy influence on the design.
What are the pros for the default arguments:
* Instead of writing many overloads you can write only one.
* The code completion can show only one function instead of 20 (E.g. System.MessageBox.Show method)
What are the cons for the default arguments:
* They can lead to strange behaviour.
– Default arguments in python: Default values
– Default arguments in C++ when using virtual functions. You use the default value according to the static and to the dynamic type.
So what is the best solution ?
In my opinion the best solution is to create many functions with overloads, but to do it automatically.
You can do it in Nemerle language using macros:
Enjoy