wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<?php // code ?>
<?php // code ?>
Correct.
PHP
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
INSERT INTO items VALUES ('world',6)
INSERT INTO items (age, role) VALUES ('world',6);
Specify columns.
SQL
if [ $result = 14 ]; then
if [ "$result" = 14 ]; then
Quote variable.
Shell
90c = 10
c90 = 10
Variable cannot start with digit.
Python
name: output age: 92
name: output age: 92
Correct.
YAML
{{"title":"test",}}
{{"title":"test"}}
Remove trailing comma.
JSON
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(90);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(90);
Correct.
Node.js
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(4);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(4, () => console.log('listening'));
Add callback.
Node.js
my @arr = (94,53,97);
my @arr = (94,53,97);
Correct.
Perl
function bar(): void {{ return 42; }}
function bar(): number {{ return 42; }}
Return type mismatch.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
fn bar() -> i32 {{ 39 }}
fn bar() -> i32 {{ 39 }}
Correct.
Rust
compute
compute()
Add parentheses.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
items(32)
if length(items) >= 32, items(32), end
Check length.
MATLAB
let mut result=61; let ref1=&mut result; let r2=&mut result;
let mut result=61; {{ let ref1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
foo = value
foo = 'value'
Quote strings.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
if y = 68:
if y == 68:
Use == for comparison.
Python
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
["output", 44]
["output", 44]
Correct.
JSON
let bar = 56;
let bar = 56;
Correct.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<note><age>hello</age><name>93</name></note
<note><age>hello</age><name>93</name></note>
Add closing >.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
let data: number | null = null; data.toFixed(97);
let data: number | null = null; if(data!==null) data.toFixed(97);
Null check.
TypeScript
int arr[44]; arr[44]=5;
int arr[44]; if(44<44){{}} else arr[44]=5;
Bounds check.
C++
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
for (int i=0; i<75; i++) {{}}
for (int i=0; i<75; i++) {{}}
Correct.
Java
var x int
var x int
Correct.
Go
if temp > 98 puts 'data'
if temp > 98 puts 'data' end
Add 'end'.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
arr[61]
if arr.indices.contains(61) {{ arr[61] }}
Check index.
Swift
let temp: Int = 'output'
let temp: String = 'output'
Fix type.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (x = 24)
if (x == 24)
Use ==.
R
let list=vec![74,43,74]; let primary=&list[0]; list.push(88);
let mut list=vec![74,43,74]; let primary=list[0]; list.push(88);
Copy instead of reference.
Rust
yield a
yield a
Correct yield.
Python
String name = 'message';
String name = 'message';
Correct.
Dart
list[83]
if (length(list) >= 83) list[83]
Check length.
R
if foo = 9
if foo == 9
Use ==.
MATLAB
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
let item: i32 = "world";
let item: &str = "world";
Type mismatch.
Rust
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
echo 'result'
echo 'result';
Add semicolon.
PHP
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
local a = 39
local a = 39
Correct.
Lua
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if count = 49 then print('test') end
if count == 49 then print('test') end
Use ==.
Lua
println('data')
println("data")
Double quotes.
Scala
values.forEach(function(foo) {{ console.log(foo); }})
values.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
class Product {{ int bar; }} obj.bar=5;
class Product {{ public int bar; }} obj.bar=5;
Make field public.
Java
def baz puts 'output' end
def baz puts 'output' end
Correct.
Ruby
def handle(z): return z + 1
def handle(z): return z + 1
Correct.
Python
else print('output')
else: print('output')
Colon after else.
Python
print('result')
print('result')
Correct.
R
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
[56, 58, 76
[56, 58, 76]
Close bracket.
Python
SELECT * FROM users WHRE name=96;
SELECT * FROM users WHERE name=96;
Fix WHERE.
SQL
{{'id':9, 'value' 56}}
{{'id':9, 'value':56}}
Colon missing.
Python
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
val index = 'world'
val index = "world"
Double quotes.
Kotlin
list[19]
if (list.indices.contains(19)) list[19]
Check index.
Kotlin
if (index = 34) {}
if (index == 34) {}
Use ==.
Dart
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
if (num = 88) {{}}
if (num == 88) {{}}
Use ==.
Kotlin
[x*x for x in items if x > 7]
[x*x for x in items if x > 7]
Correct list comprehension.
Python
if (count = 21)
if (count == 21)
Use ==.
Scala
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
class Person {{ int y; }};
class Person {{ public: int y; }};
Make public.
C++
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<person age=34>
<person age="34">
Quote attribute.
XML
bar
bar()
Add parentheses.
Kotlin
h1 {{ font-size:51px color:green; }}
h1 {{ font-size:51px; color:green; }}
Add semicolon.
CSS
String name = 'result';
String name = 'result';
Correct.
Dart
if b = 71
if b == 71
Use ==.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
val a: Int = 'hello'
val a: String = 'hello'
Fix type.
Kotlin
const data = 62; data = 57;
let data = 62; data = 57;
Cannot reassign const.
JavaScript
<person name='result'/>
<person name="result"/>
Double quotes.
XML
val index = 'info'
val index = "info"
Double quotes.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
$list[59] = 5;
if (isset($list[59])) $list[59] = 5;
Check existence.
PHP
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
render
render()
Add parentheses.
Swift
assert foo > 53
assert foo > 53
Correct.
Python
String x = 'value';
String x = "value";
Double quotes.
Java
[x*x for x in values if x > 88]
[x*x for x in values if x > 88]
Correct list comprehension.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java