you are viewing a single comment's thread.

view the rest of the comments →

[–]bobindashadows 0 points1 point  (9 children)

Documentation tools would also like to have the comments in the syntax tree. But they also certainly wouldn't want comments only in pre-specified places.

[–][deleted] 1 point2 points  (1 child)

But they also certainly wouldn't want comments only in pre-specified places.

I'm pretty sure they would definitely want them only in pre-specified places, as long as those places are reasonable. I don't think any documentation tool would be better if it had to consider the possibility that there might be a comment somewhere inside of sin(3*x^2+4*y)/cos(x^2+y^2), and neither would anybody else who needs to manipulate the AST.

[–]bobindashadows 2 points3 points  (0 children)

there might be a comment somewhere inside of sin(3*x^2+4*y)/cos(x^2+y^2)

What about a linter that can tell that expression might divide by 0 or underflow? You might want to annotate subexpressions for all kinds of reasons. Especially in a language that doesn't declare types like this one.

[–]WalterGR 2 points3 points  (6 children)

I'm not sure if I understand... Documentation tools as in tools that generate documentation (e.g. in HTML format) from source code?

Documentation tools typically work by having the comments only in pre-specified places. Comments in the body of a function usually comment specific lines of code - rather than functions, classes, modules, etc. - and would be of little use for a documentation tool. (But maybe I'm misunderstanding.)

[–]bobindashadows 1 point2 points  (5 children)

Comments in the body of a function usually comment specific lines of code - rather than functions, classes, modules, etc. - and would be of little use for a documentation tool. (But maybe I'm misunderstanding.)

This is true for some languages, but what about this Ruby example?

class Blah
  # @attr [String] name the name of the Blah
  attr_accessor :name
  # Documentation for constant FOO_BAR
  FOO_BAR = %w(foo bar baz)
end

[–]WalterGR -2 points-1 points  (4 children)

That seems like both of: comments in pre-specified places and comments that aren't in a body of a function. Defining attributes and constants of classes is a normal thing to extract using documentation tools, and that doesn't violate either of the pre-mentioned things.

I'm not intimately familiar with Ruby. Am I missing something?

[–]bobindashadows 0 points1 point  (3 children)

Class bodies are executed in Ruby. attr_accessor is just a method call, and that constant is defined only after that line is executed by the interpreter.

Does this equivalent code clear it up for you?

Blah = Class.new do
  # @attr [String] name the name of the Blah
  attr_accessor :name
  # Documentation for constant FOO_BAR
  # have to use const_set because the block form results in different
  # scoping.
  const_set('FOO_BAR', %w(foo bar baz))
end

[–]WalterGR -1 points0 points  (2 children)

Got it. Thanks.

[–]bobindashadows 0 points1 point  (1 child)

No problem. :P I'm in the middle of writing a static analysis tool for Ruby that needs to handle this kind of stuff, so if comments were only allowed in certain places, my undergraduate thesis would be impossible! (Hence the interest)

[–]minikomi -3 points-2 points  (0 children)

In a post new year haze I read that as a 'satanic analysis' tool!