Template talk:Ship prefix

(Redirected from Template talk:Ship prefix/doc)
Latest comment: 11 years ago by Tupsumato in topic Request for addition: MS, MV

This is the discussion/talk page for: Template:Ship prefix.

Created edit

The Template:Ship_prefix was created by long-term user Kotniski, on 22 September 2010, to get the length of a ship-name prefix (such as SS=2, HMS=3, USNS=4,...). -Wikid77 (talk) 14:31, 31 December 2010 (UTC)Reply

Rewrite for reduced nesting edit

31-Dec-2010: The Template:Ship prefix can be rewritten to be faster and use far less in wiki-server resources by just comparing the first 3 characters of a ship's name to short ship codes, then compare the first 5 characters of a ship's name to 4/5-character ship codes. The faster logic, used in {{Ship_prefix/sandbox}}, is the following:

{{#expr: 0 {{
#switch:{{padleft:|3|{{{1|RMS TITANIC}}} }}
  | SS = +2
  | ARA|HMS|SMS|TCG|USS = +3
}}{{#switch:{{padleft:|5|{{{1|RMS TITANIC}}} }}
  | USNS|RMAS|USAS = +4
  | USAFS|HMNZS = +5
  | HMAS = +4
}} }}<!--endexpr-->

The prior version had been using template {{First word}} which had not been optimized to avoid extra processing of strings. The use of {First_word} caused {Ship_prefix} to require 27 levels of expansion depth, whereas the faster logic (using 2 instances of #switch) needs only 3 levels of the "expansion depth limit" (40 levels during 2009-2010). -Wikid77 (talk) 14:31, 31 December 2010 (UTC)Reply

Nice one! Will you be moving the new logic to the live template?--Kotniski (talk) 15:46, 31 December 2010 (UTC)Reply
  • DONE. After confirming the new /sandbox would run 105x faster, I copied the new logic into the live template. We are still working on making other string templates faster for short strings. -Wikid77 10:57, 2 February 2011 (UTC)Reply

Testcases edit

Because there are only a few ship prefixes handled, all the testcases are listed in the table below.

# prefix {Ship_prefix} {Ship_prefix/sandbox}}
1 SS 2 2
2 MS 2 2
3 MV 2 2
4 ARA 3 3
5 HMS 3 3
6 RMS 3 3
7 SMS 3 3
8 TCG 3 3
9 USS 3 3
10 USNS 4 4
11 RMAS 4 4
12 USAS 4 4
13 HMAS 4 4
14 HMC 3 3
15 HMCS 4 4
16 USAFS 5 5
17 HMNZS 5 5
18 SSBAD 0 0
19 EMPTY 0 0
20 1 0 0

In a larger template, those testcases would be listed in subtemplate {Ship_prefix/testcases}, as the typical subpage for showing such testcases. However listing the cases here is shorter and helps to explain the template's operation with examples. -Wikid77 14:31, 31 December 2010, revised Wikid77 (talk) 03:07, 17 August 2011 (UTC)Reply

I have editied both the table above and {{Ship prefix/sandbox}}. In the table I have added test cases 19 and 20 which test for an empty parameter and a single-character parameter. I added the empty test because at the top of the {{Ship prefix}} (and {{Ship prefix/sandbox}}) is the number 3. I presume that this comes from {{{1|RMS TITANIC}}}. Does it? Why doesn't test case 19 {{Ship_prefix|}} and {{Ship_prefix/sandbox|}} also produce a 3? That it doesn't is a good thing but I am curious.
Now that {{First word}} has a Lua implementation, perhaps {{Ship prefix/sandbox}} should become the new version of {{Ship prefix}}.
Trappist the monk (talk) 16:39, 13 March 2013 (UTC)Reply

Shouldn't RMS too be in the prefix list? edit

I've noticed that all the ships like RMS Queen Mary, RMS Queen Elizabeth 2 etc. come up with the ship name in the title not correctly italicised. Is it because 'RMS' is missing from the prefix list? I was tempted to add it, but have never edited a template and don't want to screw things up unnecessarily, if somebody can please advise. --Giuliopp (talk) 23:24, 20 January 2011 (UTC)Reply

  • RMS was added on 22 January 2011. -Wikid77 10:57, 2 February 2011 (UTC)Reply

Request for addition: MS, MV edit

I noticed that the names of the ships MS St. Louis and MV American Tern are italicized in the body of their articles but not in their titles. Should the prefixes MS and MV be included in this template? —Cheng  00:52, 23 March 2011 (UTC)Reply

added. Finavon (talk) 15:39, 2 April 2011 (UTC)Reply
Thanks, Finavon. I recorded this in the history log (in the template comments). —Cheng  19:38, 2 April 2011 (UTC)Reply

Can we also add AHTS to the list? (See AHTS listed at Ship prefix.) Thanks! Wilhelm Meis (☎ Diskuss | ✍ Beiträge) 17:56, 30 March 2013 (UTC)Reply

I have rarely seen AHTS used as a prefix. Could we do without adding yet another prefix? I'd rather go without them. Tupsumato (talk) 11:05, 31 March 2013 (UTC)Reply
Ah, I guess it's used at least for some AHTS ships. Tupsumato (talk) 11:11, 31 March 2013 (UTC)Reply

Problem with Canadian ship names edit

Having noticed that article titles of ships belonging to the Royal Canadian Navy (e.g. HMCS Sarnia (J309)) aren't properly italicized, I narrowed it down to the fact that

{{ship prefix|HMCS Sarnia (J309)}} = 7

when it should have been 4. I am, to say the least, no expert on template syntax, but I think the root of the problem is that we have a shorter prefix, "HMC", listed before "HMCS" in the template code. Favonian (talk) 22:20, 15 August 2011 (UTC)Reply

Undid the "HMC" for now, until a proper fix is found. It only pertains to five revenue cutters of one class anyhow. LeadSongDog come howl! 22:01, 16 August 2011 (UTC)Reply
  • DONE. I have re-added "HMC" with a special #ifeq check versus "HMCS" to avoid matching both. Currently, the prefix results are:
  • {{ship prefix|HMCS Sarnia (J309)}} → 4
  • {{ship prefix|HMC Sarnia (J309)}} → 3
The logic will nest 1 level deeper (of the MediaWiki expansion-depth limit=40?) only when "HMC" or "HMCS" is in the ship name. The depth has been kept low to allow {Ship prefix} to be used inside any complex template, if needed. -Wikid77 (talk) 02:59, 17 August 2011 (UTC)Reply
Thank you! Works like a charm. Favonian (talk) 19:50, 17 August 2011 (UTC)Reply