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

Use "method" instead of "variable" for methods #2196

Closed
10 tasks done
jmooring opened this issue Aug 13, 2023 · 5 comments · Fixed by #2627
Closed
10 tasks done

Use "method" instead of "variable" for methods #2196

jmooring opened this issue Aug 13, 2023 · 5 comments · Fixed by #2627
Assignees

Comments

@jmooring
Copy link
Member

jmooring commented Aug 13, 2023

Recently, I spent a significant amount of time attempting to define the "language of Hugo" while creating a glossary of terms. This was a challenging exercise, as I had to reconcile current usage with terms that are specific and (mostly) narrowly defined. This is comparable to, but much less time-consuming than, writing the Go language specification ten years after the language was first released.

Although our language choices have, for the most part, been logical and consistent, I think it's time to use the term "method" instead of "variable", with the exception of variables initialized within template actions (e.g., {{ $myVar := 42 }}).

Justification:

  1. Things like "page variables" are not variable. They are immutable within a template.
  2. Our current usage is confusing. We call .Page.Title and .Page.IsSection variables, but we call .Page.RenderString a method.
  3. This would cleanup the "Functions" section. Although we call .Page.RenderString a method, we document it under the "Functions" section.

We've already done this for .Pages. Although under the "Variables" section, the title is "Pages methods".

Tasks

Completed on or before 4 Nov 2023:

  • Namespace all functions (effort: medium)
  • Create Methods section (effort: low)
  • Move methods (anything that begins with a dot) from Functions to Methods (effort: low)
  • Add and namespace methods on Page, Site, etc. (effort: high)
  • Create quick reference guides for functions and methods (effort: medium)
  • Add notice to all Variables pages, pointing readers to the Methods quick reference guide and the Methods section

Completed on 19 Feb 2024:

  • Remove Variables section after a few months

Completed on 8 Mar 2024:

Completed on 15 Jun 2024:

  • Ensure consistent use of "function", "method", and "variable" throughout the documentation (effort: high)
  • Use "argument" instead of "parameter" when referring to function, method, and shortcode arguments (effort: medium)

I've been thinking about doing this for a while: #1639

@jmooring jmooring self-assigned this Aug 13, 2023
@bep
Copy link
Member

bep commented Aug 14, 2023

So, it's still very much on my TODO list to get an auto generated reference section happening in Hugo. The recent config consolidation was a important part of this, and then I may have gotten distracted.

With that setup you would get this "Reference":

  • Function namespaces
  • Objects (Page, Site etc.)
  • Configuration
  • Go Types

While it's technically correct to say that Hugo's template functions are methods, they (mostly) behave like a function, and none of them have a "." context that the user needs to worry about, and I think the distinction between function and method is something that we need to preserve.

So with that, I would not spend high amount of effort on things that would fall into the "Reference" category above.

@jmooring
Copy link
Member Author

jmooring commented Aug 14, 2023

I think the distinction between function and method is something that we need to preserve

I agree, and that is consistent with the glossary of terms.

What I am asking is, can we stop referring to things like .Page.IsHome and .Page.Title as variables, and call them methods instead?

@chrillek
Copy link

  1. Things like "page variables" are not variable. They are immutable within a template.

Why not call them "properties"? That doesn't imply mutability (I think), but still permits to discern those from functions like RenderString.

@jmooring
Copy link
Member Author

They are not properties. They are methods. For example:

  1. .RenderString is not a function. It is a method on the .Page object that renders markdown to HTML.
  2. .Title is a method on the .Page object that returns the front matter title field
  3. .Sections is a method on the .Site object that returns a collection of all the top level sections.

@chrillek
Copy link

Well, if they are methods… I doubt that kind of terminology helps clarify things, though. A getter like .Title behaves in every way as a read-only property. Whereas .RenderString acts on its parameter(s).

If you replace (most) "variable" by "method" the intro to Site variables will read:

Site methods
Many, but not all, site-wide variables are defined in your site’s configuration. However, Hugo provides a number of built-in methods for convenient access to global values in your templates.
The following is a list of site-level (aka “global”) methods. Many of these methods are defined in your site’s configuration file, whereas others are built into Hugo’s core for convenient usage in your templates.

I do not think that that makes any sense, at all. The current wording is a lot less complex and easier to understand. Even if it might not be technically correct.

jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 3, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 3, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 4, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 4, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 5, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 5, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 6, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 6, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 8, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 8, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 9, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 9, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 11, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 11, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 13, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 13, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 13, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 13, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 15, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 15, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 15, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 15, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 17, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 18, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Feb 18, 2024
bep pushed a commit that referenced this issue Feb 19, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Mar 10, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Mar 10, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Mar 10, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue May 25, 2024
- Refer to page methods instead of page variables
- Rework 404 template page
- Remove table of contents page in favor of /methods/page/tableofcontents

Improves gohugoio#2196
jmooring added a commit to jmooring/hugo-docs that referenced this issue May 26, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue May 26, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue May 26, 2024
jmooring added a commit that referenced this issue May 26, 2024
jmooring added a commit that referenced this issue May 26, 2024
jmooring added a commit that referenced this issue May 26, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Jun 12, 2024
- Remove erroneous statements
- Document use of global, page, and remote resources
- Explain that data can be used to both augment and create content
- Simplify examples

Improves gohugoio#2196
jmooring added a commit to jmooring/hugo-docs that referenced this issue Jun 15, 2024
jmooring added a commit to jmooring/hugo-docs that referenced this issue Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants