Pedantic Semantics and Extending flash.geom.Point
I gotta think the non-native-English-speaking office of Macromedia must have developed the Flash framework. Why? I could be self-loathing and say, "because it evolved into something quite wonderful". Or, I could be truthful, and say, "because the semantics suck".
I agree, most people just get on with their lives, but by now, oh constant reader, you'll no doubt agree with my psychiatrist that I am not most reader (or, you may conclude I simply have no life to get on with). But I, however, actually care how my code reads.
I'm one of those whacky developers who attempts to avoid the need for comments throughout my code. I believe that well-written code, based on well-defined and appropriate algorithms, implemented with variables and methods named logically and appropriately, combined with the thoughtful application of white-space, shouldn't need comments beyond introductory and summary statements about how particular classes interact, where the concept derives from, etc.
The code needn't read like English, exactly, but it shouldn't require more effort than necessary to decipher. More effort equals an increased need for clarification in a comment. Furthermore, code performing a task within a particular field-of-study, should adopt the acceptable nomenclature and symbology of that field. Symbols preferred over semantics.
It is precisely because I am passionate about effective communication that some aspects of the Flash framework bug the crap out of me—to say nothing of the lacking salve-for-my-suffering that operator overloading (or overriding) could be, and the relief it could (help) provide.
If our goal is to add two numbers, the semantics we would rely upon would depend upon the context within which we are working.
Linguist: thisNumber plus thatNumber equals theSum;
Mathematician: this + that = theSum;
Developer: theSum = this + that;
flash.geom.Point: theSum = this.add(that);
Which one of these makes little or no semantic sense in any context? Here's a clue, it's not the first three. And anyone wishing to use it has no choice but to abide, as it may not be simply overridden to achieve semantic bliss. add would be better applied the way the word is actually used in the English language from which it sprang… perhaps:
theSum = add(this, that);
But even that is icky. Better, would be a static method:
theSum = Point.addTogether(this, that);
Who wants to type all that, though. So, why not use the appropriate verb:
theSum = this.plus(that);
And reserve the word add for:
this.add(that); // no result returned
When all the while, what we really want is:
theSum = this + that;
Which would be fine if
this, that, and theSum were simple data types, but what if they weren't instances of int or Number, but of EmployeeCompensationMultiplier or AlienColdStorageDetails? However Javascript/Actionscript define an operator, we have no way of overriding it or providing our own logic for it's implementation.And if they include both add and subtract, why the heck wasn't multiply and divide included as well?
Back to making the best of it…Their particular choice to implement "add" rather than "plus" or "sum" was unfortunate. Combined with the fact that it doesn't alter the value, but returns a new Point just makes things awful.I want my extended class to allow things like:
theSum = this.plus(that);
theSum = this.plus$(3);
theSum = this.plus$$(3, 5);
and…
this.add(that);
this.add$(3);
this.add$$(3, 5);
Or maybe I want:
theSum = this.addedTo(that);
theSum = MyPoint.add(this, that);
theSum = this.plus.(that).times.(something);
The latter of which can't even be done with any elegance using the base methods unless you do tricksy stuff like:
theSum = this.add(that).normalize(something);
which bears little or no resemblance to anything remotely logical, semantically speaking. Bummer.
Aaaaaaaaaarrgh!
So this was a total bitch-session as there are pitifully few options here beyond "dealing with it" and compromise—or what I like to call unfortunate bullshit. And sure, I know all about making unfortunate bullshit work…
I work for the man, after all.
about this entry
you’re currently skimming and ignoring “Pedantic Semantics and Extending flash.geom.Point,”
- published:
- 12.09.07 / 3am
- category:
- actionscript, flex
nobody cares (yet?)
click to care. click to comment. | comments rss [?] | trackback uri [?]