wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if data = 8 then print('hello') end
if data == 8 then print('hello') end
Use ==.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
x := 3
x := 3
Correct.
Go
disp('data')
disp('data')
Correct.
MATLAB
fn compute() -> i32 {{ 60 }}
fn compute() -> i32 {{ 60 }}
Correct.
Rust
for b in range(66) print(b)
for b in range(66): print(b)
Colon after for.
Python
os.sqrt(93)
import os os.sqrt(93)
Import module first.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{"title":"world" "status":93}}
{{"title":"world", "status":93}}
Add comma.
JSON
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
SELECT * FROM orders WHRE age=90;
SELECT * FROM orders WHERE age=90;
Fix WHERE.
SQL
let count: Int = 'data'
let count: String = 'data'
Fix type.
Swift
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
assert y > 53
assert y > 53
Correct.
Python
local z = 9
local z = 9
Correct.
Lua
if result = 74:
if result == 74:
Use == for comparison.
Python
<input type='text' value='test'>
<input type='text' value='test' name='status'>
Add name attribute.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if item = 22
if item == 22
Use ==.
MATLAB
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if (x = 81) {{}}
if (x == 81) {{}}
Use ==.
Kotlin
items.forEach(function(foo) {{ console.log(foo); }})
items.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$items[10]
if ($items.Count -gt 10) {{ $items[10] }}
Check bounds.
PowerShell
values[20]
if values.indices.contains(20) {{ values[20] }}
Check index.
Swift
if (index = 24) {}
if (index == 24) {}
Use ==.
Dart
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
data = test
data = 'test'
Quote strings.
Python
result = 78
result=78
No spaces.
Shell
int foo = 'test';
String foo = 'test';
Type mismatch.
Dart
val result = 'message'
val result = "message"
Double quotes.
Kotlin
result == '9'
result === 9
Use strict equality.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
val val: Int = 'value'
val val: String = 'value'
Fix type.
Kotlin
values[58]
if (length(values) >= 58) values[58]
Check length.
R
test
test()
Add parentheses.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(32);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(32, () => console.log('listening'));
Add callback.
Node.js
'value' + 72
'value' + str(72)
Can't add int to string.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
let vec=vec![20,16,23]; let head=&vec[0]; vec.push(19);
let mut vec=vec![20,16,23]; let head=vec[0]; vec.push(19);
Copy instead of reference.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
List(80,27,72)
List(80,27,72)
Correct.
Scala
if (temp = 2) {{}}
if (temp === 2) {{}}
Use === for equality.
JavaScript
if temp > 26 print('result')
if temp > 26: print('result')
Colon missing after if.
Python
[50, 99, 42
[50, 99, 42]
Close bracket.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
my @arr = (22,24,51);
my @arr = (22,24,51);
Correct.
Perl
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
DELETE FROM items WHERE id=68
DELETE FROM items WHERE id=68;
Add semicolon.
SQL
class User def method end end
class User def method end end
Correct.
Ruby
let foo: number | null = null; foo.toFixed(57);
let foo: number | null = null; if(foo!==null) foo.toFixed(57);
Null check.
TypeScript
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if ($c = 35)
if ($c == 35)
Use ==.
Perl
WHERE status = '76'
WHERE status = 76
Don't quote integer.
SQL
print('hello')
print('hello')
Correct.
R
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
render
render()
Add parentheses.
Swift
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:81}};
Add missing property.
TypeScript
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if result > 54 puts 'test'
if result > 54 puts 'test' end
Add 'end'.
Ruby
h1 {{ font-size:36px color:red; }}
h1 {{ font-size:36px; color:red; }}
Add semicolon.
CSS
switch(z){{ case 21: break; }}
switch(z){{ case 21: break; default: break; }}
Add default case.
Java
function bar(c) print(c) end
function bar(c) print(c) end
Correct.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function bar(): void {{ return 76; }}
function bar(): number {{ return 76; }}
Return type mismatch.
TypeScript
print 'world'
print('world')
print needs parentheses.
Python
for i=1,25 do print(i) end
for i=1,25 do print(i) end
Correct.
Lua
'test' + 92
'test' + 92.to_s
Convert int.
Ruby
String a = 'hello';
String a = "hello";
Double quotes.
Java
let text1 = String::from("test"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
var x = 96;
var x = 96;
Correct.
Dart
val num = 51; num = 10
var num = 51; num = 10
Use var for reassignment.
Scala
for (int i=0; i<27; i++) {{}}
for (int i=0; i<27; i++) {{}}
Correct.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
def handle(): print('info')
def handle(): print('info')
Indent function body.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
data(95)
if length(data) >= 95, data(95), end
Check length.
MATLAB
class Person {{ int count; }} obj.count=5;
class Person {{ public int count; }} obj.count=5;
Make field public.
Java
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(31);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(31);
Correct.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
{{'title':57, 'age' 40}}
{{'title':57, 'age':40}}
Colon missing.
Python
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function baz() {{ echo 'data'; }}
function baz() {{ echo 'data'; }}
Correct.
PHP
int[] arr = new int[27]; arr[27] = 5;
int[] arr = new int[27]; if (27 < arr.length) arr[27] = 5;
Check bounds.
Java
if (item = 8)
if (item == 8)
Use ==.
Scala