Useless instructions: Difference between revisions

m
syntax highlighting fixup automation
(J)
m (syntax highlighting fixup automation)
Line 13:
<code>CMP #0</code> is nearly completely useless, as most 6502 instructions do this implicitly. It can be handy when you need to check equality to zero after a different register was altered, and in that scenario using <code>PHP/PLP</code> to save and restore the condition codes would be impractical, but these situations are few and far between.
 
<langsyntaxhighlight lang="6502asm">myLoop:
;do stuff here
dex
;cpx #0 ;this isn't needed since the zero flag will be set if x=0
bne myLoop ;if x != 0, jump back to myLoop</langsyntaxhighlight>
 
=={{header|68000 Assembly}}==
Line 58:
As this sample shows, Algol 68G has only three sies of integer. The precission of LONG LONG INT can be specified by a pragmatic comment. The value shown here is the default.
<br>Algol 68G has 64 bit INT and 128 bit LONG LONG INT. In previous versions, INT was 32 bit and LONG INT had a precision of 35 decimal digits.<br>
<langsyntaxhighlight lang="algol68">print( ( long long long max int, newline ) );
print( ( long long max int, newline ) );
print( ( long max int, newline ) );
Line 69:
short short short short short short short short short short
short short short short short short short short short short
short short short short short short short short short short max int, newline ) )</langsyntaxhighlight>
{{out}}
<pre>
Line 84:
=={{header|Applesoft BASIC}}==
Many ways of printing an empty string.
<langsyntaxhighlight lang="gwbasic">?;:?"";:?"";"";:?;;;;;</langsyntaxhighlight>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f USELESS_INSTRUCTIONS.AWK
BEGIN {
Line 98:
delete array
}
</syntaxhighlight>
</lang>
 
=={{header|C}}==
Line 107:
Another keyword which is teetering on redundancy is 'register' whose purpose is to suggest to the compiler that it should store a variable in a CPU register rather than memory. However, modern optimizing compilers don't need such a suggestion and will use CPU registers anyway if they deem it appropriate. But it may still be relevant in embedded system programming so it can't be said to be completely redundant at the present time.
 
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdbool.h>
 
Line 139:
uselessFunc(0);
printf("Working OK.\n");
}</langsyntaxhighlight>
 
{{out}}
Line 147:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
printfn "%s" ("Nigel "^"Galloway")
printfn "%s" ("Nigel "+"Galloway")
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 166:
Use stack shuffle words:
 
<syntaxhighlight lang ="factor">dupd reach</langsyntaxhighlight>
 
Use data flow combinators:
 
<langsyntaxhighlight lang="factor">[ ] keepdd [ [ ] [ ] bi ] 2dip</langsyntaxhighlight>
 
Use local variables:
 
<langsyntaxhighlight lang="factor">[let :> ( a b c ) a b b c a ]</langsyntaxhighlight>
 
Use dynamic variables:
 
<langsyntaxhighlight lang="factor">SYMBOLS: a b c ;
c set b set a set a get b get b get c get a get</langsyntaxhighlight>
 
Use <code>shuffle(</code> syntax:
 
<langsyntaxhighlight lang="factor">shuffle( a b c -- a b b c a )</langsyntaxhighlight>
 
=={{header|Go}}==
Line 189:
 
However, nothing's perfect and the analogous redundant constructions which are allowed in Wren are not picked up by the Go compiler either as the following program shows.
<langsyntaxhighlight lang="go">package main
 
import (
Line 235:
set[0] = NotCompletelyUseless{} // duplicate key so not added to set
fmt.Println(set)
}</langsyntaxhighlight>
 
{{out}}
Line 259:
 
For example, consider the 'any' and 'all' functions, all versions of which have short-circuit semantics. The array-oriented versions of these functions are defined in terms of the more fundamental stream-oriented functions, making the redundancy plain to see:
<langsyntaxhighlight lang="jq">def all: all(.[]; .);
 
def any: any(.[]; .);</langsyntaxhighlight>
 
=={{header|Julia}}==
Line 269:
arrays of `Bool` type. This makes the `count()` function redundant except to better express
intent to count rather than add.
<langsyntaxhighlight lang="julia">array = [true, true, true, false, false, true]
 
@show count(array) # count(array) = 4
@show sum(array) # sum(array) = 4
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
Line 284:
Also, when defining a type with variants, when a branch doesn’t contain any field, we can use the keyword <code>discard</code> (as in a case statement) or the value <code>nil</code>.
 
<langsyntaxhighlight Nimlang="nim">type T = object
case i: 0..2
of 0: value: int
of 1: discard
of 2: nil</langsyntaxhighlight>
 
But, as <code>discard</code> is used as empty statement and <code>nil</code> is used as null value for references and pointers, we cannot say that they are useless even if they are synonyms in one context.
Line 320:
broken in almost every other sense, and from the 0 bug reports clearly had never been used in the real world.
 
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">i</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span>
Line 363:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Working OK.\n"</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
<small>(In fact, if you run "p -d test.exw" on the above, <code>if true</code> .. <code>end while</code> only emits a single instruction, <code>mov i,3</code> at the start of the for loop, and no other instructions at all for those thirteen lines.)</small><br>
<small>(Also, for the above and this by inspecting the list.asm file created, you would be able to see that it doesn't bother adding 3 to i, but instead simply sets it to 6 then 9.)</small><br>
Line 399:
 
Some examples: Say you have a variable $x that holds an integer, and you want to add 1 to it.
<syntaxhighlight lang="raku" perl6line>my $x = 1;
 
$x = $x + 1; # classic
Line 405:
++$x; # pre-increment
$x++; # post-increment
$x.=succ; # method, find successor</langsyntaxhighlight>
 
''Raku is by no means unique in that regard.'' Each one of those nominally accomplishes the same thing, though they go about it in slightly different ways, and are intended for slightly different purposes. Redundant on the face of it, but different reasons for each.
Line 411:
There may be different operations that essentially perform the same function that have been retained for historical compatibility and / or ease for crossover programmers. the <code>for next</code> construct really only exists in Raku for programmer convenience. Internally it is converted to a map operation. Programmers can use map directly, but if they come from a language that doesn't provide map, and aren't used to it, <code>for next</code> is a easy stepping stone.
 
<syntaxhighlight lang="raku" perl6line>for 1..10 { next if $_ %% 2; say '_' x $_ }; # for next
map { next if $_ %% 2; say '_' x $_ }, 1..10; # equivalent map</langsyntaxhighlight>
 
Syntactic sugar (typically) replaces some longer expression with a shorter, more easily typed one. Raku abounds with them.
 
<syntaxhighlight lang="raku" line>
<lang perl6>
my @a1 = Q:w[one two three]; # list of strings using the Q sublanguage
my @a2 = <one two three>; # syntactic sugar for the same operation
Line 422:
say (1,2,3,4,5,6,7).reduce(&infix:<*>); # multiply all of the items in a list together
say [*] (1,2,3,4,5,6,7); # same operation, sweeter syntax
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
Line 428:
 
For good measure I've also included something which looks useless but isn't in fact.
<langsyntaxhighlight lang="ecmascript">var uselessFunc = Fn.new { |uselessParam| // required but never used
if (true) {
// do something
Line 461:
 
uselessFunc.call(0)
System.print(NotCompletelyUseless) // prints the string representation of the Class object</langsyntaxhighlight>
 
{{out}}
Line 482:
Compare the following code snippets, which are functionally identical but the latter is half the size and more than double the speed:
 
<langsyntaxhighlight lang="z80">SET 7,A
SET 6,A
RES 5,A
Line 490:
OR %11000000
AND %11001111
;TOTAL 4 BYTES, 14 CPU STATES</langsyntaxhighlight>
10,333

edits