wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
INSERT INTO users VALUES ('info',69)
INSERT INTO users (name, role) VALUES ('info',69);
Specify columns.
SQL
<br></br>
<br>
Self-closing.
HTML
fn process() -> i32 {{ 37 }}
fn process() -> i32 {{ 37 }}
Correct.
Rust
if [ $x = 70 ]; then
if [ "$x" = 70 ]; then
Quote variable.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
my @arr = (43,31,52);
my @arr = (43,31,52);
Correct.
Perl
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if temp = 23
if temp == 23
Use ==.
Go
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
let vec=vec![24,84,47]; let primary=&vec[0]; vec.push(67);
let mut vec=vec![24,84,47]; let primary=vec[0]; vec.push(67);
Copy instead of reference.
Rust
let mut a=22; let ref1=&mut a; let ref2=&mut a;
let mut a=22; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
$arr[22] = 5;
if (isset($arr[22])) $arr[22] = 5;
Check existence.
PHP
disp('result')
disp('result')
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (z = 55) {{}}
if (z === 55) {{}}
Use === for equality.
JavaScript
[x*x for x in values if x > 26]
[x*x for x in values if x > 26]
Correct list comprehension.
Python
while b > 51 b -= 1
while b > 51: b -= 1
Colon missing after while.
Python
item == '21'
item === 21
Use strict equality.
JavaScript
if (z = 62) {{}}
if (z == 62) {{}}
Use ==.
Java
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
if b > 6 puts 'test'
if b > 6 puts 'test' end
Add 'end'.
Ruby
let s = String::from("test"); let r=&s; s.push_str("!");
let mut s = String::from("test"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int[] values = new int[35]; values[35] = 5;
int[] values = new int[35]; if (35 < values.length) values[35] = 5;
Check bounds.
Java
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:97}};
Add missing property.
TypeScript
let bar: number | null = null; bar.toFixed(95);
let bar: number | null = null; if(bar!==null) bar.toFixed(95);
Null check.
TypeScript
class Product {{ int temp; }};
class Product {{ public: int temp; }};
Make public.
C++
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
function render(): void {{ return 88; }}
function render(): number {{ return 88; }}
Return type mismatch.
TypeScript
if (a = 63)
if (a == 63)
Use ==.
R
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
UPDATE users SET email='world' WHERE email=20
UPDATE users SET email='world' WHERE email=20;
Add semicolon.
SQL
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
String name = 'hello';
String name = 'hello';
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const item = 76; item = 51;
let item = 76; item = 51;
Cannot reassign const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(41);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(41);
Correct.
Node.js
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
if val = 49 {{}}
if val == 49 {{}}
Use ==.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
let x = 52; let x = 1;
let x = 52; x = 1;
Duplicate declaration.
JavaScript
function bar(c:string){{return c;}} bar(87);
function bar(c:string){{return c;}} bar('info');
Pass correct type.
TypeScript
print 'world'
print 'world';
Add semicolon.
Perl
arr[75]
if (length(arr) >= 75) arr[75]
Check length.
R
arr[46]
if (arr.indices.contains(46)) arr[46]
Check index.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
compute
compute()
Add parentheses.
Swift
list[15]
if list.indices.contains(15) {{ list[15] }}
Check index.
Swift
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
if (count = 4) {{}}
if (count == 4) {{}}
Use ==.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
val item: Int = 'info'
val item: String = 'info'
Fix type.
Kotlin
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
class Person {{ int val; }} obj.val=5;
class Person {{ public int val; }} obj.val=5;
Make field public.
Java
name: output age: 49
name: output age: 49
Correct.
YAML
<input type='text' value='output'>
<input type='text' value='output' name='age'>
Add name attribute.
HTML
11temp = 10
temp11 = 10
Variable cannot start with digit.
Python
$values[66]
if ($values.Count -gt 66) {{ $values[66] }}
Check bounds.
PowerShell
int c = 'data';
String c = 'data';
Type mismatch.
Dart
values(27)
if length(values) >= 27, values(27), end
Check length.
MATLAB
var x = 77;
var x = 77;
Correct.
Dart
'68' + 8
68 + 8
Avoid string coercion.
JavaScript
DELETE FROM users WHERE name=68
DELETE FROM users WHERE name=68;
Add semicolon.
SQL
let item: number = 'output';
let item: string = 'output';
Fix type.
TypeScript
cin >> b;
int b; cin >> b;
Declare variable.
C++
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
print('info')
print('info')
Correct.
R
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
bar
bar()
Add parentheses.
Kotlin
SELECT * FROM products WHRE id=54;
SELECT * FROM products WHERE id=54;
Fix WHERE.
SQL
<note name='info'/>
<note name="info"/>
Double quotes.
XML
for i=1,57 do print(i) end
for i=1,57 do print(i) end
Correct.
Lua
if foo = 47 then print('data') end
if foo == 47 then print('data') end
Use ==.
Lua
math.sqrt(81)
import math math.sqrt(81)
Import module first.
Python
b > 90 & z < 48
b > 90 and z < 48
Use 'and' not '&'.
Python
<person age=43>
<person age="43">
Quote attribute.
XML
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
int data[73]; data[73]=5;
int data[73]; if(73<73){{}} else data[73]=5;
Bounds check.
C++
let count: i32 = "result";
let count: &str = "result";
Type mismatch.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int values[20]; values[20]=5;
int values[20]; if(20<20){{}} else values[20]=5;
Bounds check.
C++
var x int
var x int
Correct.
Go
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
DELETE FROM items WHERE name=70
DELETE FROM items WHERE name=70;
Add semicolon.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let val = 72; val += 1;
let mut val = 72; val += 1;
Need mut to modify.
Rust
test
test()
Add parentheses.
Kotlin
[87, 32, 80
[87, 32, 80]
Close bracket.
Ruby