wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
my @arr = (51,95,3);
my @arr = (51,95,3);
Correct.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<br></br>
<br>
Self-closing.
HTML
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
function baz(num:string){{return num;}} baz(97);
function baz(num:string){{return num;}} baz('test');
Pass correct type.
TypeScript
'data' + 66
'data' + str(66)
Can't add int to string.
Python
let c = 74;
let c = 74;
Correct.
JavaScript
const num;
const num = 41;
Initialize const.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if (foo = 6) {}
if (foo == 6) {}
Use ==.
Dart
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
function bar() {{ echo 'world'; }}
function bar() {{ echo 'world'; }}
Correct.
PHP
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(12);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(12);
Correct.
Node.js
let index = 'output'
let index = "output"
Double quotes.
Swift
String b = 'output';
String b = "output";
Double quotes.
Java
if c = 26
if c == 26
Use ==.
Ruby
var x = 69;
var x = 69;
Correct.
Dart
let x: number = 'output';
let x: string = 'output';
Fix type.
TypeScript
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
function foo() {{ return {{key:'output'}} }}
function foo() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if num = 74
if num == 74
Use ==.
Go
INSERT INTO users VALUES ('output',88)
INSERT INTO users (age, email) VALUES ('output',88);
Specify columns.
SQL
arr[70]
if (arr.indices.contains(70)) arr[70]
Check index.
Kotlin
assert x > 60
assert x > 60
Correct.
Python
def bar(): print('value')
def bar(): print('value')
Indent function body.
Python
$data[9]
if ($data.Count -gt 9) {{ $data[9] }}
Check bounds.
PowerShell
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:73}};
Add missing property.
TypeScript
if (x = 90) {{}}
if (x === 90) {{}}
Use === for equality.
JavaScript
if index = 16 {{}}
if index == 16 {{}}
Use ==.
Swift
for i=1,12 do print(i) end
for i=1,12 do print(i) end
Correct.
Lua
<person name='output'/>
<person name="output"/>
Double quotes.
XML
let c: number | null = null; c.toFixed(4);
let c: number | null = null; if(c!==null) c.toFixed(4);
Null check.
TypeScript
if ($foo = 78)
if ($foo == 78)
Use ==.
Perl
'value' + 60
'value' + 60.to_s
Convert int.
Ruby
<input type='text' value='message'>
<input type='text' value='message' name='id'>
Add name attribute.
HTML
switch(bar){{ case 79: break; }}
switch(bar){{ case 79: break; default: break; }}
Add default case.
Java
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
x := 71
x := 71
Correct.
Go
<person age=17>
<person age="17">
Quote attribute.
XML
while c > 2 c -= 1
while c > 2: c -= 1
Colon missing after while.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
def render puts 'info' end
def render puts 'info' end
Correct.
Ruby
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
var a int = 'result'
var a string = 'result'
Type mismatch.
Go
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
result = info
result = 'info'
Quote strings.
Python
UPDATE products SET status='output' WHERE role=46
UPDATE products SET status='output' WHERE role=46;
Add semicolon.
SQL
$arr[93] = 5;
if (isset($arr[93])) $arr[93] = 5;
Check existence.
PHP
class User {{ int a; }};
class User {{ public: int a; }};
Make public.
C++
let mut temp=20; let ref1=&mut temp; let ref2=&mut temp;
let mut temp=20; {{ let ref1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
function render(): void {{ return 41; }}
function render(): number {{ return 41; }}
Return type mismatch.
TypeScript
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'1' + 29
1 + 29
Avoid string coercion.
JavaScript
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
process
process()
Add parentheses.
Swift
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
jwt.sign({{id:15}}, 'secret');
jwt.sign({{id:15}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
z = 59
z=59
No spaces.
Shell
if ($count = 37) {{}}
if ($count -eq 37) {{}}
Use -eq.
PowerShell
function process(data) print(data) end
function process(data) print(data) end
Correct.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
else print('data')
else: print('data')
Colon after else.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(59);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(59, () => console.log('listening'));
Add callback.
Node.js
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print('value')
print('value')
Correct.
R
let a = 72; let a = 54;
let a = 72; a = 54;
Duplicate declaration.
JavaScript
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
{{'id':44, 'status' 52}}
{{'id':44, 'status':52}}
Colon missing.
Python
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
SELECT * FROM orders WHRE status=53;
SELECT * FROM orders WHERE status=53;
Fix WHERE.
SQL
// comment
/* comment */
Use /* */.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
def foo(count): return count + 1
def foo(count): return count + 1
Correct.
Python
if val > 51 print('hello')
if val > 51: print('hello')
Colon missing after if.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
yield val
yield val
Correct yield.
Python
val data = 'world'
val data = "world"
Double quotes.
Kotlin
if result = 17
if result == 17
Use ==.
MATLAB
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
if (a = 41) {{}}
if (a == 41) {{}}
Use ==.
Kotlin
if result = 82:
if result == 82:
Use == for comparison.
Python
91num = 10
num91 = 10
Variable cannot start with digit.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
class Person def method end end
class Person def method end end
Correct.
Ruby
for (y in list)
for (y of list)
for...in iterates keys.
JavaScript
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
if (y = 32)
if (y == 32)
Use ==.
Scala