4
\$\begingroup\$

I couldn't find any consensus on this on meta for a while, and this seems to be particularly helpful when answering challenges. Should swapping truthy and falsy be allowed by default, when answering such challenges, unless overridden?

For example, when testing primality, one could output a falsy value for primes and a truthy value for non-primes. Is this allowed by default?

\$\endgroup\$
  • 2
    \$\begingroup\$ I don't have the time to write an answer now, but I believe that swapping should be allowed. As per how the site usually decides, negating a determined condition only adds bytes unnecessarily to the answer, and detracts from the overall quality of the challenge. That being said, one could argue that part of golfing is figuring out how to incorporate negation into your answer, rather than simply calculating the converse and negating it. I think we could benefit from using language like "decide if X is prime", since that could allow swapping and consistent values. \$\endgroup\$ – Conor O'Brien Mar 22 '18 at 14:49
  • 5
    \$\begingroup\$ This question makes no sense at all unless we assume that there is already a default that decision-problem challenges don't need to specify their output format, and that in that case answers may use truthy/falsy. However, the tag wiki says nothing about such an assumption, and nor does this question. \$\endgroup\$ – Peter Taylor Mar 22 '18 at 16:56
12
\$\begingroup\$

Defaults apply by default (duh), but they do not override the challenge specification. In contrast, the challenge specification can override our defaults in any way it deems fit. Thus, all answers should do what the challenge asks for.

If the challenge asks for a truthy value for primes and a falsy value for non-primes, output a a truthy value for primes and a falsy value for non-primes.

However, if the challenge only asks for two consistent and distinct outputs for primes and non-primes and specifies no further restrictions, truthiness no longer matters.

\$\endgroup\$
2
\$\begingroup\$

You should ask the OP

Consensus exists to help us deem what we think is appropriate for all challenges, not to override what challengers say. The challengers are probably much better equipped to make specific decisions about what is best for their challenge than for us to make sweeping defaults about all challenges.

Note that for decision problems where two consistent values are requested, (which seem to be becoming more popular because of issues with truthy v. falsy), swapping values is perfectly acceptable just by the definition of the challenge.

\$\endgroup\$
1
\$\begingroup\$

Allow swapping them by default

Having to negate the truthiness of a certain value sometimes only adds unnecessary bytes to a submission. Unless explicitly overridden in the challenge body, swapping truthy / falsy values should be allowed by default.

Note to challenge writers – You may want to read this meta discussion about replacing truthy / falsy values (which is a concept which some languages don't have) with other methods, suitable for decision-problems.

\$\endgroup\$
  • \$\begingroup\$ I don't think we should even allow a meta consensus to override parts of the challenge specification. If the challenge asks for a truthy value, returning anything but a truthy value makes the answer invalid. \$\endgroup\$ – Dennis Mar 22 '18 at 17:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .