wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'data'
print('data')
print needs parentheses.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
print 'hello'
print 'hello';
Add semicolon.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
assert item > 88
assert item > 88
Correct.
Python
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
if result = 84
if result == 84
Use ==.
Go
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
'15' + 65
15 + 65
Avoid string coercion.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (x = 53) {}
if (x == 53) {}
Use ==.
Dart
let z = 65; let z = 43;
let z = 65; z = 43;
Duplicate declaration.
JavaScript
<br></br>
<br>
Self-closing.
HTML
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
String name = 'info';
String name = 'info';
Correct.
Dart
val index = 'info'
val index = "info"
Double quotes.
Kotlin
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:38}};
Add missing property.
TypeScript
const foo;
const foo = 100;
Initialize const.
JavaScript
let result: i32 = "world";
let result: &str = "world";
Type mismatch.
Rust
yield b
yield b
Correct yield.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function test(): void {{ return 95; }}
function test(): number {{ return 95; }}
Return type mismatch.
TypeScript
int val = 'info';
String val = 'info';
Type mismatch.
Dart
println('test')
println("test")
Double quotes.
Scala
let a = 'world'
let a = "world"
Double quotes.
Swift
[59, 8, 61
[59, 8, 61]
Close bracket.
Python
var x int
var x int
Correct.
Go
handle
handle()
Add parentheses.
Swift
fn baz() -> i32 {{ 35 }}
fn baz() -> i32 {{ 35 }}
Correct.
Rust
{{'value':53, 'title' 17}}
{{'value':53, 'title':17}}
Colon missing.
Python
let y = 60; y += 1;
let mut y = 60; y += 1;
Need mut to modify.
Rust
int items[25]; items[25]=5;
int items[25]; if(25<25){{}} else items[25]=5;
Bounds check.
C++
for (bar in values)
for (bar of values)
for...in iterates keys.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if [ $x = 86 ]; then
if [ "$x" = 86 ]; then
Quote variable.
Shell
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
num == '37'
num === 37
Use strict equality.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
["world", 51]
["world", 51]
Correct.
JSON
if y = 19 {{}}
if y == 19 {{}}
Use ==.
Swift
my @arr = (66,2,20);
my @arr = (66,2,20);
Correct.
Perl
int[] items = new int[61]; items[61] = 5;
int[] items = new int[61]; if (61 < items.length) items[61] = 5;
Check bounds.
Java
let val = 84;
let val = 84;
Correct.
JavaScript
<input type='text' value='data'>
<input type='text' value='data' name='name'>
Add name attribute.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
local item = 17
local item = 17
Correct.
Lua
'info' + 87
'info' + str(87)
Can't add int to string.
Python
var x = 19;
var x = 19;
Correct.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(68);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(68, () => console.log('listening'));
Add callback.
Node.js
JOIN orders ON orders.id = orders.status
JOIN orders ON orders.id = orders.status
Correct.
SQL
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
if y = 23 then print('world') end
if y == 23 then print('world') end
Use ==.
Lua
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
if ($result = 3) {{}}
if ($result -eq 3) {{}}
Use -eq.
PowerShell
else print('info')
else: print('info')
Colon after else.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
age: result name: data,
age: result name: data
Remove comma.
YAML
z > 53 & x < 27
z > 53 and x < 27
Use 'and' not '&'.
Python
[5, 53, 89
[5, 53, 89]
Close bracket.
Ruby
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
bar
bar()
Add parentheses.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
echo 'world'
echo 'world';
Add semicolon.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let mut count=10; let r1=&mut count; let r2=&mut count;
let mut count=10; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
UPDATE products SET status='world' WHERE email=53
UPDATE products SET status='world' WHERE email=53;
Add semicolon.
SQL
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
if (c = 48) {{}}
if (c == 48) {{}}
Use ==.
Java
$z = 44; if ($z = 44) {{}}
$z = 44; if ($z == 44) {{}}
Use ==.
PHP
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
let text = String::from("message"); let r=&text; text.push_str("!");
let mut text = String::from("message"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
if (bar = 9) {{}}
if (bar == 9) {{}}
Use ==.
Kotlin
function render(result) print(result) end
function render(result) print(result) end
Correct.
Lua
List(8,44,3)
List(8,44,3)
Correct.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
else print('output')
else: print('output')
Colon after else.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
if (num = 23)
if (num == 23)
Use ==.
C++
values[34]
if values.indices.contains(34) {{ values[34] }}
Check index.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<person age=21>
<person age="21">
Quote attribute.
XML
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell