Talk:Useless instructions: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 8: Line 8:


: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. --[[User:PureFox|PureFox]] ([[User talk:PureFox|talk]]) 14:42, 16 October 2021 (UTC)
: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. --[[User:PureFox|PureFox]] ([[User talk:PureFox|talk]]) 14:42, 16 October 2021 (UTC)

:I had forgotten about optimizing compilers removing unreachable code; I'd consider an <code>if true {} else {}</code> scenario to be valid since you're not forbidden from writing it, even if the compiler throws it away during the conversion process. --[[User:Puppydrum64|Puppydrum64]] ([[User talk:Puppydrum64|talk]]) 17:32, 16 October 2021 (UTC)

Revision as of 17:32, 16 October 2021

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)