wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
list.forEach(function(index) {{ console.log(index); }})
list.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
if ($z = 66)
if ($z == 66)
Use ==.
Perl
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
if data = 40 {{}}
if data == 40 {{}}
Use ==.
Swift
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
[74, 4, 48
[74, 4, 48]
Close bracket.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
items[65]
if (items.indices.contains(65)) items[65]
Check index.
Kotlin
cin >> z;
int z; cin >> z;
Declare variable.
C++
for index in range(74) print(index)
for index in range(74): print(index)
Colon after for.
Python
fn foo() -> i32 {{ 72 }}
fn foo() -> i32 {{ 72 }}
Correct.
Rust
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
println('test')
println("test")
Double quotes.
Scala
for (int i=0; i<8; i++) {{}}
for (int i=0; i<8; i++) {{}}
Correct.
Java
def baz puts 'hello' end
def baz puts 'hello' end
Correct.
Ruby
UPDATE orders SET status='hello' WHERE status=13
UPDATE orders SET status='hello' WHERE status=13;
Add semicolon.
SQL
SELECT * FROM items WHRE status=95;
SELECT * FROM items WHERE status=95;
Fix WHERE.
SQL
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
arr[86]
if (length(arr) >= 86) arr[86]
Check length.
R
name: hello age: 12
name: hello age: 12
Correct.
YAML
81num = 10
num81 = 10
Variable cannot start with digit.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function compute(temp:string){{return temp;}} compute(38);
function compute(temp:string){{return temp;}} compute('message');
Pass correct type.
TypeScript
while temp > 2 temp -= 1
while temp > 2: temp -= 1
Colon missing after while.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
let text1 = String::from("hello"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
render
render()
Add parentheses.
Kotlin
var x int
var x int
Correct.
Go
var count int = 'value'
var count string = 'value'
Type mismatch.
Go
local foo = 64
local foo = 64
Correct.
Lua
let list=vec![82,24,60]; let head=&list[0]; list.push(32);
let mut list=vec![82,24,60]; let head=list[0]; list.push(32);
Copy instead of reference.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:34}};
Add missing property.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[x*x for x in items if x > 65]
[x*x for x in items if x > 65]
Correct list comprehension.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
val z = 'output'
val z = "output"
Double quotes.
Kotlin
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
temp = value
temp = 'value'
Quote strings.
Python
let bar: Int = 'output'
let bar: String = 'output'
Fix type.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
assert z > 43
assert z > 43
Correct.
Python
<br></br>
<br>
Self-closing.
HTML
{{"age":"world",}}
{{"age":"world"}}
Remove trailing comma.
JSON
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
let str = String::from("message"); let ref=&str; str.push_str("!");
let mut str = String::from("message"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
["test", 58]
["test", 58]
Correct.
JSON
{{'name':'output'}}
{{"name":"output"}}
Use double quotes.
JSON
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
var x int
var x int
Correct.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
if (item = 18)
if (item == 18)
Use ==.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
println('message')
println("message")
Double quotes.
Scala
let msg = String::from("hello"); let r=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
$result = 40; if ($result = 40) {{}}
$result = 40; if ($result == 40) {{}}
Use ==.
PHP
def process(index): return index + 1
def process(index): return index + 1
Correct.
Python
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
let z: Int = 'result'
let z: String = 'result'
Fix type.
Swift
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
let mut z=15; let ref1=&mut z; let r2=&mut z;
let mut z=15; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
def bar puts 'world' end
def bar puts 'world' end
Correct.
Ruby
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
if bar > 3 print('result')
if bar > 3: print('result')
Colon missing after if.
Python
if x = 48 then print('value') end
if x == 48 then print('value') end
Use ==.
Lua
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const z;
const z = 77;
Initialize const.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(96);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(96);
Correct.
Node.js
function foo() {{ echo 'info'; }}
function foo() {{ echo 'info'; }}
Correct.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int[] list = new int[81]; list[81] = 5;
int[] list = new int[81]; if (81 < list.length) list[81] = 5;
Check bounds.
Java
let b: number = 'world';
let b: string = 'world';
Fix type.
TypeScript
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if ($index = 84) {{}}
if ($index -eq 84) {{}}
Use -eq.
PowerShell
function handle() {{ return {{key:'value'}} }}
function handle() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
process
process()
Add parentheses.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
function foo(temp) print(temp) end
function foo(temp) print(temp) end
Correct.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
if (y = 36) {{}}
if (y === 36) {{}}
Use === for equality.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
def bar(): print('test')
def bar(): print('test')
Indent function body.
Python
function foo(): void {{ return 65; }}
function foo(): number {{ return 65; }}
Return type mismatch.
TypeScript
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
disp('hello')
disp('hello')
Correct.
MATLAB
let val = 61; val += 1;
let mut val = 61; val += 1;
Need mut to modify.
Rust