Using named rules instead of defining phrases in extensions

I gather from this suggestion on uservoice that rules in an extension should all have names to make it easier to change them.

Given that, is it preferred to use named rules instead of defining new phrases where possible?

To modify an example from this post:

Is this

[code]When play begins (This is the Beginning the Game Rule):
follow the do whatever rule;
[more stuff]

This is the do whatever rule:
if X:
do something;
otherwise if Y:
[etc.] [/code]

generally preferred to this

[code]When play begins (This is the Beginning the Game Rule):
do whatever;
[more stuff]

To do whatever:
if X:
do something;
otherwise if Y:

even when there are no strings?

This isn’t really an either/or question, because you can also give names to phrases, e.g.:

To do whatever (this is the whatever doing rule):

When I try “The Alternative Rule substitutes for the Whatever Rule in Extension by Author”, it doesn’t work if the original is a phrase.

Should it? (Maybe I’m just wording it wrong?)

Edit: removed quotation marks around extension title.

I suppose the game author could just write their own “To do whatever” phrase in the source, which looks like it automatically overwrites the original. That might actually be easier than replacing a named rule.

Yes, but overloading the phrase is vulnerable to the order of instructions in the source code. I.e., if the user’s source code is:

[code]To do whatever:
say “My custom text.”

Include Extension by Author.[/code]

…then the extension will override the user’s attempt at overloading the phrase.

Hmm. Ok. Then it seems like it’s either “convert newly defined phrases to rules (with names)” or “leave game authors to their own devices when it comes to modifying defined phrases.”

It depends on what the phrase does. You’ll have to look at it from the extension’s user’s perspective. Is the phrase such that it’s reasonable to assume that someone might want to change it? Is it used only internally or is it supposed to be used directly by the author? Can the (internal) rules that use it be easily changed to use some other phrase instead?

For example, if you have:

To decide which number is the third power of (X - a number):
    decide on X * X * X.

…then it’s very unlikely that someone would need to change the mathematical definition of a third power. They’ll more likely want to change rules to use some other phrase instead.

On the other hand if you have:

To tamper with a live wire:
    now the fuse is blown;
    end the story in death.

…then it’s very likely that someone might want something else to happen instead, so the phrase should be a named rule instead.

That seems reasonable. Thanks, all!

I don’t have Inform available to test, but if responses cannot be replaced in a phrase-as-named-rule, then that sounds like a bug that should be reported, no?

To do whatever (this is the doing whatever rule): say "My custom text." (A)

This example doesn’t compile.

There are other strings that can’t be assigned letters, either. Using Basic Screen Effects

center "[player's surroundings]" at row 1. (A)

won’t compile, even inside a named rule.

I don’t know if it amounts to a bug report or a feature request, but it seems like it’d make things more convenient to be able to label strings in other circumstances.

Thanks; that definitely seems like a bug, since a named phrase is a named rule (or, if it isn’t, the word “rule” should be dropped from the instruction that creates one).

I wouldn’t expect that example to compile, though, since the (A) is outside the rule terminator (i.e., the period).

It gets confused if you put it inside:

This would certainly make things easier–then the game author could just replace the phrase if needed, and extension authors could use named phrases freely, even ones that they think game authors might want to modify.

It’s not quite the same. You don’t actually need the word ‘rule’ in there, I’m actually slightly surprised it’s allowed–in the documentation they’re usually named as participles.

To decide what number is twice (N - a number) (this is doubling):
    decide on N + N.

A named phrase is not a rule. Sorry.

To do whatever (this is whatevering):
	do nothing.

It can’t be replaced using the rule-replacement tools. It can’t be redefined at all, looks like.

If you want flexibility in your extension, use named rules.

It sounds like the “rule” should throw a compiler error when used with a named phrase. I think I learned of the ability to write “rule” there from some piece of official documentation and (if so) it was obviously misleading.

It looks like the letter goes right after the string, like this:

center "[player's surroundings]" (A) at row 1.

One thing not covered in the above discussion is that phrases can often be directly embedded in their I6 code, whereas rules always are compiled to separate I6 functions. So it will be slightly better performance to use phrases when the advantages of rules are not needed. If they are phrases involving block values the performance difference will be more noticeable. (Because I think the rule would have the overhead of initialising new block value local variables.)

Perfect, thanks! It never occurred to me to try that.

What’s a block value?