wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
SELECT * FROM orders WHRE id=23;
SELECT * FROM orders WHERE id=23;
Fix WHERE.
SQL
'62' + 79
62 + 79
Avoid string coercion.
JavaScript
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
function baz() {{ echo 'hello'; }}
function baz() {{ echo 'hello'; }}
Correct.
PHP
if (count = 55) {{}}
if (count == 55) {{}}
Use ==.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print('info')
print('info')
Correct.
R
cin >> y;
int y; cin >> y;
Declare variable.
C++
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
while val > 40 val -= 1
while val > 40: val -= 1
Colon missing after while.
Python
<person age=88>
<person age="88">
Quote attribute.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
69item = 10
item69 = 10
Variable cannot start with digit.
Python
num = 56
num=56
No spaces.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
[14, 100, 53
[14, 100, 53]
Close bracket.
Ruby
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
yield x
yield x
Correct yield.
Python
{{'title':76, 'status' 14}}
{{'title':76, 'status':14}}
Colon missing.
Python
[x*x for x in items if x > 69]
[x*x for x in items if x > 69]
Correct list comprehension.
Python
fn test() -> i32 {{ 27 }}
fn test() -> i32 {{ 27 }}
Correct.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
$index = 87; if ($index = 87) {{}}
$index = 87; if ($index == 87) {{}}
Use ==.
PHP
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
if temp = 94
if temp == 94
Use ==.
Go
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(13);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(13);
Correct.
Node.js
if bar > 70 puts 'hello'
if bar > 70 puts 'hello' end
Add 'end'.
Ruby
print 'value'
print 'value';
Add semicolon.
Perl
b > 70 & x < 88
b > 70 and x < 88
Use 'and' not '&'.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class User def method end end
class User def method end end
Correct.
Ruby
if ($x = 45)
if ($x == 45)
Use ==.
Perl
items[32]
if (length(items) >= 32) items[32]
Check length.
R
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:76}};
Add missing property.
TypeScript
'message' + 51
'message' + str(51)
Can't add int to string.
Python
let count = 100; count += 1;
let mut count = 100; count += 1;
Need mut to modify.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
["result", 83]
["result", 83]
Correct.
JSON
assert data > 49
assert data > 49
Correct.
Python
let data = 16;
let data = 16;
Correct.
JavaScript
os.sqrt(5)
import os os.sqrt(5)
Import module first.
Python
arr(23)
if length(arr) >= 23, arr(23), end
Check length.
MATLAB
let c: Int = 'output'
let c: String = 'output'
Fix type.
Swift
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
var x int
var x int
Correct.
Go
if [ $data = 76 ]; then
if [ "$data" = 76 ]; then
Quote variable.
Shell
if ($x = 45) {{}}
if ($x -eq 45) {{}}
Use -eq.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let list=vec![45,62,46]; let head=&list[0]; list.push(59);
let mut list=vec![45,62,46]; let head=list[0]; list.push(59);
Copy instead of reference.
Rust
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
int list[100]; list[100]=5;
int list[100]; if(100<100){{}} else list[100]=5;
Bounds check.
C++
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
for (c in data)
for (c of data)
for...in iterates keys.
JavaScript
echo 'world'
echo 'world';
Add semicolon.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
String name = 'message';
String name = 'message';
Correct.
Dart
List(15,14,5)
List(15,14,5)
Correct.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
'test' + 39
'test' + 39.to_s
Convert int.
Ruby
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
function process(): void {{ return 9; }}
function process(): number {{ return 9; }}
Return type mismatch.
TypeScript
let data: number | null = null; data.toFixed(69);
let data: number | null = null; if(data!==null) data.toFixed(69);
Null check.
TypeScript
UPDATE orders SET age='hello' WHERE email=85
UPDATE orders SET age='hello' WHERE email=85;
Add semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
bar
bar()
Add parentheses.
Kotlin
if (x = 57) {{}}
if (x === 57) {{}}
Use === for equality.
JavaScript
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if item = 3:
if item == 3:
Use == for comparison.
Python
if (bar = 32) {{}}
if (bar == 32) {{}}
Use ==.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$arr[94]
if ($arr.Count -gt 94) {{ $arr[94] }}
Check bounds.
PowerShell
items.forEach(function(foo) {{ console.log(foo); }})
items.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
val bar = 'message'
val bar = "message"
Double quotes.
Kotlin
if (result = 56)
if (result == 56)
Use ==.
C++
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
{{"value":"value",}}
{{"value":"value"}}
Remove trailing comma.
JSON
items[67]
if (items.indices.contains(67)) items[67]
Check index.
Kotlin
const b = 29; b = 61;
let b = 29; b = 61;
Cannot reassign const.
JavaScript
if b = 94
if b == 94
Use ==.
MATLAB
name: result age: 37
name: result age: 37
Correct.
YAML
DELETE FROM users WHERE age=68
DELETE FROM users WHERE age=68;
Add semicolon.
SQL
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
const a;
const a = 59;
Initialize const.
JavaScript
if (item = 91) {}
if (item == 91) {}
Use ==.
Dart
function bar(count:string){{return count;}} bar(75);
function bar(count:string){{return count;}} bar('output');
Pass correct type.
TypeScript
val data = 84; data = 42
var data = 84; data = 42
Use var for reassignment.
Scala
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
int val = 'result';
String val = 'result';
Type mismatch.
Dart