Template talk:Sfnp/archive 1

Latest comment: 13 years ago by Benwing in topic Several thoughts


Several thoughts

  1. Should we rewrite {{sfn}} so that it uses this style? Is this more standard? I think it's worth a discussion over at {{sfn}}. I've been thinking that the "{{harvtxt}}" style would look better in {{sfn}} for some time now and have been considering making the change. Apparently we think alike.
  2. If there is a lot of resistance, and it looks like this fork is here to stay, we should add {{sfnp}} to {{harvard citation documentation}}. This will help editors to find it when new problems or issues are discovered, when bots are designed, and etc.. I think it should be treated similarly to {{harvcol}}: as a variation on the more standard {{sfn}}.
  3. I noticed that this template transcludes another template, {{sfnp/date}}. WikiMedia's transclusion technology is very inefficient at the current time and people have noticed that articles with high number of transclusions can load extremely slowly. Using a "subtemplate" effectively doubles the load time. In a large article this can be noticeable. This is why all the other templates in the {{harv}} family don't use subtemplates. (It's a pain, because it would be great to share code between all of them, but that's the way it is for now.)

--- CharlesGillingham (talk) 16:09, 10 May 2011 (UTC)

Thanks for commenting. I'm not sure about rewriting {{sfn}}; there may be people using the current style who prefer it. We should probably ask there.
I was definitely going to add {{sfnp}} to {{harvard citation documentation}}, although I was also thinking of creating {{harvp}} that outputs in the same format as {{sfnp}} does, in place of having to use {{harvtxt}} and manually specify the page number. I was also thinking we should have {{sfncol}} and {{sfncolp}} to do the equivalents using colon page number notation, along with {{harvcolp}}. Thoughts?
As for using template transclusions, in this case it turned out to be easy to rewrite without {{sfnp/date}}. In general, though, I wonder if it's worth the increase in confusion caused by trying to avoid subtemplates. The comment on WP:SUBST says don't worry about performance (WP:PERF) except in extreme cases. Have you actually seen cases where substing a subtemplate really makes that much difference? BTW doesn't the server cache the results of rendering pages?

Benwing (talk) 01:32, 11 May 2011 (UTC)

One other question. What is the use of a construct like {{#if:||{{{2|}}}}} in place of just {{{2|}}}? I copied these from {{harvtxt}} but I can't for the life of me see the point of it. Benwing (talk) 01:32, 11 May 2011 (UTC)
I replied over at {{sfn}} on the major issues. On your other questions:
The "slow load time" issue has been discussed in many places. I would ask User:Eubulides, who created {{vancite book}} and {{vcite book}} in part to address this issue. He could probably point you to some discussions where there is concrete data. You could also ask User:SlimVirgin. She is very critical of citation templates and slow load time is one of the strongest arguments against them. She would be able to point you towards discussions where citation templates are criticized.
Yuck yuck yuck. Arguing against something that makes high-level implementation easier and more error-free on the basis of slow implementation is (from a computer science perspective) a classic mistaken belief and a cause of enormous amounts of real-world grief. It's for this reason that Donald Knuth supposedly said:

"Premature optimization is the root of all evil."

The proper solution is to fix the underlying mediawiki software to be faster.
The idiom {{#if:||{{{2|}}}}} strips leading and trailing blanks from {{{2}}}. ---- CharlesGillingham (talk) 17:23, 11 May 2011 (UTC)
This is also nasty. The horridness of template coding is actually inspiring me to create a nicer template language along with a converter that converts to regular template language. I hope eventually to get this added as a standard part of Wikipedia, but in the meantime the nice code can be added as a comment, and the nasty code added after it, at first manually by cutting/pasting, later through a gadget that converts with a single button click. That way you can insert whitespace in your code without having to worry about the whitespace appearing in the output, and just write e.g. $2 instead of {{#if:||{{{2|}}}}}, or something like $$2 if you want leading/trailing whitespace preserved, etc.
Here's an example of how you would write the code for {{sfn}}:
{{#tag:ref|
  %% Link to citation template
  [[#CITEREF $1 $2 $3 $4 $5
  |             
  %if $5 (($1 et al. $5))                %% 4 or more authors
  %elif $4 (($1, $2 & $3 $4))        %% 3 authors
  %elif $3 (($1 & $2 $3))            %% 2 authors
  %else (($1 $2))                        %% 1 author
  ]]

  %% Location or page number(s)
  (%if $loc ((, $loc))
   %elif $p ((, p. $p))
   %elif $pp ((, pp. $pp))
  )
  .

  %% Footnote name
  |name=FOOTNOTE $1 $2 $3 $4 $5 $p $pp $loc
}}
When run through the converter program, the output is the same as the actual code of {{sfn}}, but it's much easier to read and write, and much less error-prone. The basic idea is that whitespace isn't significant except in double parens ((...)) or when escaped with a backslash; so you're free to space out the code to make it look nice. Single parens are used for grouping; the main use for this is in conjunction with constructs like %if, where the arguments need to be either a single word or a balanced expression. In this case the parens around the second %if aren't actually needed but can be useful to show more clearly the extent of the conditional.
There's also %def, which defines a macro that will be substituted inline; this lets you do the equivalent of e.g. {{sfnp/date}} without actually increasing the load time, since the substitution happens when the code is converted to normal template code. Benwing (talk) 02:48, 13 May 2011 (UTC)