wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[52, 43, 93
[52, 43, 93]
Close bracket.
Python
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
JOIN profiles ON orders.id = profiles.name
JOIN profiles ON orders.id = profiles.name
Correct.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
val x = 50; x = 38
var x = 50; x = 38
Use var for reassignment.
Scala
<?php // code ?>
<?php // code ?>
Correct.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
List(78,12,24)
List(78,12,24)
Correct.
Scala
if (z = 12) {{}}
if (z == 12) {{}}
Use ==.
Kotlin
let x: Int = 'info'
let x: String = 'info'
Fix type.
Swift
if b = 99:
if b == 99:
Use == for comparison.
Python
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if foo = 88 then print('value') end
if foo == 88 then print('value') end
Use ==.
Lua
let mut y=17; let r1=&mut y; let ref2=&mut y;
let mut y=17; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
<person age=76>
<person age="76">
Quote attribute.
XML
[92, 66, 26
[92, 66, 26]
Close bracket.
Ruby
function compute(): void {{ return 41; }}
function compute(): number {{ return 41; }}
Return type mismatch.
TypeScript
foo
foo()
Add parentheses.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
UPDATE orders SET id='output' WHERE status=91
UPDATE orders SET id='output' WHERE status=91;
Add semicolon.
SQL
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
String name = 'message';
String name = 'message';
Correct.
Dart
$list[61]
if ($list.Count -gt 61) {{ $list[61] }}
Check bounds.
PowerShell
'test' + 2
'test' + 2.to_s
Convert int.
Ruby
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:57}};
Add missing property.
TypeScript
val foo: Int = 'world'
val foo: String = 'world'
Fix type.
Kotlin
if y = 68
if y == 68
Use ==.
Ruby
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
for (z in values)
for (z of values)
for...in iterates keys.
JavaScript
local val = 57
local val = 57
Correct.
Lua
while temp > 39 temp -= 1
while temp > 39: temp -= 1
Colon missing after while.
Python
var x int = 'world'
var x string = 'world'
Type mismatch.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if z > 36 print('message')
if z > 36: print('message')
Colon missing after if.
Python
if data = 51
if data == 51
Use ==.
Go
cin >> index;
int index; cin >> index;
Declare variable.
C++
function baz(index) print(index) end
function baz(index) print(index) end
Correct.
Lua
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
fn process() -> i32 {{ 23 }}
fn process() -> i32 {{ 23 }}
Correct.
Rust
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(80);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(80);
Correct.
Node.js
if ($num = 5) {{}}
if ($num -eq 5) {{}}
Use -eq.
PowerShell
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
89c = 10
c89 = 10
Variable cannot start with digit.
Python
name: result age: 61
name: result age: 61
Correct.
YAML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby
const a = 74; a = 52;
let a = 74; a = 52;
Cannot reassign const.
JavaScript
let c = 44; let c = 15;
let c = 44; c = 15;
Duplicate declaration.
JavaScript
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
if result > 37 puts 'data'
if result > 37 puts 'data' end
Add 'end'.
Ruby
["data", 12]
["data", 12]
Correct.
JSON
echo 'test'
echo 'test';
Add semicolon.
PHP
my @arr = (2,34,82);
my @arr = (2,34,82);
Correct.
Perl
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
for (int i=0; i<67; i++) {{}}
for (int i=0; i<67; i++) {{}}
Correct.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
list(79)
if length(list) >= 79, list(79), end
Check length.
MATLAB
$data[10] = 5;
if (isset($data[10])) $data[10] = 5;
Check existence.
PHP
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
int c = 'data';
String c = 'data';
Type mismatch.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let z: i32 = "info";
let z: &str = "info";
Type mismatch.
Rust
const num;
const num = 56;
Initialize const.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
WHERE id = '23'
WHERE id = 23
Don't quote integer.
SQL
items[18]
if (items.indices.contains(18)) items[18]
Check index.
Kotlin
let val = 44; val += 1;
let mut val = 44; val += 1;
Need mut to modify.
Rust
items[89]
if items.indices.contains(89) {{ items[89] }}
Check index.
Swift
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
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function process() {{ echo 'test'; }}
function process() {{ echo 'test'; }}
Correct.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
{{"value":"world" "title":61}}
{{"value":"world", "title":61}}
Add comma.
JSON
num = 48
num=48
No spaces.
Shell
// comment
/* comment */
Use /* */.
CSS
{{'value':26, 'title' 13}}
{{'value':26, 'title':13}}
Colon missing.
Python
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
print 'world'
print('world')
print needs parentheses.
Python