Talk:Useless instructions

From Rosetta Code

Leaving this as a draft for now since I'm not sure if this applies to anything that isn't assembly. --Puppydrum64 (talk) 04:01, 16 October 2021 (UTC)

if true {} else { code that is never executed }

Constructs like the above (suitably formatted for the language in question) could be useful to "temporarily" stop the execution of the else part during development. Although the compiler doesn't complain (though issuing an "unreachable code" warning would presumably be not that hard) do we know whether it actually generates code for the else part? --Tigerofdarkness (talk) 11:02, 16 October 2021 (UTC)

Of the 3 languages I've added, Go and C (using GCC) optimize away the else part.
However, the Wren compiler which is single pass does no optimizations and consequently does produce bytecode for the else part which is then interpreted by the VM. --PureFox (talk) 14:42, 16 October 2021 (UTC)
I had forgotten about optimizing compilers removing unreachable code; I'd consider an if true {} else {} scenario to be valid since you're not forbidden from writing it, even if the compiler throws it away during the conversion process. --Puppydrum64 (talk) 17:32, 16 October 2021 (UTC)

Meaning of useless in English

The meaning of useless is not as used in the task description. According to oed the formal meaning is "Not fulfilling or not expected to achieve the intended purpose or desired outcome". In what way does 'if true then ... else ...' mot achieve the intended or desired outcome? The task description says "Showcase an instruction or function built into the language, that is made redundant by another instruction also built into the language". In F# there are a number of operators built in because they are in the ML language specification but are replaced in F# by preferred operators. In ML the string concatenation operator is ^, you could write "Nigel "^"Galloway" in F# and the result would be string concatenation as expected, but in F# it would be attract disapprobation not to write "Nigel "+"Galloway". This seems closer to what the task description asks for.--Nigel Galloway (talk) 14:59, 25 March 2022 (UTC)

One thought that struck me is x = x. It could do nothing, it could prove x is not unassigned, it could be an expression that fails to work as expected for or proves it is NaN, and even, as x := x in Phix parameter passing, the two x could refer to two different things. --Pete Lomax (talk) 04:04, 26 March 2022 (UTC)