M
Michael Haufe (TNO)
[F]or the sake of argument only:
Interesting. Can you explain why you prefer these formulations? I
have no problem at all with using these objects as quasi-namespaces
for related global functionality.
String.fromCharCode -> 7.fromCharCode()
Okay, except that this functions takes an arbitrary number of
parameters. How would you handle that?
Date.parse("July 28, 2005") -> "July 28, 2005".parseDate()
This could work, but what does this have to do String instances?
Should Strings also have parseRegex, parseBoolean, parseJsonObject,
and other similar functions. If so, why? What does this have to do
with Strings?
//Number.NaN makes as much sense to me as Number.7
Number.NaN -> NaN
Would you also make global Number.NEGATIVE_INFINITY, Number.MAX_VALUE,
and the like? To what end? I think there is already far too much in
the global namespace.
Object.create(o) -> o.new
This I can almost buy, implemented with code resembling the following:
Object.prototype.new = function() {
// create new object and copy over all properties of `this`
}
But I don't see the harm in the 'Object.create' syntax. What's the
objection?
At first I replied inline, but with a little more thought I could see
even more questions being raised as a result, so I'll try to take a
step back to give an answer from my perspective as it is a perspective
argument anyway; Hopefully from there it will make more clear what my
intended objections are.
My issue is the organization of the language, and adding all of these
static members doesn't help. I agree with John G Harris's Christmas
Tree statement. A better organization the language should have strived
for is to embrace more of its SmallTalk/Self background than some type
of mixture of half-assed functional. I feel it sits in an awkward
place between the two (plus Java syntax didn't help of course). Sure,
it has first-class functions, but you can't write true functional code
as any ML/Lisp family programmer will tell you. OO is also awkward due
to verbosity and not everything being an object. In comparison to its
relatives, the layout of the inheritance model is pretty slapdash due
to its history. I suspect these things are well known to the community
here and don't need to be stated for the umpteenth time, but maybe I'm
wrong.
So IME, populating Object, Number, and so on with more and more static
members is a perpetuation of design smell. The objects are being
treated like namespaces or generic placeholders for things the awkward
language organization disallowed putting elsewhere (and the backwards
compatibility demon of course). We have Object.create, soon maybe
Function.create and Array.create according to the mailing-list. Do
these not bother you? Why Date.parse instead of new Date? Why not new
Json(...)? Each of these are rhetorical questions in themselves, but
taken as a whole I think the issue is clear.
On to my off-the-cuff code examples: If the language hypothetically
decided to embrace its OO roots and clean up the inheritance model
things may look similar to some of the examples, more specifically the
concept of "specificObjectType.releventMember". What methods go where
and their behavior is less important in relation to having a
consistent means of expressing code. I could ramble on, but this is a
topic better suited to a blog entry or a separate thread* methinks.
Things are getting off-topic enough already. Enough with my droning.
*No doubt someone will jump on my use of the word "thread" here...