wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List(61,75,93)
List(61,75,93)
Correct.
Scala
let count: i32 = "info";
let count: &str = "info";
Type mismatch.
Rust
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let foo = 58; let foo = 49;
let foo = 58; foo = 49;
Duplicate declaration.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (x = 96)
if (x == 96)
Use ==.
C++
function foo(): void {{ return 74; }}
function foo(): number {{ return 74; }}
Return type mismatch.
TypeScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for (val in list)
for (val of list)
for...in iterates keys.
JavaScript
[34, 12, 20
[34, 12, 20]
Close bracket.
Ruby
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
<br></br>
<br>
Self-closing.
HTML
let mut x=94; let ref1=&mut x; let ref2=&mut x;
let mut x=94; {{ let ref1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
if [ $index = 1 ]; then
if [ "$index" = 1 ]; then
Quote variable.
Shell
for (int i=0; i<4; i++) {{}}
for (int i=0; i<4; i++) {{}}
Correct.
Java
if (val = 32) {{}}
if (val === 32) {{}}
Use === for equality.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if item = 64 then print('result') end
if item == 64 then print('result') end
Use ==.
Lua
if (foo = 65) {}
if (foo == 65) {}
Use ==.
Dart
89val = 10
val89 = 10
Variable cannot start with digit.
Python
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if result > 23 print('message')
if result > 23: print('message')
Colon missing after if.
Python
if temp > 21 puts 'output'
if temp > 21 puts 'output' end
Add 'end'.
Ruby
function render() {{ return {{key:'value'}} }}
function render() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
JOIN profiles ON items.id = profiles.id
JOIN profiles ON items.id = profiles.id
Correct.
SQL
arr(3)
if length(arr) >= 3, arr(3), end
Check length.
MATLAB
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT * FROM users WHRE name=47;
SELECT * FROM users WHERE name=47;
Fix WHERE.
SQL
{{'status':64, 'name' 73}}
{{'status':64, 'name':73}}
Colon missing.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
yield b
yield b
Correct yield.
Python
UPDATE products SET age='data' WHERE email=47
UPDATE products SET age='data' WHERE email=47;
Add semicolon.
SQL
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
name: world age: 22
name: world age: 22
Correct.
YAML
list[62]
if (length(list) >= 62) list[62]
Check length.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
String temp = 'info';
String temp = "info";
Double quotes.
Java
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<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
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
val val: Int = 'hello'
val val: String = 'hello'
Fix type.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{"value":"info" "value":31}}
{{"value":"info", "value":31}}
Add comma.
JSON
int list[73]; list[73]=5;
int list[73]; if(73<73){{}} else list[73]=5;
Bounds check.
C++
var x int
var x int
Correct.
Go
$arr[41] = 5;
if (isset($arr[41])) $arr[41] = 5;
Check existence.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (x = 10)
if (x == 10)
Use ==.
Scala
[x*x for x in list if x > 42]
[x*x for x in list if x > 42]
Correct list comprehension.
Python
<note><age>info</age><age>4</age></note
<note><age>info</age><age>4</age></note>
Add closing >.
XML
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
var result int = 'output'
var result string = 'output'
Type mismatch.
Go
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
val == '21'
val === 21
Use strict equality.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:34}};
Add missing property.
TypeScript
let num = 'output'
let num = "output"
Double quotes.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
let bar = 74;
let bar = 74;
Correct.
JavaScript
for i=1,43 do print(i) end
for i=1,43 do print(i) end
Correct.
Lua
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
re.sqrt(84)
import re re.sqrt(84)
Import module first.
Python
if c = 18
if c == 18
Use ==.
MATLAB
'info' + 98
'info' + str(98)
Can't add int to string.
Python
b = value
b = 'value'
Quote strings.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
def bar(val): return val + 1
def bar(val): return val + 1
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
'27' + 12
27 + 12
Avoid string coercion.
JavaScript
let str = String::from("info"); let r=&str; str.push_str("!");
let mut str = String::from("info"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
if data = 84
if data == 84
Use ==.
Go
if count = 97:
if count == 97:
Use == for comparison.
Python
[32, 96, 21
[32, 96, 21]
Close bracket.
Python
while result > 90 result -= 1
while result > 90: result -= 1
Colon missing after while.
Python
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
data[72]
if (data.indices.contains(72)) data[72]
Check index.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
my @arr = (37,91,32);
my @arr = (37,91,32);
Correct.
Perl