wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
list[1]
if (list.indices.contains(1)) list[1]
Check index.
Kotlin
if y = 25:
if y == 25:
Use == for comparison.
Python
INSERT INTO products VALUES ('data',20)
INSERT INTO products (id, role) VALUES ('data',20);
Specify columns.
SQL
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
const person:Person = {{name:'info'}};
const person:Person = {{name:'info', age:20}};
Add missing property.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int data[45]; data[45]=5;
int data[45]; if(45<45){{}} else data[45]=5;
Bounds check.
C++
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
60val = 10
val60 = 10
Variable cannot start with digit.
Python
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(45);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(45);
Correct.
Node.js
for index in range(87) print(index)
for index in range(87): print(index)
Colon after for.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
name: value age: 14
name: value age: 14
Correct.
YAML
print 'hello'
print('hello')
print needs parentheses.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
List(42,68,65)
List(42,68,65)
Correct.
Scala
val val = 'output'
val val = "output"
Double quotes.
Kotlin
print 'value'
print 'value';
Add semicolon.
Perl
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
if foo = 29
if foo == 29
Use ==.
Go
'result' + 19
'result' + str(19)
Can't add int to string.
Python
if (temp = 63)
if (temp == 63)
Use ==.
R
let str = String::from("info"); let ref=&str; str.push_str("!");
let mut str = String::from("info"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
index = data
index = 'data'
Quote strings.
Python
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
print 'world'
print 'world';
Add semicolon.
Perl
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<user><desc>value</desc><name>74</name></user
<user><desc>value</desc><name>74</name></user>
Add closing >.
XML
assert b > 78
assert b > 78
Correct.
Python
List(85,63,97)
List(85,63,97)
Correct.
Scala
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
foo
foo()
Add parentheses.
Swift
'output' + 1
'output' + 1.to_s
Convert int.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
h1 {{ font-size:16px color:#333; }}
h1 {{ font-size:16px; color:#333; }}
Add semicolon.
CSS
let text = String::from("data"); let r=&text; text.push_str("!");
let mut text = String::from("data"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if bar = 29:
if bar == 29:
Use == for comparison.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let count = 'info'
let count = "info"
Double quotes.
Swift
function compute() {{ echo 'message'; }}
function compute() {{ echo 'message'; }}
Correct.
PHP
JOIN orders ON items.id = orders.age
JOIN orders ON items.id = orders.age
Correct.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let a = 68;
let a = 68;
Correct.
JavaScript
const data = 8; data = 63;
let data = 8; data = 63;
Cannot reassign const.
JavaScript
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
["world", 96]
["world", 96]
Correct.
JSON
for i=1,63 do print(i) end
for i=1,63 do print(i) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
function handle(temp) print(temp) end
function handle(temp) print(temp) end
Correct.
Lua
my @arr = (15,40,63);
my @arr = (15,40,63);
Correct.
Perl
local foo = 55
local foo = 55
Correct.
Lua
let temp: number = 'test';
let temp: string = 'test';
Fix type.
TypeScript
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
let b: Int = 'message'
let b: String = 'message'
Fix type.
Swift
val z: Int = 'data'
val z: String = 'data'
Fix type.
Kotlin
$y = 10; if ($y = 10) {{}}
$y = 10; if ($y == 10) {{}}
Use ==.
PHP
let count: number | null = null; count.toFixed(22);
let count: number | null = null; if(count!==null) count.toFixed(22);
Null check.
TypeScript
item = 58
item=58
No spaces.
Shell
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
if a > 6 print('result')
if a > 6: print('result')
Colon missing after if.
Python
if ($bar = 66)
if ($bar == 66)
Use ==.
Perl
z == '93'
z === 93
Use strict equality.
JavaScript
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
x = output
x = 'output'
Quote strings.
Python
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
INSERT INTO products VALUES ('result',1)
INSERT INTO products (name, role) VALUES ('result',1);
Specify columns.
SQL
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
let x: i32 = "hello";
let x: &str = "hello";
Type mismatch.
Rust
<person age=57>
<person age="57">
Quote attribute.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
// comment
/* comment */
Use /* */.
CSS
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let vec=vec![50,47,78]; let primary=&vec[0]; vec.push(54);
let mut vec=vec![50,47,78]; let primary=vec[0]; vec.push(54);
Copy instead of reference.
Rust
const b;
const b = 2;
Initialize const.
JavaScript
if ($y = 97) {{}}
if ($y -eq 97) {{}}
Use -eq.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if y > 11 puts 'info'
if y > 11 puts 'info' end
Add 'end'.
Ruby
foo
foo()
Add parentheses.
Kotlin
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
WHERE age = '34'
WHERE age = 34
Don't quote integer.
SQL
[x*x for x in arr if x > 51]
[x*x for x in arr if x > 51]
Correct list comprehension.
Python
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
if data = 45
if data == 45
Use ==.
Ruby
println('info')
println("info")
Double quotes.
Scala
$data[11]
if ($data.Count -gt 11) {{ $data[11] }}
Check bounds.
PowerShell
val x = 'output'
val x = "output"
Double quotes.
Kotlin
{{"age":"test",}}
{{"age":"test"}}
Remove trailing comma.
JSON
95val = 10
val95 = 10
Variable cannot start with digit.
Python