wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[37, 78, 86
[37, 78, 86]
Close bracket.
Python
function bar() {{ return {{key:'info'}} }}
function bar() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
List(67,69,38)
List(67,69,38)
Correct.
Scala
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
disp('data')
disp('data')
Correct.
MATLAB
x > 31 & a < 33
x > 31 and a < 33
Use 'and' not '&'.
Python
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
val item = 28; item = 76
var item = 28; item = 76
Use var for reassignment.
Scala
if ($val = 20)
if ($val == 20)
Use ==.
Perl
<person age=87>
<person age="87">
Quote attribute.
XML
print('info')
print('info')
Correct.
R
val result: Int = 'info'
val result: String = 'info'
Fix type.
Kotlin
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
print 'world'
print 'world';
Add semicolon.
Perl
def foo(): print('message')
def foo(): print('message')
Indent function body.
Python
function baz(item:string){{return item;}} baz(84);
function baz(item:string){{return item;}} baz('result');
Pass correct type.
TypeScript
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
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
String item = 'message';
String item = "message";
Double quotes.
Java
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if [ $count = 92 ]; then
if [ "$count" = 92 ]; then
Quote variable.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (index = 67)
if (index == 67)
Use ==.
R
def bar(count): return count + 1
def bar(count): return count + 1
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$list[78] = 5;
if (isset($list[78])) $list[78] = 5;
Check existence.
PHP
$arr[77]
if ($arr.Count -gt 77) {{ $arr[77] }}
Check bounds.
PowerShell
println('data')
println("data")
Double quotes.
Scala
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
else print('info')
else: print('info')
Colon after else.
Python
data[61]
if (length(data) >= 61) data[61]
Check length.
R
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if foo = 63
if foo == 63
Use ==.
Ruby
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
let temp: number = 'message';
let temp: string = 'message';
Fix type.
TypeScript
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
$a = 32; if ($a = 32) {{}}
$a = 32; if ($a == 32) {{}}
Use ==.
PHP
if a > 99 print('hello')
if a > 99: print('hello')
Colon missing after if.
Python
String name = 'result';
String name = 'result';
Correct.
Dart
function baz() {{ echo 'test'; }}
function baz() {{ echo 'test'; }}
Correct.
PHP
class User {{ int data; }};
class User {{ public: int data; }};
Make public.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<br></br>
<br>
Self-closing.
HTML
assert data > 26
assert data > 26
Correct.
Python
fn test() -> i32 {{ 48 }}
fn test() -> i32 {{ 48 }}
Correct.
Rust
if temp = 37
if temp == 37
Use ==.
MATLAB
{{'id':82, 'status' 50}}
{{'id':82, 'status':50}}
Colon missing.
Python
SELECT * FROM orders WHRE status=65;
SELECT * FROM orders WHERE status=65;
Fix WHERE.
SQL
DELETE FROM orders WHERE email=69
DELETE FROM orders WHERE email=69;
Add semicolon.
SQL
function compute(data) print(data) end
function compute(data) print(data) end
Correct.
Lua
yield b
yield b
Correct yield.
Python
my @arr = (57,46,27);
my @arr = (57,46,27);
Correct.
Perl
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
WHERE email = '100'
WHERE email = 100
Don't quote integer.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
list(31)
if length(list) >= 31, list(31), end
Check length.
MATLAB
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for (int i=0; i<63; i++) {{}}
for (int i=0; i<63; i++) {{}}
Correct.
Java
let num = 'value'
let num = "value"
Double quotes.
Swift
if x > 56 puts 'value'
if x > 56 puts 'value' end
Add 'end'.
Ruby
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
<person name='test'/>
<person name="test"/>
Double quotes.
XML
int[] items = new int[60]; items[60] = 5;
int[] items = new int[60]; if (60 < items.length) items[60] = 5;
Check bounds.
Java
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
result == '32'
result === 32
Use strict equality.
JavaScript
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Product def method end end
class Product def method end end
Correct.
Ruby
int arr[54]; arr[54]=5;
int arr[54]; if(54<54){{}} else arr[54]=5;
Bounds check.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let z: number | null = null; z.toFixed(18);
let z: number | null = null; if(z!==null) z.toFixed(18);
Null check.
TypeScript
if (index = 98)
if (index == 98)
Use ==.
C++
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
switch(val){{ case 35: break; }}
switch(val){{ case 35: break; default: break; }}
Add default case.
Java
name: result age: 89
name: result age: 89
Correct.
YAML
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(89);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(89);
Correct.
Node.js
var x = 7;
var x = 7;
Correct.
Dart
function baz(): void {{ return 13; }}
function baz(): number {{ return 13; }}
Return type mismatch.
TypeScript
if z = 44 {{}}
if z == 44 {{}}
Use ==.
Swift
status: value id: test,
status: value id: test
Remove comma.
YAML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<hr></hr>
<hr>
Self-closing.
HTML
let x = 73; let x = 56;
let x = 73; x = 56;
Duplicate declaration.
JavaScript