what's best practice when it comes to documenting attributes in the
source code (maybe even utilising ScalaDoc)?
What I have in mind is a kind of documentation that lists all available
attributes for a given node (hence the reference to ScalaDoc). However,
the attributes are usually not known at node side already, but if the
attributes are documented as just regular methods then there isn't a
single place that lists all attributes available for a certain node.
And something slightly related: has anyone experimented with IDE support
for attributes, e.g. code hints/autocompletion?
I wonder whether using the Pimp My Library pattern to "turn" the
node->attr syntax into node.attr would facilitate IDE support, and how
big the runtime penalty is.
Cheers,
Malte
> what's best practice when it comes to documenting attributes in the
> source code (maybe even utilising ScalaDoc)?
>
> What I have in mind is a kind of documentation that lists all available
> attributes for a given node (hence the reference to ScalaDoc). However,
> the attributes are usually not known at node side already, but if the
> attributes are documented as just regular methods then there isn't a
> single place that lists all attributes available for a certain node.
I'm not sure there is any best practice for this sort of thing yet. To
my mind attributes are functional in the sense that they are associated
with a type (say Expression) rather than a particular sub-type of that
type (say AdditionExpression).
I see your point though. How does someone find out about expression
attributes when they are looking at the documentation for a particular
kind of expression?
I suppose there is nothing stopping you adding such documentation to
the AdditionExpression class documentation, referring to the module
in which the attributes are defined. That would lead to duplication in
the docs of each sub-class of Expression. Alternatively, you could
document them in Expression with a short pointer from sub-classes.
A counter argument to all of this is that attributes are intended to
be separate from the classes on which they operate. Therefore I can
come along at any time and add new attributes to existing classes
without having to modify those classes. Adding attribute documentation
to the classes couples them more closely than you may want.
> And something slightly related: has anyone experimented with IDE support
> for attributes, e.g. code hints/autocompletion?
> I wonder whether using the Pimp My Library pattern to "turn" the
> node->attr syntax into node.attr would facilitate IDE support, and how
> big the runtime penalty is.
I'm not currently using an IDE for my Scala work, so I haven't tried
this sort of thing and I'm not aware of anyone else who has. I think you
could do it, but that pattern does incur some object creation overhead.
I've seen claims that the JVM can remove it easily since the objects
are very short-lived, but I haven't measured.
cheers,
Tony
> And something slightly related: has anyone experimented with IDE support
> for attributes, e.g. code hints/autocompletion?
> I wonder whether using the Pimp My Library pattern to "turn" the
> node->attr syntax into node.attr would facilitate IDE support, and how
> big the runtime penalty is.I'm not currently using an IDE for my Scala work, so I haven't tried
this sort of thing and I'm not aware of anyone else who has. I think you
could do it, but that pattern does incur some object creation overhead.
I've seen claims that the JVM can remove it easily since the objects
are very short-lived, but I haven't measured.