Jump to content

Module talk:Yesno: Difference between revisions

From Fifth Empire Wiki
suppress script errors
Rewrite: new section
Line 131: Line 131:
:Yes, I agree that it doesn't really make sense. It's just in there to be 100% backwards-compatible with the current template. Those html comments should really have been removed from {{tl|yesno}} when it was made subst-able, which would have prevented us from having to second-guess whether they actually affect the output of any substitutions in any meaningful way. I suppose it's possible to download a database dump and to run a search on it to find out, but that's probably a bit much for my poor ailing laptop. Or we could just remove the comments and hope nothing breaks - I'm fairly sure that no-one would have written any template code that purposefully used them. There's no way to be sure that there is no code that was inadvertently written to be dependent on the error, though, and that worries me. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 18:24, 23 March 2013 (UTC)
:Yes, I agree that it doesn't really make sense. It's just in there to be 100% backwards-compatible with the current template. Those html comments should really have been removed from {{tl|yesno}} when it was made subst-able, which would have prevented us from having to second-guess whether they actually affect the output of any substitutions in any meaningful way. I suppose it's possible to download a database dump and to run a search on it to find out, but that's probably a bit much for my poor ailing laptop. Or we could just remove the comments and hope nothing breaks - I'm fairly sure that no-one would have written any template code that purposefully used them. There's no way to be sure that there is no code that was inadvertently written to be dependent on the error, though, and that worries me. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 18:24, 23 March 2013 (UTC)
::Drop it. Come what may. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 00:17, 24 March 2013 (UTC)
::Drop it. Come what may. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 00:17, 24 March 2013 (UTC)
== Rewrite ==
I've rewritten this as a pure Lua function. The new version is a lot simpler, and is also designed to work with Lua data types such as booleans, tables, and functions. Dragons flight's criticism above is well-founded, and giving up on the idea of replacing {{tl|yesno}} seemed like the best answer. The new version should hopefully retain the basics of {{tl|yesno}} while playing well with Lua, and allow meta-modules that deal with boolean-style wikitext input to be consistent with each other. (In other words, users won't have to remember whether it was "category=yes" or "category=true" - it should Just Work<sup>TM</sup>.) — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 14:37, 20 September 2013 (UTC)

Revision as of 14:37, 20 September 2013

Testcases and documentation

{| class="wikitable"
|+ Test Cases (via [[Template:Yesno/doc]])
|-
! Module output
! Template output
! Expected
|-
| {{#invoke:Yesno|yesno|yes}}
| {{yesno|yes}}
| yes
|-
| {{#invoke:Yesno|yesno|YeS}}
| {{yesno|YeS}}
| yes
|-
| {{#invoke:Yesno|yesno|Y}}
| {{yesno|Y}}
| yes
|-
| {{#invoke:Yesno|yesno|y}}
| {{yesno|y}}
| yes
|-
| {{#invoke:Yesno|yesno|no}}
| {{yesno|no}}
| ''(blank)''
|-
| {{#invoke:Yesno|yesno|}}
| {{yesno|}}
| ''(blank)''
|-
| {{#invoke:Yesno|yesno}}
| {{yesno}}
| ''(blank)''
|-
| {{#invoke:Yesno|yesno|¬}}
| {{yesno|¬}}
| ''(blank)''
|-
| {{#invoke:Yesno|yesno|purplemonkeydishwasher}}
| {{yesno|purplemonkeydishwasher}}
| yes
|-
| {{#invoke:Yesno|yesno|yes|yes=bacon}}
| {{yesno|yes|yes=bacon}}
| bacon
|-
| {{#invoke:Yesno|yesno|no|no=ham}}
| {{yesno|no|no=ham}}
| ham
|-
| {{#invoke:Yesno|yesno|blank= eggs}}
| {{yesno|blank= eggs}}
| 
|-
| {{#invoke:Yesno|yesno|no=ham}}
| {{yesno|no=ham}}
| 
|-
| {{#invoke:Yesno|yesno|blank= eggs|no=ham}}
| {{yesno|blank= eggs|no=ham}}
| 
|-
| {{#invoke:Yesno|yesno|¬|¬=sausage}}
| {{yesno|¬|¬=sausage}}
| sausage
|-
| {{#invoke:Yesno|yesno|purplemonkeydishwasher|def=cup-of-tea}}
| {{yesno|purplemonkeydishwasher|def=cup-of-tea}}
| cup-of-tea
|-
| {{#invoke:Yesno|yesno|purplemonkeydishwasher|yes=bacon}}
| {{yesno|purplemonkeydishwasher|yes=bacon}}
| bacon
|-
| {{#invoke:Yesno|yesno|purplemonkeydishwasher|def=cup-of-tea|yes=bacon}}
| {{yesno|purplemonkeydishwasher|def=cup-of-tea|yes=bacon}}
| cup-of-tea
|-
| {{#invoke:Yesno|yesno|yes|yes=no|no=yes}}
| {{yesno|yes|yes=no|no=yes}}
| no
|-
| {{#invoke:Yesno|yesno|no|yes=no|no=yes}}
| {{yesno|no|yes=no|no=yes}}
| yes
|-
| {{#invoke:Yesno|yesno| no |no=no}}
| {{yesno| no |no=no}}
| no
|}
Note: Pre tags added to suppress script errors. — Mr. Stradivarius ♪ talk ♪ 14:25, 20 September 2013 (UTC)

As you can see, the template does not behave exactly as its documentation claims it does. I was not sure which to regard as authoritative: the ideal or actual implementation. I ultimately went with the former. Removing and not any from the Lua code will make the module behave like exactly like the template.

--Ori.livneh (talk) 10:46, 28 February 2013 (UTC)

Just needs to handle spaces in the params better. -- WOSlinker (talk) 11:41, 2 March 2013 (UTC)
Thanks. Fixed. I moved your test case to the table above. --Ori.livneh (talk) 05:58, 3 March 2013 (UTC)
Yesno has ~8M transclusions. No question it should handle the legacy 1:1. Test it. -DePiep (talk) 22:31, 11 March 2013 (UTC)

The documentation is wrong. The "egg" example assumes thet the input value is blank. But in the code examples the input parameter is omitted. Compare:

  • {{yesno|blank= eggs|no=ham}} →
  • {{yesno||blank= eggs|no=ham}} → eggs

This is what is actually documented:

  • {{yesno|blank= eggs|no=ham|¬=bread}} → bread
I have changed the documentation. Not the table above. -DePiep (talk) 13:16, 23 March 2013 (UTC)

Why?

{{yesno}} is quite simple, so I'm not sure if there is a point in replacing it with functionally equivalent Lua. There are many cases where Lua can be much faster and easier to read, but I'm not sure that is the case here. In fact, because of the slight overhead with #invoke, simple parser functions can actually be slightly faster than the equivalent Lua. I haven't tested that here, but I wouldn't be surprised if there is no performance advantage in a case like this. Seems like a strange template to target for Lua conversion. Dragons flight (talk) 14:57, 12 March 2013 (UTC)

See also

  • {{[[Module:{{{1}}}|#invoke:{{{1}}}]]|function}}

test failed

Template:Resolved One fail found in unit test: value "1= ¬ " (with whitespace). Reason:whitespace not removed before this check. Possible solution; treat '¬' as a character, separate from nil. (if val == nil or val == '¬' then ...). -DePiep (talk) 11:54, 23 March 2013 (UTC)

also fails when 1=0.0
Suggestion: change val = args[1] into val = tostring(args[1]). To prevent treating "000" as number. -DePiep (talk) 14:09, 23 March 2013 (UTC)

Solved. Module is changed, although the numeric issue different from my (incorrect) suggestion. -DePiep (talk) 14:19, 23 March 2013 (UTC)

Thanks for putting the test cases up. I learned something new about ParserFunctions. :) Still seems to be slower than the old template version though. — Mr. Stradivarius ♪ talk ♪ 14:38, 23 March 2013 (UTC)

Null?

The code now says <syntaxhighlight lang="text" class="" style="" inline="1">no = "<!-- null -->"</syntaxhighlight>. But a "" (nullstring) is not the same as ASCII NULL (0x0000). Also I see no use for adding wiki comment to code this way. -DePiep (talk) 17:47, 23 March 2013 (UTC)

Yes, I agree that it doesn't really make sense. It's just in there to be 100% backwards-compatible with the current template. Those html comments should really have been removed from {{yesno}} when it was made subst-able, which would have prevented us from having to second-guess whether they actually affect the output of any substitutions in any meaningful way. I suppose it's possible to download a database dump and to run a search on it to find out, but that's probably a bit much for my poor ailing laptop. Or we could just remove the comments and hope nothing breaks - I'm fairly sure that no-one would have written any template code that purposefully used them. There's no way to be sure that there is no code that was inadvertently written to be dependent on the error, though, and that worries me. — Mr. Stradivarius ♪ talk ♪ 18:24, 23 March 2013 (UTC)
Drop it. Come what may. -DePiep (talk) 00:17, 24 March 2013 (UTC)

Rewrite

I've rewritten this as a pure Lua function. The new version is a lot simpler, and is also designed to work with Lua data types such as booleans, tables, and functions. Dragons flight's criticism above is well-founded, and giving up on the idea of replacing {{yesno}} seemed like the best answer. The new version should hopefully retain the basics of {{yesno}} while playing well with Lua, and allow meta-modules that deal with boolean-style wikitext input to be consistent with each other. (In other words, users won't have to remember whether it was "category=yes" or "category=true" - it should Just WorkTM.) — Mr. Stradivarius ♪ talk ♪ 14:37, 20 September 2013 (UTC)