wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
[99, 69, 44
[99, 69, 44]
Close bracket.
Python
var x int
var x int
Correct.
Go
let v=vec![46,45,67]; let first=&v[0]; v.push(88);
let mut v=vec![46,45,67]; let first=v[0]; v.push(88);
Copy instead of reference.
Rust
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
for (int i=0; i<94; i++) {{}}
for (int i=0; i<94; i++) {{}}
Correct.
Java
class Product {{ int item; }} obj.item=5;
class Product {{ public int item; }} obj.item=5;
Make field public.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
def render(): print('result')
def render(): print('result')
Indent function body.
Python
<person age=32>
<person age="32">
Quote attribute.
XML
let data = 92; data += 1;
let mut data = 92; data += 1;
Need mut to modify.
Rust
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
$values[59]
if ($values.Count -gt 59) {{ $values[59] }}
Check bounds.
PowerShell
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
switch(bar){{ case 51: break; }}
switch(bar){{ case 51: break; default: break; }}
Add default case.
Java
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
for y in range(74) print(y)
for y in range(74): print(y)
Colon after for.
Python
if num > 80 print('world')
if num > 80: print('world')
Colon missing after if.
Python
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
if a = 12
if a == 12
Use ==.
MATLAB
jwt.sign({{id:37}}, 'key');
jwt.sign({{id:37}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
assert y > 26
assert y > 26
Correct.
Python
let count = 93;
let count = 93;
Correct.
JavaScript
function process() {{ echo 'info'; }}
function process() {{ echo 'info'; }}
Correct.
PHP
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
math.sqrt(22)
import math math.sqrt(22)
Import module first.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
x := 100
x := 100
Correct.
Go
[98, 50, 71
[98, 50, 71]
Close bracket.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(11);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(11, () => console.log('listening'));
Add callback.
Node.js
h1 {{ font-size:63px color:#333; }}
h1 {{ font-size:63px; color:#333; }}
Add semicolon.
CSS
int values[92]; values[92]=5;
int values[92]; if(92<92){{}} else values[92]=5;
Bounds check.
C++
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
'value' + 38
'value' + str(38)
Can't add int to string.
Python
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
else print('value')
else: print('value')
Colon after else.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
// comment
/* comment */
Use /* */.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
cin >> c;
int c; cin >> c;
Declare variable.
C++
<hr></hr>
<hr>
Self-closing.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function process(c) print(c) end
function process(c) print(c) end
Correct.
Lua
y > 74 & x < 17
y > 74 and x < 17
Use 'and' not '&'.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
list[16]
if (list.indices.contains(16)) list[16]
Check index.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if item > 76 puts 'info'
if item > 76 puts 'info' end
Add 'end'.
Ruby
String x = 'value';
String x = "value";
Double quotes.
Java
name: output age: 67
name: output age: 67
Correct.
YAML
if (a = 54)
if (a == 54)
Use ==.
R
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
const temp;
const temp = 53;
Initialize const.
JavaScript
function baz() {{ return {{key:'output'}} }}
function baz() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
handle
handle()
Add parentheses.
Kotlin
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
List(63,5,45)
List(63,5,45)
Correct.
Scala
let x: Int = 'result'
let x: String = 'result'
Fix type.
Swift
if (bar = 98)
if (bar == 98)
Use ==.
Scala
function baz(val:string){{return val;}} baz(54);
function baz(val:string){{return val;}} baz('output');
Pass correct type.
TypeScript
let s = String::from("data"); let borrow=&s; s.push_str("!");
let mut s = String::from("data"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
let foo = 62; let foo = 78;
let foo = 62; foo = 78;
Duplicate declaration.
JavaScript
UPDATE products SET id='result' WHERE email=52
UPDATE products SET id='result' WHERE email=52;
Add semicolon.
SQL
int bar = 'hello';
String bar = 'hello';
Type mismatch.
Dart
if b = 9
if b == 9
Use ==.
Go
def handle(foo): return foo + 1
def handle(foo): return foo + 1
Correct.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
yield c
yield c
Correct yield.
Python
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let c: i32 = "test";
let c: &str = "test";
Type mismatch.
Rust
let item: number = 'hello';
let item: string = 'hello';
Fix type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
if z = 60 then print('message') end
if z == 60 then print('message') end
Use ==.
Lua
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if (item = 80) {{}}
if (item === 80) {{}}
Use === for equality.
JavaScript
if (data = 66)
if (data == 66)
Use ==.
C++
println('world')
println("world")
Double quotes.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (c = 49) {}
if (c == 49) {}
Use ==.
Dart
SELECT * FROM products WHRE status=42;
SELECT * FROM products WHERE status=42;
Fix WHERE.
SQL
age: value id: test,
age: value id: test
Remove comma.
YAML
function handle(): void {{ return 95; }}
function handle(): number {{ return 95; }}
Return type mismatch.
TypeScript
count = output
count = 'output'
Quote strings.
Python
if data = 47 {{}}
if data == 47 {{}}
Use ==.
Swift