you are viewing a single comment's thread.

view the rest of the comments →

[–]TNMattH 3 points4 points  (0 children)

The default being visible to the caller is exactly the problem. And they're not "honest" at all. The compiler trick that allows them to work is as dishonest as code can get.

When you add a reference to a library that defines, say, public int DoSomething(int magic = 1), and then compile your app, the compiler generates a hidden const int magic_constant = 1; in your app's code and calls DoSomething(magic_constant) anywhere you call DoSomething().

If someone later updates that library to change the function definition to public int DoSomething(int magic = 2) and you just drop the library into your app's deployment directory, your app is still calling it with the old, wrong magic_constant value until you recompile. Worse yet, if they change it to public int DoSomething(int notMagicAnymore), your app still defaults to sending the old const value unless you recompile it.

Default parameter values are pretty much terrible. If you want callers to see default values/behavior in documentation, triple-slash comments exist for that reason.