First off, I want to clear up any confusion that may be lingering. The thoughts and opinions expressed on this blog are my own and not those of my employer or anyone else.
Lets get to it
When it comes to UX programming I always try to seperate data and display. Nearly every tutorial out there smashes them together, in a production environment that’s a practice for the fool-hearty.
At this point I’m just ignoring all display programming until I get more aligned with the WPF/.NET paradigm. So, I’ve started diving into the data side of things, setting up classes, interfaces and whatnot. Low and behold, I’ve started running into some hurdles:
How do I define optional parameters?
The short answer: you can’t.
The long answer: polymorphism.
That’s right. Good-old family-friendly polymorphism. This is something I haven’t even thought of for years. Primarily because Actionscript doesn’t allow it, even though it does allow optional parameters.
Sure, optional parameters are kind of a hack, but they make code 100x more managable. Let’s look at an example:
Actionscript 3
/* * In AS3 you can define function paramaters as optional. * In this example, the parameters "x" and "y" are required * to call the function. However, "z" and "mass" are optional and if * left out of a function call their values will default, in this * case, to "1". * * Correct usages: * myFunction(1.5, 2.78, 3.02); * myFunction (0.1, 10.4); * myFunction(5.8, 2.08, 3.89, 12.2); * * Incorrect usages: * myFunction(); * myFunction(1.1); */ public function myFuction(x:Number, y:Number, z:Number=1, mass:Number=1):void { }
C#
/* * In C# optional parameters don't exist. So you * have to use polymorphism to achieve similar * functionality as optional parameters in AS3. */ public void myFunction(double x, double y) { } public void myFunction(double x, double y, double z) { } public void myFunction(double x, double y, double z, double mass) { }
I’ve grown very fond of optional parameters because in C# you have to manage multiple seperate definitions for the same function. What a pain in the ass.
In situations like this polymorphism really seems tired and dated… a blast from the past. There are new ways to program! What’s the hold up?
That’s it for now
I have more rants queued up but this post is already too long.


