News for hackers. Stuff that matters.
Re:Fear and Loathing in Programming La La Land (2012) by sitharus on Monday July 15, 2013 @04:49PM (#6048474)
Even worse, optional parameters are implemented backwards.

That is: public void DoSomething(string required, string optional = null) is actually DoSomething(string, string), but at compile time a call to DoSomething("foo") is compiled to DoSomething("foo", null).

Hence optional parameters are not recommended for an external API.

Re:Fear and Loathing in Programming La La Land (2012) by sukuriant on Monday July 15, 2013 @04:52PM (#6048488)
So you need to be mindful and have intelligent overloads for the DoSomething method?

Personally, I don't really see that as much of a problem. Having run into that issue before, I think the compiler catches it as as an error because its an ambiguous method signature. Instead, you have to pass something like: "DoSomething("foo", (string)null)" which, in that case, defeats the purpose of the optional parameter altogether.

Re:Fear and Loathing in Programming La La Land (2012) by sitharus on Monday July 15, 2013 @06:48PM (#6049025)
Yeah, been through that before. We just standardised on using overloads for external APIs, it's cleaner externally.

The real issue is if you have DoSomething(string what, autoRetry=true) and you change to DoSomething(string what, autoRetry=false) - DLLs compiled against the old version will call with true even if the authors wanted the default behaviour.

Re:Fear and Loathing in Programming La La Land (2012) by sukuriant on Monday July 15, 2013 @06:53PM (#6049049)
That makes sense. As I said in my other thread, I locally deal with that problem by passing null instead of a primitive (though admittedly, I would probably use a primitive in cases of bool).

That said, in this circumstance my method sounds more like a hack and yours the cleaner, correct route.