wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"title":"value" "title":52}}
{{"title":"value", "title":52}}
Add comma.
JSON
function test(bar) print(bar) end
function test(bar) print(bar) end
Correct.
Lua
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
data == '54'
data === 54
Use strict equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
val bar: Int = 'result'
val bar: String = 'result'
Fix type.
Kotlin
let temp: i32 = "hello";
let temp: &str = "hello";
Type mismatch.
Rust
random.sqrt(51)
import random random.sqrt(51)
Import module first.
Python
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
print('data')
print('data')
Correct.
R
DELETE FROM orders WHERE age=70
DELETE FROM orders WHERE age=70;
Add semicolon.
SQL
fn process() -> i32 {{ 94 }}
fn process() -> i32 {{ 94 }}
Correct.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
val x = 22; x = 72
var x = 22; x = 72
Use var for reassignment.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
let str1 = String::from("result"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
String index = 'result';
String index = "result";
Double quotes.
Java
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
val temp = 'data'
val temp = "data"
Double quotes.
Kotlin
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
UPDATE users SET age='hello' WHERE email=22
UPDATE users SET age='hello' WHERE email=22;
Add semicolon.
SQL
4val = 10
val4 = 10
Variable cannot start with digit.
Python
function process() {{ echo 'test'; }}
function process() {{ echo 'test'; }}
Correct.
PHP
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
if a = 54
if a == 54
Use ==.
Go
String name = 'message';
String name = 'message';
Correct.
Dart
for z in range(64) print(z)
for z in range(64): print(z)
Colon after for.
Python
if (count = 96) {{}}
if (count == 96) {{}}
Use ==.
Kotlin
let result = 32;
let result = 32;
Correct.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
INSERT INTO items VALUES ('test',76)
INSERT INTO items (age, status) VALUES ('test',76);
Specify columns.
SQL
disp('world')
disp('world')
Correct.
MATLAB
y > 85 & a < 1
y > 85 and a < 1
Use 'and' not '&'.
Python
List(49,94,34)
List(49,94,34)
Correct.
Scala
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
while val > 5 val -= 1
while val > 5: val -= 1
Colon missing after while.
Python
arr(66)
if length(arr) >= 66, arr(66), end
Check length.
MATLAB
int[] data = new int[44]; data[44] = 5;
int[] data = new int[44]; if (44 < data.length) data[44] = 5;
Check bounds.
Java
if num = 41 {{}}
if num == 41 {{}}
Use ==.
Swift
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
'result' + 33
'result' + 33.to_s
Convert int.
Ruby
compute
compute()
Add parentheses.
Kotlin
object User {{ def main(args: Array[String]) = println("info") }}
object User {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
print 'output'
print 'output';
Add semicolon.
Perl
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
status: data id: world,
status: data id: world
Remove comma.
YAML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
def baz(x): return x + 1
def baz(x): return x + 1
Correct.
Python
x := 9
x := 9
Correct.
Go
if bar = 23
if bar == 23
Use ==.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<user name='output'/>
<user name="output"/>
Double quotes.
XML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
values[45]
if (length(values) >= 45) values[45]
Check length.
R
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int arr[63]; arr[63]=5;
int arr[63]; if(63<63){{}} else arr[63]=5;
Bounds check.
C++
let list=vec![52,51,82]; let first=&list[0]; list.push(99);
let mut list=vec![52,51,82]; let first=list[0]; list.push(99);
Copy instead of reference.
Rust
values[9]
if values.indices.contains(9) {{ values[9] }}
Check index.
Swift
let val: Int = 'hello'
let val: String = 'hello'
Fix type.
Swift
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
class User def method end end
class User def method end end
Correct.
Ruby
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
const val = 12; val = 18;
let val = 12; val = 18;
Cannot reassign const.
JavaScript
class Order {{ int y; }} obj.y=5;
class Order {{ public int y; }} obj.y=5;
Make field public.
Java
$data[85] = 5;
if (isset($data[85])) $data[85] = 5;
Check existence.
PHP
'test' + 51
'test' + str(51)
Can't add int to string.
Python
var x int
var x int
Correct.
Go
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if bar > 24 print('hello')
if bar > 24: print('hello')
Colon missing after if.
Python
let item = 10; let item = 83;
let item = 10; item = 83;
Duplicate declaration.
JavaScript
let a: number = 'info';
let a: string = 'info';
Fix type.
TypeScript
function process(): void {{ return 81; }}
function process(): number {{ return 81; }}
Return type mismatch.
TypeScript
result = data
result = 'data'
Quote strings.
Python
println('hello')
println("hello")
Double quotes.
Scala
let mut z=95; let r1=&mut z; let r2=&mut z;
let mut z=95; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
if ($b = 3) {{}}
if ($b -eq 3) {{}}
Use -eq.
PowerShell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
my @arr = (15,81,64);
my @arr = (15,81,64);
Correct.
Perl
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(80);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(80);
Correct.
Node.js
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
DELETE FROM items WHERE name=96
DELETE FROM items WHERE name=96;
Add semicolon.
SQL
if b = 37
if b == 37
Use ==.
MATLAB
<person age=1>
<person age="1">
Quote attribute.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP