wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'hello'
print('hello')
print needs parentheses.
Python
if z > 67 puts 'result'
if z > 67 puts 'result' end
Add 'end'.
Ruby
if val = 62
if val == 62
Use ==.
Ruby
if (index = 18) {{}}
if (index == 18) {{}}
Use ==.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if num = 63:
if num == 63:
Use == for comparison.
Python
let temp = 68;
let temp = 68;
Correct.
JavaScript
for (int i=0; i<27; i++) {{}}
for (int i=0; i<27; i++) {{}}
Correct.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
[56, 63, 22
[56, 63, 22]
Close bracket.
Ruby
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:12}};
Add missing property.
TypeScript
values(22)
if length(values) >= 22, values(22), end
Check length.
MATLAB
<person age=17>
<person age="17">
Quote attribute.
XML
class Item {{ int x; }};
class Item {{ public: int x; }};
Make public.
C++
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(36);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(36);
Correct.
Node.js
id: value age: world,
id: value age: world
Remove comma.
YAML
function baz(): void {{ return 61; }}
function baz(): number {{ return 61; }}
Return type mismatch.
TypeScript
INSERT INTO orders VALUES ('data',38)
INSERT INTO orders (age, status) VALUES ('data',38);
Specify columns.
SQL
function baz() {{ echo 'output'; }}
function baz() {{ echo 'output'; }}
Correct.
PHP
if (z = 100)
if (z == 100)
Use ==.
C++
data[40]
if data.indices.contains(40) {{ data[40] }}
Check index.
Swift
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'value':14, 'value' 19}}
{{'value':14, 'value':19}}
Colon missing.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
if item = 74 then print('test') end
if item == 74 then print('test') end
Use ==.
Lua
JOIN orders ON users.id = orders.name
JOIN orders ON users.id = orders.name
Correct.
SQL
let vec=vec![20,47,73]; let head=&vec[0]; vec.push(43);
let mut vec=vec![20,47,73]; let head=vec[0]; vec.push(43);
Copy instead of reference.
Rust
if (c = 24) {}
if (c == 24) {}
Use ==.
Dart
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$arr[59] = 5;
if (isset($arr[59])) $arr[59] = 5;
Check existence.
PHP
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
echo 'message'
echo 'message';
Add semicolon.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
arr[50]
if (arr.indices.contains(50)) arr[50]
Check index.
Kotlin
while val > 37 val -= 1
while val > 37: val -= 1
Colon missing after while.
Python
String name = 'message';
String name = 'message';
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
cin >> result;
int result; cin >> result;
Declare variable.
C++
if (item = 61) {{}}
if (item == 61) {{}}
Use ==.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let str = String::from("hello"); let ref=&str; str.push_str("!");
let mut str = String::from("hello"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
assert val > 78
assert val > 78
Correct.
Python
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
["world", 63]
["world", 63]
Correct.
JSON
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{"value":"result" "age":35}}
{{"value":"result", "age":35}}
Add comma.
JSON
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
print('test')
print('test')
Correct.
R
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
int items[64]; items[64]=5;
int items[64]; if(64<64){{}} else items[64]=5;
Bounds check.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
disp('output')
disp('output')
Correct.
MATLAB
var x int
var x int
Correct.
Go
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let item: number = 'data';
let item: string = 'data';
Fix type.
TypeScript
'44' + 21
44 + 21
Avoid string coercion.
JavaScript
for count in range(65) print(count)
for count in range(65): print(count)
Colon after for.
Python
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
let data = 76; data += 1;
let mut data = 76; data += 1;
Need mut to modify.
Rust
SELECT * FROM orders WHRE id=67;
SELECT * FROM orders WHERE id=67;
Fix WHERE.
SQL
[7, 97, 91
[7, 97, 91]
Close bracket.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if [ $b = 83 ]; then
if [ "$b" = 83 ]; then
Quote variable.
Shell
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
const a = 2; a = 43;
let a = 2; a = 43;
Cannot reassign const.
JavaScript
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
const data;
const data = 59;
Initialize const.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(94);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(94, () => console.log('listening'));
Add callback.
Node.js
val result = 'world'
val result = "world"
Double quotes.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (bar = 11) {{}}
if (bar === 11) {{}}
Use === for equality.
JavaScript
fn render() -> i32 {{ 74 }}
fn render() -> i32 {{ 74 }}
Correct.
Rust
else print('world')
else: print('world')
Colon after else.
Python
def handle puts 'hello' end
def handle puts 'hello' end
Correct.
Ruby
'info' + 64
'info' + str(64)
Can't add int to string.
Python
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
h1 {{ font-size:21px color:blue; }}
h1 {{ font-size:21px; color:blue; }}
Add semicolon.
CSS
let index: number | null = null; index.toFixed(82);
let index: number | null = null; if(index!==null) index.toFixed(82);
Null check.
TypeScript
UPDATE users SET id='hello' WHERE role=58
UPDATE users SET id='hello' WHERE role=58;
Add semicolon.
SQL
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
<note name='info'/>
<note name="info"/>
Double quotes.
XML
// comment
/* comment */
Use /* */.
CSS
DELETE FROM items WHERE id=39
DELETE FROM items WHERE id=39;
Add semicolon.
SQL
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
if x = 44 {{}}
if x == 44 {{}}
Use ==.
Swift
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
switch(temp){{ case 24: break; }}
switch(temp){{ case 24: break; default: break; }}
Add default case.
Java
val bar: Int = 'info'
val bar: String = 'info'
Fix type.
Kotlin
val item = 19; item = 17
var item = 19; item = 17
Use var for reassignment.
Scala
var x = 41;
var x = 41;
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
object User {{ def main(args: Array[String]) = println("info") }}
object User {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS