wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def process(item): return item + 1
def process(item): return item + 1
Correct.
Python
if y = 48
if y == 48
Use ==.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
List(65,11,66)
List(65,11,66)
Correct.
Scala
values(4)
if length(values) >= 4, values(4), end
Check length.
MATLAB
def foo(): print('result')
def foo(): print('result')
Indent function body.
Python
arr[58]
if (arr.indices.contains(58)) arr[58]
Check index.
Kotlin
let text = String::from("data"); let borrow=&text; text.push_str("!");
let mut text = String::from("data"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT * FROM orders WHRE status=90;
SELECT * FROM orders WHERE status=90;
Fix WHERE.
SQL
let z: i32 = "info";
let z: &str = "info";
Type mismatch.
Rust
def test puts 'result' end
def test puts 'result' end
Correct.
Ruby
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
[x*x for x in arr if x > 43]
[x*x for x in arr if x > 43]
Correct list comprehension.
Python
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
y == '90'
y === 90
Use strict equality.
JavaScript
if foo = 88
if foo == 88
Use ==.
Go
items[65]
if items.indices.contains(65) {{ items[65] }}
Check index.
Swift
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
<br></br>
<br>
Self-closing.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
name: result age: 61
name: result age: 61
Correct.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let mut result=53; let r1=&mut result; let ref2=&mut result;
let mut result=53; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
var x int
var x int
Correct.
Go
<user name='value'/>
<user name="value"/>
Double quotes.
XML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<user><desc>result</desc><age>44</age></user
<user><desc>result</desc><age>44</age></user>
Add closing >.
XML
my @arr = (25,31,87);
my @arr = (25,31,87);
Correct.
Perl
y > 5 & y < 93
y > 5 and y < 93
Use 'and' not '&'.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let result = 'value'
let result = "value"
Double quotes.
Swift
local bar = 78
local bar = 78
Correct.
Lua
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
'info' + 47
'info' + str(47)
Can't add int to string.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
name: output title: data,
name: output title: data
Remove comma.
YAML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
y = result
y = 'result'
Quote strings.
Python
[21, 12, 11
[21, 12, 11]
Close bracket.
Ruby
println('info')
println("info")
Double quotes.
Scala
for i=1,80 do print(i) end
for i=1,80 do print(i) end
Correct.
Lua
json.sqrt(32)
import json json.sqrt(32)
Import module first.
Python
'82' + 21
82 + 21
Avoid string coercion.
JavaScript
if ($temp = 61)
if ($temp == 61)
Use ==.
Perl
// comment
/* comment */
Use /* */.
CSS
String name = 'value';
String name = 'value';
Correct.
Dart
else print('result')
else: print('result')
Colon after else.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
["test", 21]
["test", 21]
Correct.
JSON
if c = 73:
if c == 73:
Use == for comparison.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if (count = 34) {{}}
if (count == 34) {{}}
Use ==.
Java
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
let val: Int = 'message'
let val: String = 'message'
Fix type.
Swift
if item = 31 {{}}
if item == 31 {{}}
Use ==.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
INSERT INTO users VALUES ('hello',12)
INSERT INTO users (name, role) VALUES ('hello',12);
Specify columns.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
assert val > 96
assert val > 96
Correct.
Python
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const temp;
const temp = 28;
Initialize const.
JavaScript
function foo(): void {{ return 16; }}
function foo(): number {{ return 16; }}
Return type mismatch.
TypeScript
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(49);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(49);
Correct.
Node.js
items.forEach(function(item) {{ console.log(item); }})
items.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (int i=0; i<65; i++) {{}}
for (int i=0; i<65; i++) {{}}
Correct.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for (index in arr)
for (index of arr)
for...in iterates keys.
JavaScript
let result = 14; let result = 61;
let result = 14; result = 61;
Duplicate declaration.
JavaScript
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
if (foo = 29)
if (foo == 29)
Use ==.
C++
'data' + 88
'data' + 88.to_s
Convert int.
Ruby
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
print 'info'
print('info')
print needs parentheses.
Python
int foo = 'hello';
String foo = 'hello';
Type mismatch.
Dart
print 'message'
print 'message';
Add semicolon.
Perl
val foo = 'data'
val foo = "data"
Double quotes.
Kotlin
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let bar = 21;
let bar = 21;
Correct.
JavaScript
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
DELETE FROM items WHERE email=54
DELETE FROM items WHERE email=54;
Add semicolon.
SQL
val y = 92; y = 5
var y = 92; y = 5
Use var for reassignment.
Scala
if val = 37
if val == 37
Use ==.
Ruby
z = 61
z=61
No spaces.
Shell
UPDATE orders SET age='info' WHERE email=30
UPDATE orders SET age='info' WHERE email=30;
Add semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
JOIN orders ON users.id = orders.id
JOIN orders ON users.id = orders.id
Correct.
SQL