__doc__ for functions, classes, objects etc.

Dmitry Soshnikov dmitry.soshnikov at gmail.com
Mon Sep 5 07:12:05 PDT 2011


On 05.09.2011 13:26, Andreas Rossberg wrote:
> On 4 September 2011 21:45, Brendan Eich <brendan at mozilla.com 
> <mailto:brendan at mozilla.com>> wrote:
>
>     On Sep 6, 2011, at 1:52 PM, Dmitry Soshnikov wrote:
>
>     > (1) to standardize `toString` (for this particular case -- do
>     not remove comments inside);
>     >
>     > If the (1) is not possible (why by the way?),
>
>     Because comments are not saved in the compilation process and
>     doing so would slow parsing down and take more space. It's not
>     obvious this would matter in head-to-head competition with other
>     browsers (esp. with minified benchmarks) -- we would have to find out.
>
>     Switching to source recovery will entrain more space but may be
>     tolerable -- except that switching to source recovery is work,
>     competing with other demands. There's no free lunch.
>
>
> Plus, it breaks all function-based data abstraction if you can 
> reliably reflect on its implementation and then even reify it through 
> eval.
>

In other words, if to rephrase you, you nevertheless are talking about 
standardization of `toString`, but to make it some like this, right? :

Function.prototype.toString = function () {
   throw "Don't break out abstractions, malicious hacker!"
};

;)

> I am indifferent about the general idea of a doc interface,

Then I don't think incorrect judging about the concept of an 
"abstraction" is a good topic in this thread (you may open a new one). 
Abstraction is about _abstraction_, it's not about "security". 
Especially in the interpreted dynamically typed language with embedded 
reflection. Abstractions are for programmers. Not for "hackers".

Anyway. It's a completely different story.

> but: having to peek at the _implementation_ of something (which is 
> what toString does) in order to gather its _interface_ description 
> sounds like a fundamental violation of basic principles and exactly 
> the wrong way to go about it.
>

Fundamental principle of an abstraction, once again, is _the 
abstraction_. That is, to provide convenient black box with API hiding 
implementation details. Thus, nobody says it's about security and that 
we can't use things directly if needed. Of course it's a bad practice to 
rely on the internal state. But in case of to string it's not even about 
application level. It's just a meta-reflection. Yes, achieved via such 
way. If it had been implemented at lower level (about what I was talking 
about), then we could get it via reflection API, e.g. Function.getDoc(fn).

However, I already mentioned, I already think it makes sense only for 
technologies such as Node.js (i.e. with big standard library on which 
it's needed often to get quickly help), not ECMAScript at its core.

Dmitry.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110905/d00a4b9c/attachment.html>


More information about the es-discuss mailing list