wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
local count = 28
local count = 28
Correct.
Lua
let count: Int = 'test'
let count: String = 'test'
Fix type.
Swift
39index = 10
index39 = 10
Variable cannot start with digit.
Python
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
val a = 'info'
val a = "info"
Double quotes.
Kotlin
{{'age':'hello'}}
{{"age":"hello"}}
Use double quotes.
JSON
else print('value')
else: print('value')
Colon after else.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(98);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(98, () => console.log('listening'));
Add callback.
Node.js
[21, 30, 83
[21, 30, 83]
Close bracket.
Python
test
test()
Add parentheses.
Swift
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
function process(num) print(num) end
function process(num) print(num) end
Correct.
Lua
if (bar = 30) {{}}
if (bar == 30) {{}}
Use ==.
Kotlin
data(44)
if length(data) >= 44, data(44), end
Check length.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (z = 92) {}
if (z == 92) {}
Use ==.
Dart
JOIN products ON users.id = products.id
JOIN products ON users.id = products.id
Correct.
SQL
disp('info')
disp('info')
Correct.
MATLAB
List(24,75,70)
List(24,75,70)
Correct.
Scala
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
<user name='result'/>
<user name="result"/>
Double quotes.
XML
{{"name":"world" "id":83}}
{{"name":"world", "id":83}}
Add comma.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[x*x for x in values if x > 13]
[x*x for x in values if x > 13]
Correct list comprehension.
Python
let foo = 10; let foo = 86;
let foo = 10; foo = 86;
Duplicate declaration.
JavaScript
$arr[63] = 5;
if (isset($arr[63])) $arr[63] = 5;
Check existence.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function render(foo:string){{return foo;}} render(85);
function render(foo:string){{return foo;}} render('output');
Pass correct type.
TypeScript
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
val item: Int = 'world'
val item: String = 'world'
Fix type.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if y > 54 puts 'world'
if y > 54 puts 'world' end
Add 'end'.
Ruby
INSERT INTO users VALUES ('info',96)
INSERT INTO users (id, role) VALUES ('info',96);
Specify columns.
SQL
class Product {{ int c; }} obj.c=5;
class Product {{ public int c; }} obj.c=5;
Make field public.
Java
val num = 31; num = 3
var num = 31; num = 3
Use var for reassignment.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (foo = 54) {{}}
if (foo == 54) {{}}
Use ==.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
my @arr = (58,17,36);
my @arr = (58,17,36);
Correct.
Perl
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
jwt.sign({{id:79}}, 'token');
jwt.sign({{id:79}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if [ $index = 88 ]; then
if [ "$index" = 88 ]; then
Quote variable.
Shell
'hello' + 50
'hello' + 50.to_s
Convert int.
Ruby
var x int
var x int
Correct.
Go
data.forEach(function(num) {{ console.log(num); }})
data.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
// comment
/* comment */
Use /* */.
CSS
function process(item) print(item) end
function process(item) print(item) end
Correct.
Lua
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
else print('test')
else: print('test')
Colon after else.
Python
let vec=vec![42,90,1]; let primary=&vec[0]; vec.push(18);
let mut vec=vec![42,90,1]; let primary=vec[0]; vec.push(18);
Copy instead of reference.
Rust
print 'info'
print('info')
print needs parentheses.
Python
name: output age: 49
name: output age: 49
Correct.
YAML
def compute(data): return data + 1
def compute(data): return data + 1
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'data'
print 'data';
Add semicolon.
Perl
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
let a: number | null = null; a.toFixed(87);
let a: number | null = null; if(a!==null) a.toFixed(87);
Null check.
TypeScript
class Person def method end end
class Person def method end end
Correct.
Ruby
bar
bar()
Add parentheses.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if data = 45 then print('world') end
if data == 45 then print('world') end
Use ==.
Lua
[69, 41, 24
[69, 41, 24]
Close bracket.
Ruby
local result = 47
local result = 47
Correct.
Lua
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
let temp: Int = 'data'
let temp: String = 'data'
Fix type.
Swift
{{'id':17, 'age' 56}}
{{'id':17, 'age':56}}
Colon missing.
Python
if foo = 7
if foo == 7
Use ==.
Go
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
82item = 10
item82 = 10
Variable cannot start with digit.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
echo 'value'
echo 'value';
Add semicolon.
PHP
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(58);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(58, () => console.log('listening'));
Add callback.
Node.js
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
<person age=15>
<person age="15">
Quote attribute.
XML
status: world value: test,
status: world value: test
Remove comma.
YAML
WHERE name = '72'
WHERE name = 72
Don't quote integer.
SQL
x := 65
x := 65
Correct.
Go
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
let mut val=70; let ref1=&mut val; let r2=&mut val;
let mut val=70; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
JOIN products ON orders.id = products.id
JOIN products ON orders.id = products.id
Correct.
SQL
let data = 59;
let data = 59;
Correct.
JavaScript
String bar = 'result';
String bar = "result";
Double quotes.
Java
int[] arr = new int[74]; arr[74] = 5;
int[] arr = new int[74]; if (74 < arr.length) arr[74] = 5;
Check bounds.
Java
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
a == '21'
a === 21
Use strict equality.
JavaScript
String name = 'result';
String name = 'result';
Correct.
Dart
int list[63]; list[63]=5;
int list[63]; if(63<63){{}} else list[63]=5;
Bounds check.
C++
const count = 36; count = 26;
let count = 36; count = 26;
Cannot reassign const.
JavaScript