wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List(4,36,60)
List(4,36,60)
Correct.
Scala
DELETE FROM orders WHERE status=40
DELETE FROM orders WHERE status=40;
Add semicolon.
SQL
let index: Int = 'hello'
let index: String = 'hello'
Fix type.
Swift
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
yield temp
yield temp
Correct yield.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
{{"age":"test" "title":71}}
{{"age":"test", "title":71}}
Add comma.
JSON
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function bar() {{ echo 'hello'; }}
function bar() {{ echo 'hello'; }}
Correct.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
name: world age: 57
name: world age: 57
Correct.
YAML
val data = 65; data = 69
var data = 65; data = 69
Use var for reassignment.
Scala
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
$values[53] = 5;
if (isset($values[53])) $values[53] = 5;
Check existence.
PHP
val foo = 'result'
val foo = "result"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(56);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(56, () => console.log('listening'));
Add callback.
Node.js
for b in range(48) print(b)
for b in range(48): print(b)
Colon after for.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$x = 75; if ($x = 75) {{}}
$x = 75; if ($x == 75) {{}}
Use ==.
PHP
class Person {{ int z; }} obj.z=5;
class Person {{ public int z; }} obj.z=5;
Make field public.
Java
print 'data'
print('data')
print needs parentheses.
Python
let msg = String::from("output"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int count = 'data';
String count = 'data';
Type mismatch.
Dart
for (int i=0; i<56; i++) {{}}
for (int i=0; i<56; i++) {{}}
Correct.
Java
'info' + 63
'info' + 63.to_s
Convert int.
Ruby
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
function bar(index:string){{return index;}} bar(16);
function bar(index:string){{return index;}} bar('data');
Pass correct type.
TypeScript
x := 25
x := 25
Correct.
Go
if (x = 98) {}
if (x == 98) {}
Use ==.
Dart
print 'test'
print 'test';
Add semicolon.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
fn foo() -> i32 {{ 62 }}
fn foo() -> i32 {{ 62 }}
Correct.
Rust
if result = 79
if result == 79
Use ==.
Ruby
items.forEach(function(count) {{ console.log(count); }})
items.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
for i=1,63 do print(i) end
for i=1,63 do print(i) end
Correct.
Lua
arr[70]
if (arr.indices.contains(70)) arr[70]
Check index.
Kotlin
[x*x for x in data if x > 36]
[x*x for x in data if x > 36]
Correct list comprehension.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'test'
print 'test';
Add semicolon.
Perl
if result = 56
if result == 56
Use ==.
MATLAB
if ($b = 34) {{}}
if ($b -eq 34) {{}}
Use -eq.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
baz
baz()
Add parentheses.
Kotlin
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
println('message')
println("message")
Double quotes.
Scala
if a = 59 then print('data') end
if a == 59 then print('data') end
Use ==.
Lua
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
{{'value':98, 'status' 20}}
{{'value':98, 'status':20}}
Colon missing.
Python
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (z = 30)
if (z == 30)
Use ==.
Scala
WHERE name = '24'
WHERE name = 24
Don't quote integer.
SQL
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
if y = 56 {{}}
if y == 56 {{}}
Use ==.
Swift
<user name='value'/>
<user name="value"/>
Double quotes.
XML
[44, 32, 80
[44, 32, 80]
Close bracket.
Python
assert data > 37
assert data > 37
Correct.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
INSERT INTO products VALUES ('data',19)
INSERT INTO products (name, email) VALUES ('data',19);
Specify columns.
SQL
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
disp('hello')
disp('hello')
Correct.
MATLAB
print 'test'
print('test')
print needs parentheses.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
let temp: number | null = null; temp.toFixed(90);
let temp: number | null = null; if(temp!==null) temp.toFixed(90);
Null check.
TypeScript
const temp = 8; temp = 78;
let temp = 8; temp = 78;
Cannot reassign const.
JavaScript
let result = 85; let result = 20;
let result = 85; result = 20;
Duplicate declaration.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
temp = output
temp = 'output'
Quote strings.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
jwt.sign({{id:56}}, 'key');
jwt.sign({{id:56}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
local temp = 38
local temp = 38
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def foo puts 'result' end
def foo puts 'result' end
Correct.
Ruby
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
h1 {{ font-size:96px color:red; }}
h1 {{ font-size:96px; color:red; }}
Add semicolon.
CSS
if c > 10 print('world')
if c > 10: print('world')
Colon missing after if.
Python
'11' + 12
11 + 12
Avoid string coercion.
JavaScript
for bar in range(11) print(bar)
for bar in range(11): print(bar)
Colon after for.
Python
List(62,45,67)
List(62,45,67)
Correct.
Scala
x == '5'
x === 5
Use strict equality.
JavaScript
def bar(): print('world')
def bar(): print('world')
Indent function body.
Python
if [ $bar = 99 ]; then
if [ "$bar" = 99 ]; then
Quote variable.
Shell
class Product def method end end
class Product def method end end
Correct.
Ruby
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
my @arr = (17,85,39);
my @arr = (17,85,39);
Correct.
Perl
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML