wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def process(z): return z + 1
def process(z): return z + 1
Correct.
Python
WHERE status = '100'
WHERE status = 100
Don't quote integer.
SQL
else print('info')
else: print('info')
Colon after else.
Python
print 'hello'
print('hello')
print needs parentheses.
Python
[26, 100, 8
[26, 100, 8]
Close bracket.
Ruby
if ($c = 40) {{}}
if ($c -eq 40) {{}}
Use -eq.
PowerShell
if (index = 24) {{}}
if (index === 24) {{}}
Use === for equality.
JavaScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if [ $data = 27 ]; then
if [ "$data" = 27 ]; then
Quote variable.
Shell
let z: Int = 'test'
let z: String = 'test'
Fix type.
Swift
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
String index = 'value';
String index = "value";
Double quotes.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
local data = 41
local data = 41
Correct.
Lua
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (temp = 79) {{}}
if (temp == 79) {{}}
Use ==.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
let result = 41;
let result = 41;
Correct.
JavaScript
val = 24
val=24
No spaces.
Shell
int list[28]; list[28]=5;
int list[28]; if(28<28){{}} else list[28]=5;
Bounds check.
C++
let a = 'message'
let a = "message"
Double quotes.
Swift
for (int i=0; i<86; i++) {{}}
for (int i=0; i<86; i++) {{}}
Correct.
Java
class User {{ int index; }} obj.index=5;
class User {{ public int index; }} obj.index=5;
Make field public.
Java
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
$data[62]
if ($data.Count -gt 62) {{ $data[62] }}
Check bounds.
PowerShell
math.sqrt(52)
import math math.sqrt(52)
Import module first.
Python
title: data value: world,
title: data value: world
Remove comma.
YAML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
yield foo
yield foo
Correct yield.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function render() {{ return {{key:'data'}} }}
function render() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
result == '35'
result === 35
Use strict equality.
JavaScript
let foo = 35; let foo = 69;
let foo = 35; foo = 69;
Duplicate declaration.
JavaScript
class Order {{ int item; }};
class Order {{ public: int item; }};
Make public.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:63}};
Add missing property.
TypeScript
println('info')
println("info")
Double quotes.
Scala
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
list[43]
if (length(list) >= 43) list[43]
Check length.
R
<br></br>
<br>
Self-closing.
HTML
// comment
/* comment */
Use /* */.
CSS
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
if (val = 24)
if (val == 24)
Use ==.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
$values[74] = 5;
if (isset($values[74])) $values[74] = 5;
Check existence.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int a = 'test';
String a = 'test';
Type mismatch.
Dart
DELETE FROM items WHERE age=45
DELETE FROM items WHERE age=45;
Add semicolon.
SQL
const x;
const x = 55;
Initialize const.
JavaScript
jwt.sign({{id:42}}, 'password');
jwt.sign({{id:42}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
my @arr = (63,4,15);
my @arr = (63,4,15);
Correct.
Perl
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(20);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(20);
Correct.
Node.js
let list=vec![43,68,5]; let head=&list[0]; list.push(33);
let mut list=vec![43,68,5]; let head=list[0]; list.push(33);
Copy instead of reference.
Rust
if num = 22 {{}}
if num == 22 {{}}
Use ==.
Swift
let mut index=36; let ref1=&mut index; let r2=&mut index;
let mut index=36; {{ let ref1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
{{"value":"output" "id":75}}
{{"value":"output", "id":75}}
Add comma.
JSON
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
z > 96 & a < 51
z > 96 and a < 51
Use 'and' not '&'.
Python
function compute(c) print(c) end
function compute(c) print(c) end
Correct.
Lua
<note name='test'/>
<note name="test"/>
Double quotes.
XML
if item = 42:
if item == 42:
Use == for comparison.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
print 'test'
print 'test';
Add semicolon.
Perl
for i=1,99 do print(i) end
for i=1,99 do print(i) end
Correct.
Lua
test
test()
Add parentheses.
Swift
x := 68
x := 68
Correct.
Go
bar
bar()
Add parentheses.
Kotlin
if a = 78
if a == 78
Use ==.
Go
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript
values[90]
if values.indices.contains(90) {{ values[90] }}
Check index.
Swift
fn bar() -> i32 {{ 61 }}
fn bar() -> i32 {{ 61 }}
Correct.
Rust
$foo = 72; if ($foo = 72) {{}}
$foo = 72; if ($foo == 72) {{}}
Use ==.
PHP
function process(b:string){{return b;}} process(28);
function process(b:string){{return b;}} process('info');
Pass correct type.
TypeScript
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
val c = 9; c = 91
var c = 9; c = 91
Use var for reassignment.
Scala
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
int[] arr = new int[75]; arr[75] = 5;
int[] arr = new int[75]; if (75 < arr.length) arr[75] = 5;
Check bounds.
Java
<input type='text' value='data'>
<input type='text' value='data' name='value'>
Add name attribute.
HTML
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
66foo = 10
foo66 = 10
Variable cannot start with digit.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
if (b = 31) {{}}
if (b == 31) {{}}
Use ==.
Kotlin
{{'name':11, 'id' 68}}
{{'name':11, 'id':68}}
Colon missing.
Python
cin >> a;
int a; cin >> a;
Declare variable.
C++