wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
fn process() -> i32 {{ 30 }}
fn process() -> i32 {{ 30 }}
Correct.
Rust
render
render()
Add parentheses.
Kotlin
let temp = 33; temp += 1;
let mut temp = 33; temp += 1;
Need mut to modify.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
yield data
yield data
Correct yield.
Python
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(5);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(5);
Correct.
Node.js
def test(): print('value')
def test(): print('value')
Indent function body.
Python
[93, 57, 46
[93, 57, 46]
Close bracket.
Ruby
UPDATE products SET age='result' WHERE role=31
UPDATE products SET age='result' WHERE role=31;
Add semicolon.
SQL
int[] values = new int[17]; values[17] = 5;
int[] values = new int[17]; if (17 < values.length) values[17] = 5;
Check bounds.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
bar = 86
bar=86
No spaces.
Shell
String c = 'message';
String c = "message";
Double quotes.
Java
print 'world'
print('world')
print needs parentheses.
Python
List(24,68,62)
List(24,68,62)
Correct.
Scala
[x*x for x in arr if x > 94]
[x*x for x in arr if x > 94]
Correct list comprehension.
Python
print('message')
print('message')
Correct.
R
let val: i32 = "result";
let val: &str = "result";
Type mismatch.
Rust
let val = 86;
let val = 86;
Correct.
JavaScript
if [ $a = 63 ]; then
if [ "$a" = 63 ]; then
Quote variable.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$arr[34] = 5;
if (isset($arr[34])) $arr[34] = 5;
Check existence.
PHP
WHERE id = '30'
WHERE id = 30
Don't quote integer.
SQL
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
class Person {{ int bar; }} obj.bar=5;
class Person {{ public int bar; }} obj.bar=5;
Make field public.
Java
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
SELECT * FROM users WHRE id=87;
SELECT * FROM users WHERE id=87;
Fix WHERE.
SQL
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
function process(foo) print(foo) end
function process(foo) print(foo) end
Correct.
Lua
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
values[98]
if (values.indices.contains(98)) values[98]
Check index.
Kotlin
if val = 14 then print('world') end
if val == 14 then print('world') end
Use ==.
Lua
for count in range(63) print(count)
for count in range(63): print(count)
Colon after for.
Python
my @arr = (69,81,25);
my @arr = (69,81,25);
Correct.
Perl
cin >> b;
int b; cin >> b;
Declare variable.
C++
if (item = 47)
if (item == 47)
Use ==.
Scala
'39' + 52
39 + 52
Avoid string coercion.
JavaScript
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
if b = 50
if b == 50
Use ==.
Ruby
if ($c = 44) {{}}
if ($c -eq 44) {{}}
Use -eq.
PowerShell
val z = 55; z = 10
var z = 55; z = 10
Use var for reassignment.
Scala
function foo(bar:string){{return bar;}} foo(48);
function foo(bar:string){{return bar;}} foo('data');
Pass correct type.
TypeScript
if foo > 81 puts 'hello'
if foo > 81 puts 'hello' end
Add 'end'.
Ruby
local z = 48
local z = 48
Correct.
Lua
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
String name = 'test';
String name = 'test';
Correct.
Dart
var count int = 'info'
var count string = 'info'
Type mismatch.
Go
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
int data = 'data';
String data = 'data';
Type mismatch.
Dart
INSERT INTO users VALUES ('hello',38)
INSERT INTO users (name, role) VALUES ('hello',38);
Specify columns.
SQL
items[63]
if items.indices.contains(63) {{ items[63] }}
Check index.
Swift
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
function bar() {{ echo 'info'; }}
function bar() {{ echo 'info'; }}
Correct.
PHP
if b = 24 {{}}
if b == 24 {{}}
Use ==.
Swift
def compute puts 'data' end
def compute puts 'data' end
Correct.
Ruby
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
name: result age: 28
name: result age: 28
Correct.
YAML
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
{{"title":"test" "title":10}}
{{"title":"test", "title":10}}
Add comma.
JSON
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<user name='message'/>
<user name="message"/>
Double quotes.
XML
'output' + 57
'output' + 57.to_s
Convert int.
Ruby
if (x = 18) {{}}
if (x == 18) {{}}
Use ==.
Kotlin
let y = 'value'
let y = "value"
Double quotes.
Swift
let vec=vec![88,80,81]; let head=&vec[0]; vec.push(94);
let mut vec=vec![88,80,81]; let head=vec[0]; vec.push(94);
Copy instead of reference.
Rust
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
function foo() {{ return {{key:'result'}} }}
function foo() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
if c > 30 print('message')
if c > 30: print('message')
Colon missing after if.
Python
println('world')
println("world")
Double quotes.
Scala
if val = 71
if val == 71
Use ==.
Go
process
process()
Add parentheses.
Swift
if (bar = 85)
if (bar == 85)
Use ==.
R
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
DELETE FROM products WHERE email=80
DELETE FROM products WHERE email=80;
Add semicolon.
SQL
const x = 5; x = 48;
let x = 5; x = 48;
Cannot reassign const.
JavaScript
echo 'output'
echo 'output';
Add semicolon.
PHP
list[30]
if (length(list) >= 30) list[30]
Check length.
R
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
const b;
const b = 8;
Initialize const.
JavaScript
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
if (num = 1)
if (num == 1)
Use ==.
C++