Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] Revision for XML::Node.add_child #3431

Closed

Conversation

BurdetteLamar
Copy link
Contributor

No description provided.

@BurdetteLamar
Copy link
Contributor Author

@flavorjones, much that follows will depend on this PR (b/c the example code will be cited).

Copy link
Member

@flavorjones flavorjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I like the idea of having a real-world document that the examples can demonstrate upon.

I've asked some questions and made some small suggestions. Thank you again for taking the time to work on Nokogiri! I really appreciate it.

#
# Also see related method +<<+.
# :call-seq:
# add_child(object) -> object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been gradually introducing a documentation convention to give a brief overview of arguments and argument types, which I'd like to ask you to use (or improve upon).

Good examples of this convention are in this file, and applying it here might look like:

[Parameters]
- +object+ (String, Node, NodeSet) The Node or Nodes to be added as children of this node. A String will be parsed as a fragment and the resulting NodeSet will be added as children.

followed by the prose explanation and examples below. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you're suggesting fits well with my own personal philosophy. (That's how I wrote in various DEC programmer's reference manuals back at the Dawn of Time.)

However, I think you should consider the Ruby Documentation Guide, first drafted by @jeremyevans and often discussed and augmented since. It represents consensus in the Ruby community, which I think has value in itself. But it also gives a consistent "Feel" to the Ruby documentation that readers might appreciate also finding in the gems' documentation.

But of course, "your call."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean this section in the Documentation Guide? I don't find it specifies much of anything beyond "use a labeled list", but to be clear I'm fine with that if that's what you want to go with.

The general principal is: give a brief summary of arguments and their expected types. I'm not finicky about the particulars of the style we use to present it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the "if necessary" bit in that section makes me groan a bit. I get it, we don't need to over-specify things for simple methods with simple arguments.

But all of these Node methods in particular take complex arguments (could be a Node, could be a NodeSet, could be a String that is cast as a NodeSet via fragment parsing) and so, yes, I think for those kinds of methods, documenting the arguments is necessary. WDYT?

@BurdetteLamar
Copy link
Contributor Author

@flavorjones, as guidance going forward: You prefer '<root></root>' to <root/>?

@flavorjones
Copy link
Member

@BurdetteLamar Oh! I don't actually have any feelings here. I suppose if it's XML then <root/> is fine! 😃

@BurdetteLamar BurdetteLamar marked this pull request as draft February 20, 2025 17:01
@BurdetteLamar
Copy link
Contributor Author

Marked as draft, while I make a little more consistent.

@BurdetteLamar BurdetteLamar marked this pull request as ready for review February 20, 2025 17:19
Copy link
Member

@flavorjones flavorjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, adding the examples is an obvious improvement over what was there.

I would still like to have a brief summary of the types that the input argument can be. Again, I don't feel strongly about the style used to present it, but I do feel strongly that the types and behaviors are complex enough that they justify being summarized very briefly for users who are looking for API reference material and not an explanation. We need to provide both, I think.

#
# Argument +object+ is one of:
#
# - A Nokogiri::XML::Node (of any kind).
Copy link
Member

@flavorjones flavorjones Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"any kind" isn't technically true, it must be a Node but also cannot be a Document or an Attr.

There are also additional constraints applied based on the type of self, which probably aren't worth going into detail about here.

Maybe we can just change drop the "(of any kind)".

# #(Element:0x5992dc { name = "bar", children = [ #(Text "BAR")] }),
# #(Element:0x5994bc { name = "baz", children = [ #(Text "BAZ")] })]
#
# Raises ArgumentError if +object+ is not a node, a nodeset, or a string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think information about return types, exceptions, and blocks should be the top of the docstring near the information about argument types.

#
# Also see related method +<<+.
# :call-seq:
# add_child(object) -> node or nodeset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When possible, I'd like to use the proper constant name when we reference classes.

Suggested change
# add_child(object) -> node or nodeset
# add_child(object) -> Node or NodeSet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, different from what's seen in Ruby core and standard libraries. And again, I'll do as you say.

#
# - A Nokogiri::XML::Node (of any kind).
# - A Nokogiri::XML::NodeSet.
# - A string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# - A string.
# - A String.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

#
# Appends child nodes to +self+.
#
# Argument +object+ is one of:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, reading the previous documentation, I'm now realizing that object could also be a DocumentFragment

@BurdetteLamar
Copy link
Contributor Author

As above, I'll do as you say. Thanks for taking time on this PR, as it establishes what we're trying to do.

@BurdetteLamar BurdetteLamar marked this pull request as draft February 20, 2025 22:46
@BurdetteLamar
Copy link
Contributor Author

Converting to draft (again), while I mull things over.

@BurdetteLamar
Copy link
Contributor Author

@flavorjones, I have greatly modified this PR. It can (I hope) serve as a model for what's to come.

A few points:

  • This now has a "reference" style of opening, consisting of a 1-line description, Arguments:, Returns:, Raises:. Other methods may also need Options:, Yields:.
  • The first example (arg is a Node) carries the main load; it shows in great detail how the method works. The other examples (other arg types) have less detail.

@BurdetteLamar
Copy link
Contributor Author

@flavorjones, let's wait on this. I've only now discovered CONTRIBUTING.md@Documentation)(!). I will study it, and maybe offer some ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants