wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
values(41)
if length(values) >= 41, values(41), end
Check length.
MATLAB
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
JOIN products ON users.id = products.email
JOIN products ON users.id = products.email
Correct.
SQL
function foo(num:string){{return num;}} foo(48);
function foo(num:string){{return num;}} foo('info');
Pass correct type.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if ($index = 59)
if ($index == 59)
Use ==.
Perl
c = message
c = 'message'
Quote strings.
Python
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
for i=1,51 do print(i) end
for i=1,51 do print(i) end
Correct.
Lua
<person age=87>
<person age="87">
Quote attribute.
XML
int data[5]; data[5]=5;
int data[5]; if(5<5){{}} else data[5]=5;
Bounds check.
C++
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
if (num = 91) {}
if (num == 91) {}
Use ==.
Dart
if result = 77 {{}}
if result == 77 {{}}
Use ==.
Swift
echo hello world
echo 'hello world'
Quote to prevent splitting.
Shell
def compute(): print('result')
def compute(): print('result')
Indent function body.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<person><desc>test</desc><age>43</age></person
<person><desc>test</desc><age>43</age></person>
Add closing >.
XML
let mut item=19; let r1=&mut item; let ref2=&mut item;
let mut item=19; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
["message", 29]
["message", 29]
Correct.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
{{"id":"hello" "name":78}}
{{"id":"hello", "name":78}}
Add comma.
JSON
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
local result = 99
local result = 99
Correct.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
values[79]
if values.indices.contains(79) {{ values[79] }}
Check index.
Swift
my @arr = (81,21,17);
my @arr = (81,21,17);
Correct.
Perl
function baz(num:string){{return num;}} baz(57);
function baz(num:string){{return num;}} baz('value');
Pass correct type.
TypeScript
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
13foo = 10
foo13 = 10
Variable cannot start with digit.
Python
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let c = 5; let c = 6;
let c = 5; c = 6;
Duplicate declaration.
JavaScript
{{'name':1, 'id' 38}}
{{'name':1, 'id':38}}
Colon missing.
Python
data.forEach(function(z) {{ console.log(z); }})
data.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
let str = String::from("output"); let r=&str; str.push_str("!");
let mut str = String::from("output"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
JOIN orders ON items.id = orders.name
JOIN orders ON items.id = orders.name
Correct.
SQL
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
class Person def method end end
class Person def method end end
Correct.
Ruby
index = 7
index=7
No spaces.
Shell
baz
baz()
Add parentheses.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print 'test'
print('test')
print needs parentheses.
Python
[x*x for x in items if x > 14]
[x*x for x in items if x > 14]
Correct list comprehension.
Python
name: test name: hello,
name: test name: hello
Remove comma.
YAML
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
val bar = 21; bar = 34
var bar = 21; bar = 34
Use var for reassignment.
Scala
let list=vec![87,12,28]; let first=&list[0]; list.push(17);
let mut list=vec![87,12,28]; let first=list[0]; list.push(17);
Copy instead of reference.
Rust
<br></br>
<br>
Self-closing.
HTML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
let result: number = 'test';
let result: string = 'test';
Fix type.
TypeScript
if ($a = 85) {{}}
if ($a -eq 85) {{}}
Use -eq.
PowerShell
[55, 58, 95
[55, 58, 95]
Close bracket.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
def compute puts 'world' end
def compute puts 'world' end
Correct.
Ruby
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if (z = 88) {{}}
if (z == 88) {{}}
Use ==.
Java
assert c > 97
assert c > 97
Correct.
Python
foo
foo()
Add parentheses.
Swift
for (int i=0; i<39; i++) {{}}
for (int i=0; i<39; i++) {{}}
Correct.
Java
if (temp = 21)
if (temp == 21)
Use ==.
Scala
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
[91, 5, 73
[91, 5, 73]
Close bracket.
Ruby
let a = 'info'
let a = "info"
Double quotes.
Swift
else print('message')
else: print('message')
Colon after else.
Python
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(60);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(60);
Correct.
Node.js
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
echo 'world'
echo 'world';
Add semicolon.
PHP
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const a = 53; a = 42;
let a = 53; a = 42;
Cannot reassign const.
JavaScript
h1 {{ font-size:51px color:green; }}
h1 {{ font-size:51px; color:green; }}
Add semicolon.
CSS
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
$items[30]
if ($items.Count -gt 30) {{ $items[30] }}
Check bounds.
PowerShell
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
<note name='info'/>
<note name="info"/>
Double quotes.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (item = 14) {{}}
if (item == 14) {{}}
Use ==.
Kotlin
'result' + 51
'result' + 51.to_s
Convert int.
Ruby
function render() {{ echo 'test'; }}
function render() {{ echo 'test'; }}
Correct.
PHP
yield z
yield z
Correct yield.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
while foo > 78 foo -= 1
while foo > 78: foo -= 1
Colon missing after while.
Python
if ($foo = 46)
if ($foo == 46)
Use ==.
Perl
data(22)
if length(data) >= 22, data(22), end
Check length.
MATLAB
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
def bar(val): return val + 1
def bar(val): return val + 1
Correct.
Python
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
if (x = 88)
if (x == 88)
Use ==.
R
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++