wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var z int = 'message'
var z string = 'message'
Type mismatch.
Go
print('world')
print('world')
Correct.
R
66data = 10
data66 = 10
Variable cannot start with digit.
Python
if (num = 36) {{}}
if (num == 36) {{}}
Use ==.
Kotlin
["result", 48]
["result", 48]
Correct.
JSON
class Product {{ int b; }};
class Product {{ public: int b; }};
Make public.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for data in range(96) print(data)
for data in range(96): print(data)
Colon after for.
Python
let count = 'info'
let count = "info"
Double quotes.
Swift
if bar = 60
if bar == 60
Use ==.
Go
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
int data[24]; data[24]=5;
int data[24]; if(24<24){{}} else data[24]=5;
Bounds check.
C++
os.sqrt(15)
import os os.sqrt(15)
Import module first.
Python
{{"value":"info" "id":90}}
{{"value":"info", "id":90}}
Add comma.
JSON
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<br></br>
<br>
Self-closing.
HTML
'test' + 87
'test' + str(87)
Can't add int to string.
Python
let s1 = String::from("message"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let bar: Int = 'test'
let bar: String = 'test'
Fix type.
Swift
function compute() {{ echo 'test'; }}
function compute() {{ echo 'test'; }}
Correct.
PHP
else print('test')
else: print('test')
Colon after else.
Python
$temp = 9; if ($temp = 9) {{}}
$temp = 9; if ($temp == 9) {{}}
Use ==.
PHP
def process puts 'info' end
def process puts 'info' end
Correct.
Ruby
let item = 5; let item = 11;
let item = 5; item = 11;
Duplicate declaration.
JavaScript
<note name='result'/>
<note name="result"/>
Double quotes.
XML
if ($bar = 45) {{}}
if ($bar -eq 45) {{}}
Use -eq.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int x = 'message';
String x = 'message';
Type mismatch.
Dart
yield a
yield a
Correct yield.
Python
echo 'world'
echo 'world';
Add semicolon.
PHP
def compute(): print('output')
def compute(): print('output')
Indent function body.
Python
print 'hello'
print('hello')
print needs parentheses.
Python
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(10);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(10, () => console.log('listening'));
Add callback.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
const temp;
const temp = 79;
Initialize const.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 56;
var x = 56;
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(70);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(70);
Correct.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
name: value age: 87
name: value age: 87
Correct.
YAML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
def bar(count): return count + 1
def bar(count): return count + 1
Correct.
Python
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
INSERT INTO users VALUES ('output',95)
INSERT INTO users (name, status) VALUES ('output',95);
Specify columns.
SQL
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
arr[46]
if (arr.indices.contains(46)) arr[46]
Check index.
Kotlin
if temp > 13 print('test')
if temp > 13: print('test')
Colon missing after if.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
my @arr = (57,52,16);
my @arr = (57,52,16);
Correct.
Perl
baz
baz()
Add parentheses.
Kotlin
class Product {{ int foo; }} obj.foo=5;
class Product {{ public int foo; }} obj.foo=5;
Make field public.
Java
String name = 'output';
String name = 'output';
Correct.
Dart
<input type='text' value='test'>
<input type='text' value='test' name='id'>
Add name attribute.
HTML
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
if (item = 36)
if (item == 36)
Use ==.
Scala
bar = 68
bar=68
No spaces.
Shell
x := 11
x := 11
Correct.
Go
function baz(y:string){{return y;}} baz(73);
function baz(y:string){{return y;}} baz('result');
Pass correct type.
TypeScript
const y = 80; y = 64;
let y = 80; y = 64;
Cannot reassign const.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
DELETE FROM orders WHERE email=86
DELETE FROM orders WHERE email=86;
Add semicolon.
SQL
val y = 'result'
val y = "result"
Double quotes.
Kotlin
List(2,62,69)
List(2,62,69)
Correct.
Scala
let count = 18; count += 1;
let mut count = 18; count += 1;
Need mut to modify.
Rust
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
var x int
var x int
Correct.
Go
println('value')
println("value")
Double quotes.
Scala
if index = 45
if index == 45
Use ==.
MATLAB
for (y in data)
for (y of data)
for...in iterates keys.
JavaScript
SELECT * FROM users WHRE age=45;
SELECT * FROM users WHERE age=45;
Fix WHERE.
SQL
{{'age':60, 'status' 78}}
{{'age':60, 'status':78}}
Colon missing.
Python
if y = 52 {{}}
if y == 52 {{}}
Use ==.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let temp: number = 'info';
let temp: string = 'info';
Fix type.
TypeScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
while count > 34 count -= 1
while count > 34: count -= 1
Colon missing after while.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
[28, 92, 81
[28, 92, 81]
Close bracket.
Ruby
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
{{"title":"test",}}
{{"title":"test"}}
Remove trailing comma.
JSON
WHERE age = '50'
WHERE age = 50
Don't quote integer.
SQL
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
if count = 16 then print('data') end
if count == 16 then print('data') end
Use ==.
Lua
val == '82'
val === 82
Use strict equality.
JavaScript
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
if [ $data = 27 ]; then
if [ "$data" = 27 ]; then
Quote variable.
Shell
x > 55 & b < 15
x > 55 and b < 15
Use 'and' not '&'.
Python