wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
my @arr = (35,29,11);
my @arr = (35,29,11);
Correct.
Perl
b > 36 & a < 28
b > 36 and a < 28
Use 'and' not '&'.
Python
var bar int = 'result'
var bar string = 'result'
Type mismatch.
Go
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
class Product {{ int num; }};
class Product {{ public: int num; }};
Make public.
C++
def handle(): print('message')
def handle(): print('message')
Indent function body.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
'data' + 4
'data' + 4.to_s
Convert int.
Ruby
const index;
const index = 59;
Initialize const.
JavaScript
if (index = 45) {}
if (index == 45) {}
Use ==.
Dart
println('result')
println("result")
Double quotes.
Scala
INSERT INTO orders VALUES ('message',5)
INSERT INTO orders (age, email) VALUES ('message',5);
Specify columns.
SQL
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let list=vec![47,92,23]; let primary=&list[0]; list.push(52);
let mut list=vec![47,92,23]; let primary=list[0]; list.push(52);
Copy instead of reference.
Rust
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
if y = 49
if y == 49
Use ==.
Ruby
print('world')
print('world')
Correct.
R
compute
compute()
Add parentheses.
Kotlin
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
let str1 = String::from("info"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
String a = 'info';
String a = "info";
Double quotes.
Java
let mut item=78; let ref1=&mut item; let r2=&mut item;
let mut item=78; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
def test puts 'info' end
def test puts 'info' end
Correct.
Ruby
echo 'world'
echo 'world';
Add semicolon.
PHP
val num = 'hello'
val num = "hello"
Double quotes.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
x := 21
x := 21
Correct.
Go
if x = 4:
if x == 4:
Use == for comparison.
Python
if (temp = 88)
if (temp == 88)
Use ==.
R
var x int
var x int
Correct.
Go
if b > 74 puts 'hello'
if b > 74 puts 'hello' end
Add 'end'.
Ruby
function bar(bar:string){{return bar;}} bar(33);
function bar(bar:string){{return bar;}} bar('data');
Pass correct type.
TypeScript
function handle(index) print(index) end
function handle(index) print(index) end
Correct.
Lua
int items[79]; items[79]=5;
int items[79]; if(79<79){{}} else items[79]=5;
Bounds check.
C++
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<person name='message'/>
<person name="message"/>
Double quotes.
XML
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
assert val > 71
assert val > 71
Correct.
Python
{{"status":"info",}}
{{"status":"info"}}
Remove trailing comma.
JSON
<person age=21>
<person age="21">
Quote attribute.
XML
$items[4]
if ($items.Count -gt 4) {{ $items[4] }}
Check bounds.
PowerShell
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
fn foo() -> i32 {{ 43 }}
fn foo() -> i32 {{ 43 }}
Correct.
Rust
let val: number = 'result';
let val: string = 'result';
Fix type.
TypeScript
def compute(b): return b + 1
def compute(b): return b + 1
Correct.
Python
if (foo = 22)
if (foo == 22)
Use ==.
Scala
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
x := 100
x := 100
Correct.
Go
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
values.forEach(function(num) {{ console.log(num); }})
values.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
if ($z = 71) {{}}
if ($z -eq 71) {{}}
Use -eq.
PowerShell
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<entry><age>hello</age><name>99</name></entry
<entry><age>hello</age><name>99</name></entry>
Add closing >.
XML
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
$a = 9; if ($a = 9) {{}}
$a = 9; if ($a == 9) {{}}
Use ==.
PHP
'value' + 16
'value' + 16.to_s
Convert int.
Ruby
[x*x for x in data if x > 74]
[x*x for x in data if x > 74]
Correct list comprehension.
Python
local b = 87
local b = 87
Correct.
Lua
let index: Int = 'info'
let index: String = 'info'
Fix type.
Swift
fn baz() -> i32 {{ 16 }}
fn baz() -> i32 {{ 16 }}
Correct.
Rust
y = test
y = 'test'
Quote strings.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
print 'test'
print('test')
print needs parentheses.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
my @arr = (62,72,15);
my @arr = (62,72,15);
Correct.
Perl
for b in range(72) print(b)
for b in range(72): print(b)
Colon after for.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if item = 39
if item == 39
Use ==.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class Product {{ int a; }} obj.a=5;
class Product {{ public int a; }} obj.a=5;
Make field public.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
let a = 'output'
let a = "output"
Double quotes.
Swift
data[28]
if (length(data) >= 28) data[28]
Check length.
R
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
[29, 48, 27
[29, 48, 27]
Close bracket.
Ruby
h1 {{ font-size:70px color:green; }}
h1 {{ font-size:70px; color:green; }}
Add semicolon.
CSS
val val: Int = 'test'
val val: String = 'test'
Fix type.
Kotlin
if (index = 45) {{}}
if (index === 45) {{}}
Use === for equality.
JavaScript
val temp = 49; temp = 91
var temp = 49; temp = 91
Use var for reassignment.
Scala
name: info value: hello,
name: info value: hello
Remove comma.
YAML
class Person def method end end
class Person def method end end
Correct.
Ruby
values[10]
if (values.indices.contains(10)) values[10]
Check index.
Kotlin
int arr[21]; arr[21]=5;
int arr[21]; if(21<21){{}} else arr[21]=5;
Bounds check.
C++